Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
b4969997
Commit
b4969997
authored
Oct 09, 2013
by
Claes Sjofors
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modbus TCP, configuration of max slave timeout added
parent
ade88e3b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
16 deletions
+54
-16
otherio/lib/rt/src/os_linux/rt_io_m_mb_tcp_slave.c
otherio/lib/rt/src/os_linux/rt_io_m_mb_tcp_slave.c
+37
-13
otherio/lib/rt/src/os_linux/rt_io_mb_locals.h
otherio/lib/rt/src/os_linux/rt_io_mb_locals.h
+2
-1
otherio/wbl/mcomp/src/otherio.wb_load
otherio/wbl/mcomp/src/otherio.wb_load
+15
-2
No files found.
otherio/lib/rt/src/os_linux/rt_io_m_mb_tcp_slave.c
View file @
b4969997
...
...
@@ -202,20 +202,39 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sts
=
select
((
int
)
local
->
s
+
1
,
&
fdr
,
NULL
,
NULL
,
&
tv
);
if
(
sts
<=
0
)
{
// Timeout or error.
if
((
sts
==
0
)
&&
(
local
->
expected_msgs
>
0
))
{
// Timeout but there are messages pending
local
->
msgs_lost
++
;
if
(
local
->
msgs_lost
>
MAX_MSGS_LOST
)
{
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
errh_Error
(
"Data expected but timeout. Connection down to modbus slave, %s"
,
rp
->
Name
);
}
return
IO__SUCCESS
;
if
((
sts
==
0
)
&&
(
local
->
expected_msgs
>
0
))
{
// Timeout but there are messages pending
local
->
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
;
close
(
local
->
s
);
errh_Error
(
"Data expected but timeout. Connection down to modbus slave, %s"
,
rp
->
Name
);
local
->
timeout
=
0
;
}
}
return
IO__SUCCESS
;
}
if
(
sts
<
0
)
{
// Error in the socket
sp
->
Status
=
MB__CONNLOST
;
close
(
local
->
s
);
errh_Error
(
"Socket Error. Connection lost to modbus slave, %s"
,
rp
->
Name
);
local
->
timeout
=
0
;
return
IO__SUCCESS
;
}
...
...
@@ -226,12 +245,14 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sp
->
Status
=
MB__CONNLOST
;
close
(
local
->
s
);
errh_Error
(
"Error reading data. Connection lost to modbus slave, %s"
,
rp
->
Name
);
local
->
timeout
=
0
;
return
IO__SUCCESS
;
}
if
(
data_size
==
0
)
{
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
local
->
timeout
=
0
;
errh_Error
(
"Error reading data. Connection down to modbus slave, %s"
,
rp
->
Name
);
return
IO__SUCCESS
;
}
...
...
@@ -249,6 +270,7 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
sp
->
Status
=
MB__CONNDOWN
;
close
(
local
->
s
);
errh_Error
(
"Invalid Modbus packet. Connection down to modbus slave, %s"
,
rp
->
Name
);
local
->
timeout
=
0
;
return
IO__SUCCESS
;
}
...
...
@@ -261,6 +283,8 @@ pwr_tStatus mb_recv_data(io_sRackLocal *local,
if
(
sts
>
0
)
{
// processing packet...
local
->
msgs_lost
=
0
;
local
->
timeout
=
0
;
sp
->
RX_packets
++
;
local
->
expected_msgs
--
;
cardp
=
rp
->
cardlist
;
...
...
@@ -631,7 +655,7 @@ pwr_tStatus mb_send_data(io_sRackLocal *local,
if
(
sp
->
SingleOp
)
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
;
...
...
@@ -841,8 +865,8 @@ static pwr_tStatus IoRackRead (
/* Reconnect */
time_GetTimeMonotonic
(
&
now
);
time_Adiff
(
&
dt
,
&
now
,
&
local
->
last_try_connect_time
);
if
(
dt
.
tv_sec
>=
(
1
<<
MIN
(
sp
->
ReconnectCount
,
6
)))
{
time_Adiff
(
&
dt
,
&
now
,
&
local
->
last_try_connect_time
);
if
(
dt
.
tv_sec
>=
(
1
<<
MIN
(
sp
->
ReconnectCount
,
6
)))
{
sts
=
connect_slave
(
local
,
rp
);
if
(
sts
>=
0
)
{
sp
->
ReconnectCount
=
0
;
...
...
@@ -855,7 +879,7 @@ static pwr_tStatus IoRackRead (
}
/* Receive data */
if
(
(
sp
->
Status
==
MB__NORMAL
)
&&
!
sp
->
SingleOp
)
{
if
(
sp
->
Status
==
MB__NORMAL
&&
!
sp
->
SingleOp
)
{
sts
=
mb_recv_data
(
local
,
rp
,
sp
);
}
...
...
@@ -900,7 +924,7 @@ static pwr_tStatus IoRackWrite (
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
);
}
...
...
otherio/lib/rt/src/os_linux/rt_io_mb_locals.h
View file @
b4969997
...
...
@@ -39,7 +39,6 @@
#endif
#define IO_MAXCHAN 96
#define MAX_MSGS_LOST 5
// These constants are obsolete from V4.1, except for the old style
// (Pb_Di, Pb_Do etc)
...
...
@@ -99,6 +98,8 @@ typedef struct {
int
expected_msgs
;
int
msgs_lost
;
pwr_tTime
last_try_connect_time
;
pwr_tTime
timeout_time
;
int
timeout
;
}
io_sRackLocal
;
typedef
struct
{
...
...
otherio/wbl/mcomp/src/otherio.wb_load
View file @
b4969997
...
...
@@ -2179,7 +2179,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
Object RtBody $ObjBodyDef 1 08-FEB-2008 10:26:36.84
Body SysBody 08-FEB-2008 10:26:36.85
Attr StructName = "Modbus_TCP_Slave"
Attr NextAix = "_X2
1
"
Attr NextAix = "_X2
2
"
EndBody
!/**
! Description of slave
...
...
@@ -2355,6 +2355,18 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
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.
! 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.
...
...
@@ -2447,11 +2459,12 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
EndObject
Object Template Modbus_TCP_Slave 2148499456 01-JAN-1970 01:00:00.00
Body RtBody 0
5-SEP-2008 11:08:41.87
Body RtBody 0
9-OCT-2013 11:01:20.19
Attr Process = 1
Attr ErrorLimit = 50
Attr ReconnectLimit = 5
Attr ResponseTime = 200
Attr MaxTimeout = 2.000000e+00
EndBody
EndObject
EndObject
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment