This commit is contained in:
parent
fa0c64aa32
commit
1c601ebb99
2 changed files with 18 additions and 18 deletions
|
@ -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
|
// Here: The method will open a TCP socket and connect to the remote device
|
||||||
word _ModbusConnectTo(dword remoteIp, word remotePort)
|
word _ModbusConnectTo(dword remoteIp, word remotePort)
|
||||||
{
|
{
|
||||||
long fehler;
|
long error;
|
||||||
|
|
||||||
// Try to open a socket
|
// Try to open a socket
|
||||||
fehler = _TcpOpenSocket();
|
error = _TcpOpenSocket();
|
||||||
if (fehler != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
gSocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return fehler;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
gRemoteIP = remoteIp;
|
gRemoteIP = remoteIp;
|
||||||
|
@ -89,14 +89,14 @@ word _ModbusConnectTo(dword remoteIp, word remotePort)
|
||||||
// Connect to Server
|
// Connect to Server
|
||||||
if (gSocket.Connect(remoteIp, remotePort) != 0)
|
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;
|
gSocketState = ERROR;
|
||||||
OnModbusClientPanics(ConnectionError);
|
OnModbusClientPanics(ConnectionError);
|
||||||
return fehler;
|
return error;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,7 @@ word _ModbusConnectTo(dword remoteIp, word remotePort)
|
||||||
}
|
}
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +177,8 @@ word _ModbusSnd(byte buffer[], word length)
|
||||||
|
|
||||||
switch (gSocketState)
|
switch (gSocketState)
|
||||||
{
|
{
|
||||||
|
case OK: // Go on and send
|
||||||
|
break;
|
||||||
case CLOSED: // If the connection is closed
|
case CLOSED: // If the connection is closed
|
||||||
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
||||||
if (gSocketState < OK) // If this didn't work (state != OK)
|
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
|
return 1; // Abort sending in all cases
|
||||||
}
|
}
|
||||||
case OK:
|
|
||||||
break;
|
|
||||||
case NULL: // Delay
|
case NULL: // Delay
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -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
|
// 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)
|
word _ModbusConnectTo(dword remoteIp, word remotePort)
|
||||||
{
|
{
|
||||||
long fehler;
|
long error;
|
||||||
|
|
||||||
// Try to open a socket
|
// Try to open a socket
|
||||||
fehler = _UdpOpenSocket();
|
error = _UdpOpenSocket();
|
||||||
if (fehler != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
gSocketState = ERROR;
|
gSocketState = ERROR;
|
||||||
return fehler;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
gRemoteIP = remoteIp;
|
gRemoteIP = remoteIp;
|
||||||
|
@ -133,6 +133,8 @@ byte _ModbusSnd(byte buffer[], word length)
|
||||||
|
|
||||||
switch (gSocketState)
|
switch (gSocketState)
|
||||||
{
|
{
|
||||||
|
case OK: // Send
|
||||||
|
break;
|
||||||
case CLOSED: // If the connection is closed
|
case CLOSED: // If the connection is closed
|
||||||
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
||||||
if (gSocketState != OK) // If this didn't work
|
if (gSocketState != OK) // If this didn't work
|
||||||
|
@ -141,8 +143,6 @@ byte _ModbusSnd(byte buffer[], word length)
|
||||||
OnModbusClientPanics(ConnectionError);
|
OnModbusClientPanics(ConnectionError);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
case OK:
|
|
||||||
break;
|
|
||||||
case NULL: // Delay
|
case NULL: // Delay
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue