Menu

Example WriteSingleCoil

Rossmann Engineering

Example for Writing single coils

The following example complains how to set two Coils (1 and 17) to "TRUE"

using System;
using SRModbusTCP;

namespace test_ModbusClient
{
public class ModbusClient
{
private string ipAddress = "127.0.0.1";
private int port = 502;
private ushort addressOfCoil1 = 0;
private ushort addressOfCoil2 = 16;
private ModbusTCP modbusTCP;

    public ModbusClient()
    {
        modbusTCP = new ModbusTCP(ipAddress, port);
    }

    public void ExecuteWriteOrders()
    {
        if (!modbusTCP.Connected)
            modbusTCP.Connect();
        modbusTCP.WriteSingleCoil(addressOfCoil1, true);
        modbusTCP.WriteSingleCoil(addressOfCoil2, true);
    }

    static void Main(string[] args)
    {
        ModbusClient modbusClient = new ModbusClient();
        modbusClient.ExecuteWriteOrders();
        Console.ReadLine();
    }
}

}


Related

Wiki: Methods ModbusClient

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.