This commit is contained in:
Jonny007-MKD 2014-07-15 16:47:29 +00:00
parent fa0c64aa32
commit 1c601ebb99
2 changed files with 18 additions and 18 deletions

View File

@ -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();

View File

@ -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;