/*@!Encoding:1252*/ includes { #include "TcpCommon.cin" #include "ModbusClientCommon.cin" } void ModbusConnectTo(char Remote_IP[], word Remote_Port) { TcpConnectTo("192.168.1.3", 502); } void ModbusSend(byte buffer[]) { TcpSnd(buffer); } void ModbusRecv() { TcpRecv(); } void OnTcpReceive(dword socket, long result, dword address, dword port, byte buffer[], dword size) { if (result == 0) { if (size == 0) { // Size of zero indicates that the socket was closed by the communication peer. writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive: Socket closed by peer"); gSocket.Close(); gSocketState = CLOSED; } else { // Sucessfully received some bytes over the TCP/IP connection. OnModbusReceive(buffer, size); TcpRecv(); } } else { gIpLastErr = gSocket.GetLastSocketError(); gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); writeLineEx(0, 2, "<%NODE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr); gSocket.Close(); gSocketState = CLOSED; } }