Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
1aa7a6a5
Commit
1aa7a6a5
authored
Nov 20, 2009
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug in MBTCPMaster and minor fixed in debug logs
parent
9e44a19f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
21 deletions
+64
-21
test.xml
conf/test.xml
+4
-3
MBTCPMaster.cc
extensions/MBTCPMaster/MBTCPMaster.cc
+9
-6
main.cc
extensions/MBTCPMaster/main.cc
+1
-1
start_fg.sh
extensions/MBTCPMaster/start_fg.sh
+9
-5
SharedMemory.cc
extensions/SharedMemory/SharedMemory.cc
+23
-2
ModbusTCPMaster.cc
src/Communications/Modbus/ModbusTCPMaster.cc
+18
-4
No files found.
conf/test.xml
View file @
1aa7a6a5
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
<RSExchange
name=
"RSExchange"
speed=
"38400"
>
<RSExchange
name=
"RSExchange"
speed=
"38400"
>
<DeviceList>
<DeviceList>
<item
addr=
"0x02"
speed=
"9600"
respondSensor=
"R
TU_Not_Respond_FS"
timeout=
"2
000"
invert=
"0"
/>
<item
addr=
"0x02"
speed=
"9600"
respondSensor=
"R
espondRTU_S"
timeout=
"5
000"
invert=
"0"
/>
</DeviceList>
</DeviceList>
</RSExchange>
</RSExchange>
...
@@ -103,7 +103,7 @@
...
@@ -103,7 +103,7 @@
textname -
textname -
-->
-->
<nodes
port=
"2809"
>
<nodes
port=
"2809"
>
<item
name=
"LocalhostNode"
alias=
""
textname=
" "
ip=
"127.0.0.1"
infserver=
"InfoServer"
dbserver=
"
DBServer
"
/>
<item
name=
"LocalhostNode"
alias=
""
textname=
" "
ip=
"127.0.0.1"
infserver=
"InfoServer"
dbserver=
""
/>
<item
name=
"Node2"
alias=
""
textname=
" "
ip=
"127.0.0.1"
infserver=
"InfoServer"
dbserver=
""
/>
<item
name=
"Node2"
alias=
""
textname=
" "
ip=
"127.0.0.1"
infserver=
"InfoServer"
dbserver=
""
/>
</nodes>
</nodes>
...
@@ -111,7 +111,8 @@
...
@@ -111,7 +111,8 @@
<sensors
name=
"Sensors"
>
<sensors
name=
"Sensors"
>
<item
name=
"Input1_S"
textname=
" 1"
node=
""
iotype=
"DI"
priority=
"Medium"
default=
"1"
/>
<item
name=
"Input1_S"
textname=
" 1"
node=
""
iotype=
"DI"
priority=
"Medium"
default=
"1"
/>
<item
name=
"Input2_S"
textname=
" 2"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtype=
"rtu"
mbaddr=
"0x01"
mbfunc=
"0x04"
mbreg=
"0x02"
rs=
"2"
/>
<item
name=
"Input2_S"
textname=
" 2"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtype=
"rtu"
mbaddr=
"0x01"
mbfunc=
"0x04"
mbreg=
"0x02"
rs=
"2"
/>
<item
name=
"Input3_S"
textname=
" 3"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtcp=
"1"
mbaddr=
"0x02"
mbfunc=
"0x04"
mbreg=
"0x02"
/>
<item
name=
"Input3_S"
textname=
" 3"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtcp=
"1"
tcp_mbtype=
"rtu"
tcp_mbaddr=
"0x02"
tcp_mbfunc=
"0x04"
tcp_mbreg=
"0x02"
/>
<item
name=
"Input4_S"
textname=
" 4"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtype=
"rtu"
mbaddr=
"0x02"
mbfunc=
"0x04"
mbreg=
"0x02"
rs=
"2"
/>
<item
name=
"Input4_S"
textname=
" 4"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtype=
"rtu"
mbaddr=
"0x02"
mbfunc=
"0x04"
mbreg=
"0x02"
rs=
"2"
/>
<item
name=
"Input5_S"
textname=
" 5"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"2"
/>
<item
name=
"Input5_S"
textname=
" 5"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"2"
/>
<item
name=
"Input6_S"
textname=
" 6"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"2"
>
<item
name=
"Input6_S"
textname=
" 6"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"2"
>
...
...
extensions/MBTCPMaster/MBTCPMaster.cc
View file @
1aa7a6a5
...
@@ -192,7 +192,7 @@ void MBTCPMaster::waitSMReady()
...
@@ -192,7 +192,7 @@ void MBTCPMaster::waitSMReady()
if
(
!
shm
->
waitSMready
(
ready_timeout
,
50
)
)
if
(
!
shm
->
waitSMready
(
ready_timeout
,
50
)
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
myname
<<
"(waitSMReady):
SharedMemory "
<<
ready_timeout
<<
"
"
;
err
<<
myname
<<
"(waitSMReady):
failed waiting SharedMemory "
<<
ready_timeout
<<
" msec
"
;
dlog
[
Debug
::
CRIT
]
<<
err
.
str
()
<<
endl
;
dlog
[
Debug
::
CRIT
]
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
@@ -254,6 +254,7 @@ void MBTCPMaster::poll()
...
@@ -254,6 +254,7 @@ void MBTCPMaster::poll()
for
(
MBTCPMaster
::
RTUDeviceMap
::
iterator
it
=
rmap
.
begin
();
it
!=
rmap
.
end
();
++
it
)
for
(
MBTCPMaster
::
RTUDeviceMap
::
iterator
it
=
rmap
.
begin
();
it
!=
rmap
.
end
();
++
it
)
it
->
second
->
resp_real
=
false
;
it
->
second
->
resp_real
=
false
;
}
}
cerr
<<
"*********** mb=NULL "
<<
endl
;
updateSM
();
updateSM
();
return
;
return
;
}
}
...
@@ -393,7 +394,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
...
@@ -393,7 +394,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return
false
;
return
false
;
}
}
cerr
<<
"**** mbreg="
<<
ModbusRTU
::
dat2str
(
p
->
mbreg
)
<<
" val="
<<
ModbusRTU
::
dat2str
(
p
->
mbval
)
<<
endl
;
//
cerr << "**** mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
ModbusRTU
::
WriteSingleOutputRetMessage
ret
=
mb
->
write06
(
dev
->
mbaddr
,
p
->
mbreg
+
p
->
offset
,
p
->
mbval
);
ModbusRTU
::
WriteSingleOutputRetMessage
ret
=
mb
->
write06
(
dev
->
mbaddr
,
p
->
mbreg
+
p
->
offset
,
p
->
mbval
);
}
}
break
;
break
;
...
@@ -417,7 +418,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
...
@@ -417,7 +418,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return
false
;
return
false
;
}
}
cerr
<<
"****(coil) mbreg="
<<
ModbusRTU
::
dat2str
(
p
->
mbreg
)
<<
" val="
<<
ModbusRTU
::
dat2str
(
p
->
mbval
)
<<
endl
;
//
cerr << "****(coil) mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
ModbusRTU
::
ForceSingleCoilRetMessage
ret
=
mb
->
write05
(
dev
->
mbaddr
,
p
->
mbreg
+
p
->
offset
,
p
->
mbval
);
ModbusRTU
::
ForceSingleCoilRetMessage
ret
=
mb
->
write05
(
dev
->
mbaddr
,
p
->
mbreg
+
p
->
offset
,
p
->
mbval
);
}
}
break
;
break
;
...
@@ -478,13 +479,15 @@ void MBTCPMaster::updateSM()
...
@@ -478,13 +479,15 @@ void MBTCPMaster::updateSM()
for
(
MBTCPMaster
::
RTUDeviceMap
::
iterator
it1
=
rmap
.
begin
();
it1
!=
rmap
.
end
();
++
it1
)
for
(
MBTCPMaster
::
RTUDeviceMap
::
iterator
it1
=
rmap
.
begin
();
it1
!=
rmap
.
end
();
++
it1
)
{
{
RTUDevice
*
d
(
it1
->
second
);
RTUDevice
*
d
(
it1
->
second
);
/*
cout << "check respond addr=" << ModbusRTU::addr2str(d->mbaddr)
if
(
dlog
.
debugging
(
Debug
::
LEVEL4
)
)
{
dlog
[
Debug
::
LEVEL4
]
<<
"check respond addr="
<<
ModbusRTU
::
addr2str
(
d
->
mbaddr
)
<<
" respond="
<<
d
->
resp_id
<<
" respond="
<<
d
->
resp_id
<<
" real="
<<
d
->
resp_real
<<
" real="
<<
d
->
resp_real
<<
" state="
<<
d
->
resp_state
<<
" state="
<<
d
->
resp_state
<<
endl
;
<<
endl
;
*/
}
if
(
d
->
resp_real
)
if
(
d
->
resp_real
)
allNotRespond
=
false
;
allNotRespond
=
false
;
...
...
extensions/MBTCPMaster/main.cc
View file @
1aa7a6a5
...
@@ -56,7 +56,7 @@ int main( int argc, const char** argv )
...
@@ -56,7 +56,7 @@ int main( int argc, const char** argv )
MBTCPMaster
*
mb
=
MBTCPMaster
::
init_mbmaster
(
argc
,
argv
,
shmID
);
MBTCPMaster
*
mb
=
MBTCPMaster
::
init_mbmaster
(
argc
,
argv
,
shmID
);
if
(
!
mb
)
if
(
!
mb
)
{
{
dlog
[
Debug
::
CRIT
]
<<
"(mbmaster): init
ۣ..
."
<<
endl
;
dlog
[
Debug
::
CRIT
]
<<
"(mbmaster): init
MBTCPMaster failed
."
<<
endl
;
return
1
;
return
1
;
}
}
...
...
extensions/MBTCPMaster/start_fg.sh
View file @
1aa7a6a5
#!/bin/sh
#!/bin/sh
uniset-start.sh
-f
./uniset-mbtcpmaster
--mbtcp-name
MBTCPExchange1
\
uniset-start.sh
-f
./uniset-mbtcpmaster
\
--dlog-add-levels
info,crit,warn
\
--confile
test.xml
\
--mbtcp-filter-field
CAN2sender
\
--mbtcp-name
MBMaster1
\
--mbtcp-filter-value
SYSTSNode
\
--smemory-id
SharedMemory
\
--dlog-add-levels
info,crit,warn,level4
\
--mbtcp-filter-field
mbtcp
\
--mbtcp-filter-value
1
\
--mbtcp-gateway-iaddr
127.0.0.1
\
--mbtcp-gateway-iaddr
127.0.0.1
\
--mbtcp-gateway-port
2048
--mbtcp-gateway-port
1024
\
--mbtcp-recv-timeout
5000
#--mbtcp-filter-field mbtcp --mbtcp-filter-value 1
#--mbtcp-filter-field mbtcp --mbtcp-filter-value 1
extensions/SharedMemory/SharedMemory.cc
View file @
1aa7a6a5
...
@@ -17,8 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
...
@@ -17,8 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
activated
(
false
),
activated
(
false
),
workready
(
false
),
workready
(
false
),
dblogging
(
false
),
dblogging
(
false
),
msecPulsar
(
0
),
iotypePulsar
(
UniversalIO
::
DigitalInput
),
iotypePulsar
(
UniversalIO
::
DigitalInput
)
msecPulsar
(
0
)
{
{
// cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl;
// cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl;
...
@@ -168,6 +168,25 @@ void SharedMemory::processingMessage( UniSetTypes::VoidMessage *msg )
...
@@ -168,6 +168,25 @@ void SharedMemory::processingMessage( UniSetTypes::VoidMessage *msg )
{
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(processingMessage): "
<<
ex
<<
endl
;
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(processingMessage): "
<<
ex
<<
endl
;
}
}
catch
(
CORBA
::
SystemException
&
ex
)
{
dlog
[
Debug
::
WARN
]
<<
myname
<<
"(processingMessage): CORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(
CORBA
::
Exception
&
ex
)
{
dlog
[
Debug
::
WARN
]
<<
myname
<<
"(processingMessage): CORBA::Exception: "
<<
ex
.
_name
()
<<
endl
;
}
catch
(
omniORB
::
fatalException
&
fe
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(processingMessage): Caught omniORB::fatalException:"
<<
endl
;
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(processingMessage): file: "
<<
fe
.
file
()
<<
" line: "
<<
fe
.
line
()
<<
" mesg: "
<<
fe
.
errmsg
()
<<
endl
;
}
catch
(...)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(processingMessage): catch..."
<<
endl
;
}
}
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
...
@@ -281,6 +300,7 @@ bool SharedMemory::activateObject()
...
@@ -281,6 +300,7 @@ bool SharedMemory::activateObject()
{
{
PassiveTimer
pt
(
UniSetTimer
::
WaitUpTime
);
PassiveTimer
pt
(
UniSetTimer
::
WaitUpTime
);
bool
res
=
true
;
bool
res
=
true
;
// Startup
// Startup
// ģ
// ģ
// . sysCommand()
// . sysCommand()
...
@@ -311,6 +331,7 @@ bool SharedMemory::activateObject()
...
@@ -311,6 +331,7 @@ bool SharedMemory::activateObject()
activated
=
true
;
activated
=
true
;
}
}
cerr
<<
"************************** activate: "
<<
pt
.
getCurrent
()
<<
" msec "
<<
endl
;
cerr
<<
"************************** activate: "
<<
pt
.
getCurrent
()
<<
" msec "
<<
endl
;
return
res
;
return
res
;
}
}
...
...
src/Communications/Modbus/ModbusTCPMaster.cc
View file @
1aa7a6a5
...
@@ -93,23 +93,35 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -93,23 +93,35 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
mbPrintMessage
(
dlog
,
(
ModbusByte
*
)(
&
mh
),
sizeof
(
mh
));
mbPrintMessage
(
dlog
,
(
ModbusByte
*
)(
&
mh
),
sizeof
(
mh
));
dlog
(
Debug
::
INFO
)
<<
endl
;
dlog
(
Debug
::
INFO
)
<<
endl
;
}
}
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
(
*
tcp
)
<<
mh
;
(
*
tcp
)
<<
mh
;
mh
.
swapdata
();
// send PDU
// send PDU
mbErrCode
res
=
send
(
msg
);
mbErrCode
res
=
send
(
msg
);
if
(
res
!=
erNoError
)
if
(
res
!=
erNoError
)
return
res
;
return
res
;
if
(
!
tcp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
timeout
)
)
if
(
tcp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
timeout
)
)
{
break
;
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
"(ModbusTCPMaster): no write pending.. reconnnect.."
<<
endl
;
dlog
[
Debug
::
INFO
]
<<
"(ModbusTCPMaster
::query
): no write pending.. reconnnect.."
<<
endl
;
reconnect
();
reconnect
();
if
(
!
isConnection
()
)
{
dlog
[
Debug
::
WARN
]
<<
"(ModbusTCPMaster::query): not connected to server..."
<<
endl
;
return
erTimeOut
;
return
erTimeOut
;
}
}
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
"(ModbusTCPMaster::query): no write pending.. reconnnect OK"
<<
endl
;
}
mh
.
swapdata
();
if
(
timeout
!=
UniSetTimer
::
WaitUpTime
)
if
(
timeout
!=
UniSetTimer
::
WaitUpTime
)
{
{
timeout
=
ptTimeout
.
getLeft
(
timeout
);
timeout
=
ptTimeout
.
getLeft
(
timeout
);
...
@@ -159,6 +171,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -159,6 +171,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
// return recv_pdu(msg.func,reply,timeout);
// return recv_pdu(msg.func,reply,timeout);
}
}
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
"(query): input pending timeout "
<<
endl
;
return
erTimeOut
;
return
erTimeOut
;
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
ModbusRTU
::
mbException
&
ex
)
...
...
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