/*@!Encoding:1252*/ includes { #include "UdpCommon.cin" #include "ModbusClientCommon.cin" } void ModbusConnectTo(char Remote_IP[], word Remote_Port) { UdpConnectTo("192.168.1.3", 502); } void ModbusSend(byte buffer[]) { UdpSnd(buffer); } void ModbusRecv() { UdpRecv(); } void OnUdpReceiveFrom(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, "<%BASE_FILE_NAME%> OnTcpReceive: Socket closed by peer"); gSocket.Close(); gSocketState = CLOSED; } else { // Sucessfully received some bytes over the TCP/IP connection. OnModbusReceive(buffer, size); UdpRecv(); } } else { gIpLastErr = gSocket.GetLastSocketError(); gSocket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr)); writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr); gSocket.Close(); gSocketState = CLOSED; } }