Bachelorthesis/Modbus/ModbusUdpClientCommon.cin
2014-05-09 13:39:16 +00:00

51 lines
No EOL
1.2 KiB
Text

/*@!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");
g_%NODE_NAME%_Socket.Close();
g_%NODE_NAME%_SocketState = CLOSED;
}
else
{
// Sucessfully received some bytes over the TCP/IP connection.
OnModbusReceive(buffer, size);
UdpRecv();
}
}
else
{
gIpLastErr = g_%NODE_NAME%_Socket.GetLastSocketError();
g_%NODE_NAME%_Socket.GetLastSocketErrorAsString(gIpLastErrStr, elcount(gIpLastErrStr));
writeLineEx(0, 2, "<%BASE_FILE_NAME%> OnTcpReceive error (%d): %s", gIpLastErr, gIpLastErrStr);
g_%NODE_NAME%_Socket.Close();
g_%NODE_NAME%_SocketState = CLOSED;
}
}