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
08cccaf0
Commit
08cccaf0
authored
Oct 16, 2022
by
Pavel Vainerman
Committed by
Pavel Vainerman
Oct 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(modbus): supported "stopbits","charsize" settings
parent
85fb17dc
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
125 additions
and
5 deletions
+125
-5
MBConfig.cc
extensions/ModbusMaster/MBConfig.cc
+13
-0
MBConfig.h
extensions/ModbusMaster/MBConfig.h
+2
-0
RTUExchange.cc
extensions/ModbusMaster/RTUExchange.cc
+27
-0
RTUExchange.h
extensions/ModbusMaster/RTUExchange.h
+2
-0
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+17
-2
tests_with_sm.cc
extensions/ModbusSlave/tests/tests_with_sm.cc
+2
-2
ComPort.h
include/ComPort.h
+6
-0
ModbusRTUMaster.h
include/modbus/ModbusRTUMaster.h
+2
-0
ModbusRTUSlave.h
include/modbus/ModbusRTUSlave.h
+3
-0
ComPort.cc
src/Communications/ComPort.cc
+23
-1
ModbusRTUMaster.cc
src/Communications/Modbus/ModbusRTUMaster.cc
+16
-0
ModbusRTUSlave.cc
src/Communications/Modbus/ModbusRTUSlave.cc
+12
-0
No files found.
extensions/ModbusMaster/MBConfig.cc
View file @
08cccaf0
...
...
@@ -1083,6 +1083,16 @@ namespace uniset
if
(
!
p
.
empty
()
)
d
->
second
->
parity
=
ComPort
::
getParity
(
p
);
auto
cs
=
it
.
getProp
(
"charSize"
);
if
(
!
cs
.
empty
()
)
d
->
second
->
csize
=
ComPort
::
getCharacterSize
(
cs
);
auto
sb
=
it
.
getIntProp
(
"stopBits"
);
if
(
sb
>
0
)
d
->
second
->
stopBits
=
(
ComPort
::
StopBits
)
sb
;
return
true
;
}
// -----------------------------------------------------------------------------
...
...
@@ -1167,6 +1177,9 @@ namespace uniset
<<
" timeout="
<<
resp_Delay
.
getOffDelay
()
<<
" type="
<<
dtype
<<
" ask_every_reg="
<<
ask_every_reg
<<
" stopBits="
<<
stopBits
<<
" charSize="
<<
csize
<<
" parity="
<<
parity
<<
" regs="
<<
regs
<<
")"
<<
endl
;
return
s
.
str
();
...
...
extensions/ModbusMaster/MBConfig.h
View file @
08cccaf0
...
...
@@ -201,6 +201,8 @@ namespace uniset
ComPort
::
Speed
speed
=
{
ComPort
::
ComSpeed38400
};
std
::
shared_ptr
<
RTUStorage
>
rtu188
;
ComPort
::
Parity
parity
=
{
ComPort
::
NoParity
};
ComPort
::
CharacterSize
csize
=
{
ComPort
::
CSize8
};
ComPort
::
StopBits
stopBits
=
{
ComPort
::
OneBit
};
std
::
string
getShortInfo
()
const
;
};
...
...
extensions/ModbusMaster/RTUExchange.cc
View file @
08cccaf0
...
...
@@ -81,6 +81,16 @@ RTUExchange::RTUExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const s
if
(
!
p
.
empty
()
)
parity
=
ComPort
::
getParity
(
p
);
auto
sb
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-stopbits"
,
it
.
getProp
(
"stopBits"
));
if
(
sb
>
0
)
stopBits
=
(
ComPort
::
StopBits
)
sb
;
auto
cs
=
conf
->
getArgParam
(
"--"
+
mbconf
->
prefix
+
"-charsize"
,
it
.
getProp
(
"charSize"
));
if
(
!
cs
.
empty
()
)
csize
=
ComPort
::
getCharacterSize
(
cs
);
mbconf
->
sleepPause_msec
=
conf
->
getArgPInt
(
"--"
+
mbconf
->
prefix
+
"-sleepPause-usec"
,
it
.
getProp
(
"slepePause"
),
100
);
rs_pre_clean
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-pre-clean"
,
it
.
getProp
(
"pre_clean"
));
...
...
@@ -156,6 +166,9 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
mbrtu
->
setSleepPause
(
mbconf
->
sleepPause_msec
);
mbrtu
->
setAfterSendPause
(
mbconf
->
aftersend_pause
);
mbrtu
->
setCharacterSize
(
csize
);
mbrtu
->
setStopBits
(
stopBits
);
mbrtu
->
setParity
(
parity
);
mbinfo
<<
myname
<<
"(init): dev="
<<
devname
<<
" speed="
<<
ComPort
::
getSpeed
(
mbrtu
->
getSpeed
()
)
<<
endl
;
}
...
...
@@ -232,6 +245,8 @@ bool RTUExchange::poll()
bool
allNotRespond
=
true
;
ComPort
::
Speed
s
=
mbrtu
->
getSpeed
();
ComPort
::
Parity
p
=
mbrtu
->
getParity
();
ComPort
::
CharacterSize
cs
=
mbrtu
->
getCharacterSize
();
ComPort
::
StopBits
sb
=
mbrtu
->
getStopBits
();
for
(
auto
it1
:
mbconf
->
devices
)
{
...
...
@@ -252,6 +267,18 @@ bool RTUExchange::poll()
mbrtu
->
setParity
(
p
);
}
if
(
d
->
stopBits
!=
sb
)
{
sb
=
d
->
stopBits
;
mbrtu
->
setStopBits
(
sb
);
}
if
(
d
->
csize
!=
cs
)
{
cs
=
d
->
csize
;
mbrtu
->
setCharacterSize
(
cs
);
}
d
->
prev_numreply
.
store
(
d
->
numreply
);
if
(
d
->
dtype
==
MBConfig
::
dtRTU188
)
...
...
extensions/ModbusMaster/RTUExchange.h
View file @
08cccaf0
...
...
@@ -49,6 +49,8 @@ namespace uniset
std
::
string
devname
;
ComPort
::
Speed
defSpeed
;
ComPort
::
Parity
parity
;
ComPort
::
CharacterSize
csize
;
ComPort
::
StopBits
stopBits
;
bool
use485F
;
bool
transmitCtl
;
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
08cccaf0
...
...
@@ -171,16 +171,27 @@ namespace uniset
speed
=
"38400"
;
string
parity
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-parity"
,
it
.
getProp
(
"parity"
));
int
stopbits
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-stopbits"
,
it
.
getProp
(
"stopBits"
));
bool
use485F
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
bool
transmitCtl
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
string
charsize
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-char-size"
,
it
.
getProp
(
"charSize"
));
auto
rs
=
make_shared
<
ModbusRTUSlaveSlot
>
(
dev
,
use485F
,
transmitCtl
);
rs
->
setSpeed
(
speed
);
if
(
!
parity
.
empty
()
)
rs
->
setParity
(
parity
);
rs
->
setRecvTimeout
(
2000
);
rs
->
setAfterSendPause
(
aftersend_pause
);
rs
->
setReplyTimeout
(
reply_tout
);
if
(
stopbits
>
0
)
rs
->
setStopBits
((
ComPort
::
StopBits
)
stopbits
);
if
(
!
charsize
.
empty
()
)
rs
->
setCharSize
(
ComPort
::
getCharacterSize
(
charsize
));
// rs->setLog(mblog);
mbslot
=
std
::
static_pointer_cast
<
ModbusServerSlot
>
(
rs
);
...
...
@@ -1583,8 +1594,12 @@ namespace uniset
cout
<<
" Настройки протокола RTU: "
<<
endl
;
cout
<<
"--prefix-dev devname - файл устройства"
<<
endl
;
cout
<<
"--prefix-speed - Скорость обмена (9600,19920,38400,57600,115200)."
<<
endl
;
cout
<<
"--prefix-parity - Контроль чётности (odd,even,noparity,space,mark)."
<<
endl
;
cout
<<
"--prefix-parity val - Контроль чётности (odd,even,noparity,space,mark)."
<<
endl
;
cout
<<
"--prefix-charsize val - Битность (cs5, cs6, cs7, cs8). По умолчанию: cs8"
<<
endl
;
cout
<<
"--prefix-stopbits val - Стоп-биты"
<<
endl
;
cout
<<
" 1 - OneBit"
<<
endl
;
cout
<<
" 2 - OneAndHalfBits"
<<
endl
;
cout
<<
" 3 - TwoBits"
<<
endl
;
cout
<<
" Настройки протокола TCP: "
<<
endl
;
cout
<<
"--prefix-inet-addr [xxx.xxx.xxx.xxx | hostname ] - this modbus server address"
<<
endl
;
cout
<<
"--prefix-inet-port num - this modbus server port. Default: 502"
<<
endl
;
...
...
extensions/ModbusSlave/tests/tests_with_sm.cc
View file @
08cccaf0
...
...
@@ -30,8 +30,8 @@ int main(int argc, const char* argv[] )
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
);
// if( returnCode != 0 ) // Indicates a command line error
// return returnCode;
// if( returnCode != 0 ) // Indicates a command line error
// return returnCode;
auto
conf
=
uniset_init
(
argc
,
argv
);
...
...
include/ComPort.h
View file @
08cccaf0
...
...
@@ -100,13 +100,17 @@ namespace uniset
static
Speed
getSpeed
(
const
std
::
string
&
s
);
static
std
::
string
getSpeed
(
Speed
s
);
static
Parity
getParity
(
const
std
::
string
&
s
);
static
CharacterSize
getCharacterSize
(
const
std
::
string
&
s
);
void
setParity
(
Parity
);
void
setParity
(
const
std
::
string
&
s
);
Parity
getParity
();
void
setCharacterSize
(
CharacterSize
);
CharacterSize
getCharacterSize
();
void
setStopBits
(
StopBits
sBit
);
StopBits
getStopBits
();
virtual
void
setTimeout
(
timeout_t
msec
);
timeout_t
getTimeout
()
const
;
...
...
@@ -137,6 +141,8 @@ namespace uniset
Speed
speed
=
ComSpeed38400
;
std
::
string
dev
=
{
""
};
Parity
parity
=
NoParity
;
CharacterSize
charSize
=
CSize8
;
StopBits
stopBits
=
OneBit
;
virtual
unsigned
char
m_receiveByte
(
bool
wait
);
...
...
include/modbus/ModbusRTUMaster.h
View file @
08cccaf0
...
...
@@ -35,7 +35,9 @@ namespace uniset
void
setParity
(
ComPort
::
Parity
parity
);
ComPort
::
Parity
getParity
();
void
setCharacterSize
(
ComPort
::
CharacterSize
csize
);
ComPort
::
CharacterSize
getCharacterSize
();
void
setStopBits
(
ComPort
::
StopBits
sBit
);
ComPort
::
StopBits
getStopBits
();
timeout_t
getTimeout
()
const
;
...
...
include/modbus/ModbusRTUSlave.h
View file @
08cccaf0
...
...
@@ -38,6 +38,9 @@ namespace uniset
void
setParity
(
ComPort
::
Parity
p
);
void
setParity
(
const
std
::
string
&
p
);
void
setStopBits
(
ComPort
::
StopBits
b
);
void
setCharSize
(
ComPort
::
CharacterSize
s
);
virtual
void
cleanupChannel
()
override
{
if
(
port
)
port
->
cleanupChannel
();
...
...
src/Communications/ComPort.cc
View file @
08cccaf0
...
...
@@ -87,7 +87,7 @@ void ComPort::openPort()
options
.
c_cc
[
VMIN
]
=
0
;
options
.
c_cc
[
VTIME
]
=
1
;
options
.
c_cflag
&=
~
CSIZE
;
options
.
c_cflag
|=
CS8
;
options
.
c_cflag
|=
charSize
;
options
.
c_cflag
&=
~
PARENB
;
options
.
c_iflag
&=
~
INPCK
;
options
.
c_cflag
|=
(
CLOCAL
|
CREAD
);
...
...
@@ -128,6 +128,18 @@ void ComPort::setSpeed( Speed s )
tcsetattr
(
fd
,
TCSADRAIN
,
&
options
);
}
// --------------------------------------------------------------------------------
ComPort
::
CharacterSize
ComPort
::
getCharacterSize
(
const
std
::
string
&
s
)
{
if
(
s
==
"cs5"
)
return
CSize5
;
if
(
s
==
"cs6"
)
return
CSize6
;
if
(
s
==
"cs7"
)
return
CSize7
;
return
CSize8
;
}
// --------------------------------------------------------------------------------
ComPort
::
Parity
ComPort
::
getParity
(
const
std
::
string
&
s
)
{
if
(
s
==
"odd"
)
...
...
@@ -223,6 +235,16 @@ void ComPort::setCharacterSize(CharacterSize csize)
tcsetattr
(
fd
,
TCSADRAIN
,
&
options
);
}
// --------------------------------------------------------------------------------
ComPort
::
CharacterSize
ComPort
::
getCharacterSize
()
{
return
charSize
;
}
// --------------------------------------------------------------------------------
ComPort
::
StopBits
ComPort
::
getStopBits
()
{
return
stopBits
;
}
// --------------------------------------------------------------------------------
void
ComPort
::
setStopBits
(
StopBits
sBit
)
{
struct
termios
options
;
...
...
src/Communications/Modbus/ModbusRTUMaster.cc
View file @
08cccaf0
...
...
@@ -131,6 +131,22 @@ namespace uniset
port
->
setCharacterSize
(
csize
);
}
// -------------------------------------------------------------------------
ComPort
::
CharacterSize
ModbusRTUMaster
::
getCharacterSize
()
{
if
(
port
!=
NULL
)
return
port
->
getCharacterSize
();
return
ComPort
::
CSize8
;
}
// -------------------------------------------------------------------------
ComPort
::
StopBits
ModbusRTUMaster
::
getStopBits
()
{
if
(
port
!=
NULL
)
port
->
getStopBits
();
return
ComPort
::
OneBit
;
}
// -------------------------------------------------------------------------
void
ModbusRTUMaster
::
setStopBits
(
ComPort
::
StopBits
sBit
)
{
if
(
port
!=
NULL
)
...
...
src/Communications/Modbus/ModbusRTUSlave.cc
View file @
08cccaf0
...
...
@@ -94,6 +94,18 @@ namespace uniset
return
port
->
getSpeed
();
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setCharSize
(
ComPort
::
CharacterSize
s
)
{
if
(
port
!=
NULL
)
port
->
setCharacterSize
(
s
);
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setStopBits
(
ComPort
::
StopBits
b
)
{
if
(
port
!=
NULL
)
port
->
setStopBits
(
b
);
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setParity
(
ComPort
::
Parity
p
)
{
if
(
port
!=
NULL
)
...
...
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