From 1c601ebb99fbf8c0a929ce292bf3b797f22f77aa Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Tue, 15 Jul 2014 16:47:29 +0000 Subject: [PATCH] --- .../include/CAPL/include/ModbusTcp.cin | 24 +++++++++---------- .../include/CAPL/include/ModbusUdp.cin | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Modbus-CAPL/include/CAPL/include/ModbusTcp.cin b/Modbus-CAPL/include/CAPL/include/ModbusTcp.cin index 8c7b373..d359359 100644 --- a/Modbus-CAPL/include/CAPL/include/ModbusTcp.cin +++ b/Modbus-CAPL/include/CAPL/include/ModbusTcp.cin @@ -72,14 +72,14 @@ word _ModbusConnectTo(char Remote_IP[], word remotePort) // Here: The method will open a TCP socket and connect to the remote device word _ModbusConnectTo(dword remoteIp, word remotePort) { - long fehler; + long error; // Try to open a socket - fehler = _TcpOpenSocket(); - if (fehler != 0) + error = _TcpOpenSocket(); + if (error != 0) { gSocketState = ERROR; - return fehler; + return error; } gRemoteIP = remoteIp; @@ -89,14 +89,14 @@ word _ModbusConnectTo(dword remoteIp, word remotePort) // Connect to Server if (gSocket.Connect(remoteIp, remotePort) != 0) { - fehler = gSocket.GetLastSocketError(); + error = gSocket.GetLastSocketError(); - if (fehler != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise + if (error != WSAEWOULDBLOCK) // OnTcpConnect will be called otherwise { - writeDbg(ConnError, "_ModbusConnectTo: No connection established: %d", fehler); + writeDbg(ConnError, "_ModbusConnectTo: No connection established: %d", error); gSocketState = ERROR; OnModbusClientPanics(ConnectionError); - return fehler; + return error; } else { @@ -105,7 +105,7 @@ word _ModbusConnectTo(dword remoteIp, word remotePort) } return 0; } - gSocketState = CONNECTING; // Don't set state OK because the Stack doesn't tell us WSAEWOULDBLOCK + gSocketState = CONNECTING; // Don't set state OK because the Stack doesn't tell us WSAEWOULDBLOCK each time whensoever is neccessary return 0; } @@ -177,6 +177,8 @@ word _ModbusSnd(byte buffer[], word length) switch (gSocketState) { + case OK: // Go on and send + break; case CLOSED: // If the connection is closed _ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect if (gSocketState < OK) // If this didn't work (state != OK) @@ -188,8 +190,6 @@ word _ModbusSnd(byte buffer[], word length) } return 1; // Abort sending in all cases } - case OK: - break; case NULL: // Delay case CONNECTING: return 1; @@ -204,7 +204,7 @@ word _ModbusSnd(byte buffer[], word length) } bin_to_strhex(buffer, str); - + if (gSocket.Send(buffer, length) != 0) { gIpLastErr = gSocket.GetLastSocketError(); diff --git a/Modbus-CAPL/include/CAPL/include/ModbusUdp.cin b/Modbus-CAPL/include/CAPL/include/ModbusUdp.cin index 32d653e..b4f4df2 100644 --- a/Modbus-CAPL/include/CAPL/include/ModbusUdp.cin +++ b/Modbus-CAPL/include/CAPL/include/ModbusUdp.cin @@ -71,14 +71,14 @@ word _ModbusConnectTo(char Remote_IP[], word remotePort) // Here: The method will open a UDP socket and save the IP and Port in global variables so they can be used when sending word _ModbusConnectTo(dword remoteIp, word remotePort) { - long fehler; + long error; // Try to open a socket - fehler = _UdpOpenSocket(); - if (fehler != 0) + error = _UdpOpenSocket(); + if (error != 0) { gSocketState = ERROR; - return fehler; + return error; } gRemoteIP = remoteIp; @@ -133,6 +133,8 @@ byte _ModbusSnd(byte buffer[], word length) switch (gSocketState) { + case OK: // Send + break; case CLOSED: // If the connection is closed _ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect if (gSocketState != OK) // If this didn't work @@ -141,8 +143,6 @@ byte _ModbusSnd(byte buffer[], word length) OnModbusClientPanics(ConnectionError); return 1; } - case OK: - break; case NULL: // Delay case CONNECTING: return 1;