C#、.Net使用NModbus4进行ModbusTCP连接
第一步 从Nuget包管理器安装相应版本的NModbus
第二步 直接上代码
string ipAddr = "127.0.0.5"; // IP Address of the slave
int tcpPort = 502; // Communication port
TcpClient tcpClient = new TcpClient();
tcpClient.BeginConnect(ipAddr, tcpPort, null, null);
//创建连接客户端
ModbusIpMaster master = ModbusIpMaster.CreateIp(tcpClient);