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
a2756ef7
Commit
a2756ef7
authored
Mar 18, 2009
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testing
parent
2cebcea4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
390 additions
and
216 deletions
+390
-216
mbtcptester.cc
Utilities/MBTester/mbtcptester.cc
+158
-155
test.xml
conf/test.xml
+1
-1
MBMaster.cc
extentions/MBTCPMaster/MBMaster.cc
+169
-34
MBMaster.h
extentions/MBTCPMaster/MBMaster.h
+6
-2
start_fg.sh
extentions/MBTCPMaster/start_fg.sh
+6
-2
MBSlave.cc
extentions/ModbusSlave/MBSlave.cc
+0
-0
MBSlave.h
extentions/ModbusSlave/MBSlave.h
+4
-4
start_tcp_fg.sh
extentions/ModbusSlave/start_tcp_fg.sh
+5
-2
IOBase.cc
extentions/lib/IOBase.cc
+9
-7
SMInterface.cc
extentions/lib/SMInterface.cc
+4
-4
ModbusTCPMaster.h
include/modbus/ModbusTCPMaster.h
+4
-0
ModbusTCPMaster.cc
src/Communications/Modbus/ModbusTCPMaster.cc
+24
-5
No files found.
Utilities/MBTester/mbtcptester.cc
View file @
a2756ef7
This diff is collapsed.
Click to expand it.
conf/test.xml
View file @
a2756ef7
...
...
@@ -93,7 +93,7 @@
<sensors
name=
"Sensors"
>
<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=
"0x31"
mbfunc=
"0x04"
mbreg=
"0x02"
rs=
"1"
/>
<item
name=
"Input3_S"
textname=
" 3"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"1
"
/>
<item
name=
"Input3_S"
textname=
" 3"
node=
""
iotype=
"DI"
priority=
"Medium"
mbtcp=
"1"
mbaddr=
"0x31"
mbfunc=
"0x04"
mbreg=
"0x02
"
/>
<item
name=
"Input4_S"
textname=
" 4"
node=
""
iotype=
"DI"
priority=
"Medium"
udp=
"1"
/>
<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"
>
...
...
extentions/MBTCPMaster/MBMaster.cc
View file @
a2756ef7
This diff is collapsed.
Click to expand it.
extentions/MBTCPMaster/MBMaster.h
View file @
a2756ef7
...
...
@@ -43,10 +43,11 @@ class MBMaster:
ModbusRTU
::
ModbusAddr
mbaddr
;
/*!< */
ModbusRTU
::
ModbusData
mbreg
;
/*!< */
ModbusRTU
::
SlaveFunctionCode
mbfunc
;
/*!< / */
short
nbit
;
/*!< bit number (for func=[0x01,0x02]) */
MBProperty
()
:
mbaddr
(
0
),
mbreg
(
0
),
mbfunc
(
ModbusRTU
::
fnUnknown
)
mbfunc
(
ModbusRTU
::
fnUnknown
)
,
nbit
(
0
)
{}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
MBProperty
&
p
);
...
...
@@ -80,7 +81,8 @@ class MBMaster:
void
askSensors
(
UniversalIO
::
UIOCommand
cmd
);
void
initOutput
();
void
waitSMReady
();
long
callItem
(
MBMap
::
iterator
&
p
);
long
readReg
(
MBMap
::
iterator
&
p
);
bool
writeReg
(
MBMap
::
iterator
&
p
,
long
val
);
virtual
bool
activateObject
();
...
...
@@ -100,6 +102,7 @@ class MBMaster:
bool
initPause
;
UniSetTypes
::
uniset_mutex
mutex_start
;
bool
mbregFromID
;
bool
force
;
/*!< , SM, */
bool
force_out
;
/*!< , */
int
polltime
;
/*!< , [] */
...
...
@@ -113,6 +116,7 @@ class MBMaster:
Trigger
trTimeout
;
PassiveTimer
ptTimeout
;
bool
activated
;
int
activateTimeout
;
std
::
string
prefix
;
...
...
extentions/MBTCPMaster/start_fg.sh
View file @
a2756ef7
#!/bin/sh
uniset-start.sh
-f
./uniset-mbtcpmaster
--mbtcp-name
MBMaster1
--confile
test.xml
\
--dlog-add-levels
info,crit,warn
--mbtcp-reg-from-id
1
\
--mbtcp-iaddr
127.0.0.1
--mbtcp-port
30000
--dlog-add-levels
info,crit,warn
\
--mbtcp-iaddr
127.0.0.1
--mbtcp-port
2048
\
--mbtcp-filter-field
mbtcp
--mbtcp-filter-value
1
#--mbtcp-reg-from-id 1
\ No newline at end of file
extentions/ModbusSlave/MBSlave.cc
View file @
a2756ef7
This diff is collapsed.
Click to expand it.
extentions/ModbusSlave/MBSlave.h
View file @
a2756ef7
...
...
@@ -13,7 +13,6 @@
#include "PassiveTimer.h"
#include "Trigger.h"
#include "Mutex.h"
#include "Calibration.h"
#include "SMInterface.h"
#include "SharedMemory.h"
#include "IOBase.h"
...
...
@@ -23,12 +22,13 @@ class MBSlave:
public
UniSetObject_LT
{
public
:
MBSlave
(
UniSetTypes
::
ObjectId
objId
,
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
);
MBSlave
(
UniSetTypes
::
ObjectId
objId
,
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
,
std
::
string
prefix
=
"mbs"
);
virtual
~
MBSlave
();
/*! */
static
MBSlave
*
init_mbslave
(
int
argc
,
char
*
argv
[],
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
);
UniSetTypes
::
ObjectId
shmID
,
SharedMemory
*
ic
=
0
,
std
::
string
prefix
=
"mbs"
);
/*! help- */
static
void
help_print
(
int
argc
,
char
*
argv
[]
);
...
...
@@ -172,12 +172,12 @@ class MBSlave:
bool
pingOK
;
int
wait_msec
;
bool
force
;
/*!< , SM, */
bool
force_out
;
/*!< , */
bool
mbregFromID
;
typedef
std
::
map
<
int
,
std
::
string
>
FileList
;
FileList
flist
;
std
::
string
prefix
;
};
// -----------------------------------------------------------------------------
#endif // _MBSlave_H_
...
...
extentions/ModbusSlave/start_tcp_fg.sh
View file @
a2756ef7
#!/bin/sh
uniset-start.sh
-f
./uniset-mbslave
--mbs-name
MBSlave1
--confile
test.xml
--dlog-add-levels
info,crit,warn
\
--mbs-type
TCP
--mbs-inet-addr
127.0.0.2
--mbs-inet-port
2048
--mbs-reg-from-id
1
\ No newline at end of file
--mbs-type
TCP
--mbs-inet-addr
127.0.0.1
--mbs-inet-port
2048
\
--mbs-filter-field
rs
--mbs-filter-value
1
# --mbs-force 1
#--mbs-reg-from-id 1 \
\ No newline at end of file
extentions/lib/IOBase.cc
View file @
a2756ef7
...
...
@@ -252,18 +252,20 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
{
string
sname
(
it
.
getProp
(
"name"
)
);
ObjectId
sid
=
UniSetTypes
::
uni_atoi
(
it
.
getProp
(
"id"
).
c_str
());
if
(
sid
<=
0
)
ObjectId
sid
=
DefaultObjectId
;
if
(
it
.
getProp
(
"id"
).
empty
()
)
sid
=
conf
->
getSensorID
(
sname
);
else
{
if
(
dlog
)
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(readItem): ID : "
<<
sname
<<
endl
;
return
false
;
sid
=
UniSetTypes
::
uni_atoi
(
it
.
getProp
(
"id"
).
c_str
());
if
(
sid
<=
0
)
sid
=
DefaultObjectId
;
}
if
(
sid
==
DefaultObjectId
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(readItem): (-1) ID : "
if
(
dlog
)
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(readItem): (-1) ID : "
<<
sname
<<
endl
;
return
false
;
}
...
...
extentions/lib/SMInterface.cc
View file @
a2756ef7
...
...
@@ -439,16 +439,16 @@ void SMInterface::initAIterator( IOController::AIOStateList::iterator& it )
{
if
(
ic
)
it
=
ic
->
aioEnd
();
else
cerr
<<
"(SMInterface::initAIterator): ic=NULL"
<<
endl
;
//
else
//
cerr << "(SMInterface::initAIterator): ic=NULL" << endl;
}
// --------------------------------------------------------------------------
void
SMInterface
::
initDIterator
(
IOController
::
DIOStateList
::
iterator
&
it
)
{
if
(
ic
)
it
=
ic
->
dioEnd
();
else
cerr
<<
"(SMInterface::initDIterator): ic=NULL"
<<
endl
;
// else
//
cerr << "(SMInterface::initDIterator): ic=NULL" << endl;
}
// --------------------------------------------------------------------------
bool
SMInterface
::
waitSMready
(
int
ready_timeout
,
int
pmsec
)
...
...
include/modbus/ModbusTCPMaster.h
View file @
a2756ef7
...
...
@@ -24,6 +24,8 @@ class ModbusTCPMaster:
bool
isConnection
();
protected
:
void
reconnect
();
virtual
int
getNextData
(
unsigned
char
*
buf
,
int
len
);
virtual
void
setChannelTimeout
(
int
msec
);
...
...
@@ -35,6 +37,8 @@ class ModbusTCPMaster:
ost
::
TCPStream
*
tcp
;
static
int
nTransaction
;
std
::
queue
<
unsigned
char
>
qrecv
;
PassiveTimer
ptTimeout
;
std
::
string
iaddr
;
};
// -------------------------------------------------------------------------
#endif // ModbusTCPMaster_H_
...
...
src/Communications/Modbus/ModbusTCPMaster.cc
View file @
a2756ef7
...
...
@@ -13,7 +13,8 @@ using namespace ModbusRTU;
using
namespace
UniSetTypes
;
// -------------------------------------------------------------------------
ModbusTCPMaster
::
ModbusTCPMaster
()
:
tcp
(
0
)
tcp
(
0
),
iaddr
(
""
)
{
setCRCNoCheckit
(
true
);
}
...
...
@@ -46,13 +47,16 @@ int ModbusTCPMaster::nTransaction = 0;
mbErrCode
ModbusTCPMaster
::
query
(
ModbusAddr
addr
,
ModbusMessage
&
msg
,
ModbusMessage
&
reply
,
int
timeout
)
{
if
(
!
isConnection
()
)
// if( !isConnection() )
if
(
iaddr
.
empty
()
)
{
dlog
[
Debug
::
WARN
]
<<
"(query): not connection to server..."
<<
endl
;
return
erHardwareError
;
}
PassiveTimer
ptTimeout
;
reconnect
()
;
if
(
timeout
<=
0
||
timeout
==
UniSetTimer
::
WaitUpTime
)
{
...
...
@@ -66,6 +70,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
try
{
if
(
nTransaction
>=
numeric_limits
<
int
>::
max
()
)
nTransaction
=
0
;
ModbusTCP
::
MBAPHeader
mh
;
mh
.
tID
=
++
nTransaction
;
mh
.
pID
=
0
;
...
...
@@ -89,7 +96,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
mbErrCode
res
=
send
(
msg
);
if
(
res
!=
erNoError
)
return
res
;
if
(
!
tcp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
timeout
)
)
return
erTimeOut
;
...
...
@@ -159,6 +166,17 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
return
erHardwareError
;
}
// -------------------------------------------------------------------------
void
ModbusTCPMaster
::
reconnect
()
{
if
(
tcp
)
{
tcp
->
disconnect
();
delete
tcp
;
}
tcp
=
new
ost
::
TCPStream
(
iaddr
.
c_str
());
}
// -------------------------------------------------------------------------
void
ModbusTCPMaster
::
connect
(
ost
::
InetAddress
addr
,
int
port
)
{
if
(
!
tcp
)
...
...
@@ -169,7 +187,8 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
if
(
dlog
.
debugging
(
Debug
::
INFO
)
)
dlog
[
Debug
::
INFO
]
<<
"(ModbusTCPMaster): connect to "
<<
s
.
str
()
<<
endl
;
tcp
=
new
ost
::
TCPStream
(
s
.
str
().
c_str
());
iaddr
=
s
.
str
();
tcp
=
new
ost
::
TCPStream
(
iaddr
.
c_str
());
}
}
// -------------------------------------------------------------------------
...
...
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