Commit b4969997 authored by Claes Sjofors's avatar Claes Sjofors

Modbus TCP, configuration of max slave timeout added

parent ade88e3b
...@@ -204,10 +204,28 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local, ...@@ -204,10 +204,28 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
if (sts<=0) { // Timeout or error. if (sts<=0) { // Timeout or error.
if ((sts == 0) && (local->expected_msgs > 0)) { // Timeout but there are messages pending if ((sts == 0) && (local->expected_msgs > 0)) { // Timeout but there are messages pending
local->msgs_lost++; local->msgs_lost++;
if (local->msgs_lost > MAX_MSGS_LOST) {
if ( !local->timeout) {
time_GetTimeMonotonic( &local->timeout_time);
local->timeout = 1;
}
else {
pwr_tTime now;
pwr_tDeltaTime dt;
pwr_tDeltaTime max_dt;
float max_timeout = sp->MaxTimeout;
if ( max_timeout == 0)
max_timeout = 2;
time_FloatToD( &max_dt, max_timeout);
time_GetTimeMonotonic( &now);
time_Adiff(&dt, &now, &local->timeout_time);
if ( time_Dcomp( &dt, &max_dt) > 0) {
sp->Status = MB__CONNDOWN; sp->Status = MB__CONNDOWN;
close(local->s); close(local->s);
errh_Error( "Data expected but timeout. Connection down to modbus slave, %s", rp->Name); errh_Error( "Data expected but timeout. Connection down to modbus slave, %s", rp->Name);
local->timeout = 0;
}
} }
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -216,6 +234,7 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local, ...@@ -216,6 +234,7 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sp->Status = MB__CONNLOST; sp->Status = MB__CONNLOST;
close(local->s); close(local->s);
errh_Error( "Socket Error. Connection lost to modbus slave, %s", rp->Name); errh_Error( "Socket Error. Connection lost to modbus slave, %s", rp->Name);
local->timeout = 0;
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -226,12 +245,14 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local, ...@@ -226,12 +245,14 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sp->Status = MB__CONNLOST; sp->Status = MB__CONNLOST;
close(local->s); close(local->s);
errh_Error( "Error reading data. Connection lost to modbus slave, %s", rp->Name); errh_Error( "Error reading data. Connection lost to modbus slave, %s", rp->Name);
local->timeout = 0;
return IO__SUCCESS; return IO__SUCCESS;
} }
if (data_size == 0) { if (data_size == 0) {
sp->Status = MB__CONNDOWN; sp->Status = MB__CONNDOWN;
close(local->s); close(local->s);
local->timeout = 0;
errh_Error( "Error reading data. Connection down to modbus slave, %s", rp->Name); errh_Error( "Error reading data. Connection down to modbus slave, %s", rp->Name);
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -249,6 +270,7 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local, ...@@ -249,6 +270,7 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sp->Status = MB__CONNDOWN; sp->Status = MB__CONNDOWN;
close(local->s); close(local->s);
errh_Error( "Invalid Modbus packet. Connection down to modbus slave, %s", rp->Name); errh_Error( "Invalid Modbus packet. Connection down to modbus slave, %s", rp->Name);
local->timeout = 0;
return IO__SUCCESS; return IO__SUCCESS;
} }
...@@ -261,6 +283,8 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local, ...@@ -261,6 +283,8 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
if (sts > 0) { // processing packet... if (sts > 0) { // processing packet...
local->msgs_lost = 0; local->msgs_lost = 0;
local->timeout = 0;
sp->RX_packets++; sp->RX_packets++;
local->expected_msgs--; local->expected_msgs--;
cardp = rp->cardlist; cardp = rp->cardlist;
...@@ -631,7 +655,7 @@ pwr_tStatus mb_send_data(io_sRackLocal *local, ...@@ -631,7 +655,7 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
if (sp->SingleOp) if (sp->SingleOp)
sts = mb_recv_data(local, rp, sp); sts = mb_recv_data(local, rp, sp);
if (sp->Status != MB__NORMAL) return IO__SUCCESS; if ( sp->Status != MB__NORMAL) return IO__SUCCESS;
cardp = cardp->next; cardp = cardp->next;
...@@ -855,7 +879,7 @@ static pwr_tStatus IoRackRead ( ...@@ -855,7 +879,7 @@ static pwr_tStatus IoRackRead (
} }
/* Receive data */ /* Receive data */
if ((sp->Status == MB__NORMAL) && !sp->SingleOp) { if ( sp->Status == MB__NORMAL && !sp->SingleOp) {
sts = mb_recv_data(local, rp, sp); sts = mb_recv_data(local, rp, sp);
} }
...@@ -900,7 +924,7 @@ static pwr_tStatus IoRackWrite ( ...@@ -900,7 +924,7 @@ static pwr_tStatus IoRackWrite (
local->expected_msgs = 0; local->expected_msgs = 0;
if (sp->Status == MB__NORMAL && sp->DisableSlave != 1) { if ( sp->Status == MB__NORMAL && sp->DisableSlave != 1) {
sts = mb_send_data(local, rp, sp, mb_mSendMask_WriteReq); sts = mb_send_data(local, rp, sp, mb_mSendMask_WriteReq);
} }
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#endif #endif
#define IO_MAXCHAN 96 #define IO_MAXCHAN 96
#define MAX_MSGS_LOST 5
// These constants are obsolete from V4.1, except for the old style // These constants are obsolete from V4.1, except for the old style
// (Pb_Di, Pb_Do etc) // (Pb_Di, Pb_Do etc)
...@@ -99,6 +98,8 @@ typedef struct { ...@@ -99,6 +98,8 @@ typedef struct {
int expected_msgs; int expected_msgs;
int msgs_lost; int msgs_lost;
pwr_tTime last_try_connect_time; pwr_tTime last_try_connect_time;
pwr_tTime timeout_time;
int timeout;
} io_sRackLocal; } io_sRackLocal;
typedef struct { typedef struct {
......
...@@ -2179,7 +2179,7 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -2179,7 +2179,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
Object RtBody $ObjBodyDef 1 08-FEB-2008 10:26:36.84 Object RtBody $ObjBodyDef 1 08-FEB-2008 10:26:36.84
Body SysBody 08-FEB-2008 10:26:36.85 Body SysBody 08-FEB-2008 10:26:36.85
Attr StructName = "Modbus_TCP_Slave" Attr StructName = "Modbus_TCP_Slave"
Attr NextAix = "_X21" Attr NextAix = "_X22"
EndBody EndBody
!/** !/**
! Description of slave ! Description of slave
...@@ -2355,6 +2355,18 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -2355,6 +2355,18 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody EndBody
EndObject EndObject
!/** !/**
! Maximum timeout. I no messages is received within this time the
! connection to the slave is closed, and a new connection is opened.
! The value should be greater than the TCP retransmit time.
!*/
Object MaxTimeout $Attribute 21 09-OCT-2013 11:00:36.49
Body SysBody 09-OCT-2013 11:00:46.65
Attr PgmName = "MaxTimeout"
Attr Size = 4
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/**
! @Summary Single operation. ! @Summary Single operation.
! Depending on the tcp stack used in the slave and also the size of its receive ! Depending on the tcp stack used in the slave and also the size of its receive
! buffer it may not be possible to send several requests at a time to a slave. ! buffer it may not be possible to send several requests at a time to a slave.
...@@ -2447,11 +2459,12 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -2447,11 +2459,12 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody EndBody
EndObject EndObject
Object Template Modbus_TCP_Slave 2148499456 01-JAN-1970 01:00:00.00 Object Template Modbus_TCP_Slave 2148499456 01-JAN-1970 01:00:00.00
Body RtBody 05-SEP-2008 11:08:41.87 Body RtBody 09-OCT-2013 11:01:20.19
Attr Process = 1 Attr Process = 1
Attr ErrorLimit = 50 Attr ErrorLimit = 50
Attr ReconnectLimit = 5 Attr ReconnectLimit = 5
Attr ResponseTime = 200 Attr ResponseTime = 200
Attr MaxTimeout = 2.000000e+00
EndBody EndBody
EndObject EndObject
EndObject EndObject
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment