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
bbcf1069
Commit
bbcf1069
authored
Oct 09, 2022
by
Pavel Vainerman
Committed by
Pavel Vainerman
Oct 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(modbus): supported parity
parent
384da8d8
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
99 additions
and
10 deletions
+99
-10
MBConfig.cc
extensions/ModbusMaster/MBConfig.cc
+5
-0
MBConfig.h
extensions/ModbusMaster/MBConfig.h
+1
-0
MBTCPMaster.cc
extensions/ModbusMaster/MBTCPMaster.cc
+2
-2
MBTCPMultiMaster.cc
extensions/ModbusMaster/MBTCPMultiMaster.cc
+2
-2
RTUExchange.cc
extensions/ModbusMaster/RTUExchange.cc
+11
-0
RTUExchange.h
extensions/ModbusMaster/RTUExchange.h
+1
-0
run_test_mbtcpmaster.cc
extensions/ModbusMaster/tests/run_test_mbtcpmaster.cc
+2
-2
run_test_mbtcpmultimaster.cc
extensions/ModbusMaster/tests/run_test_mbtcpmultimaster.cc
+2
-2
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+5
-1
ComPort.h
include/ComPort.h
+5
-0
ModbusRTUMaster.h
include/modbus/ModbusRTUMaster.h
+1
-0
ModbusRTUSlave.h
include/modbus/ModbusRTUSlave.h
+3
-0
ComPort.cc
src/Communications/ComPort.cc
+40
-0
ModbusRTUMaster.cc
src/Communications/Modbus/ModbusRTUMaster.cc
+8
-0
ModbusRTUSlave.cc
src/Communications/Modbus/ModbusRTUSlave.cc
+11
-1
No files found.
extensions/ModbusMaster/MBConfig.cc
View file @
bbcf1069
...
...
@@ -1078,6 +1078,11 @@ namespace uniset
}
}
auto
p
=
it
.
getProp
(
"parity"
);
if
(
!
p
.
empty
()
)
d
->
second
->
parity
=
ComPort
::
getParity
(
p
);
return
true
;
}
// -----------------------------------------------------------------------------
...
...
extensions/ModbusMaster/MBConfig.h
View file @
bbcf1069
...
...
@@ -200,6 +200,7 @@ namespace uniset
// специфические поля для RS
ComPort
::
Speed
speed
=
{
ComPort
::
ComSpeed38400
};
std
::
shared_ptr
<
RTUStorage
>
rtu188
;
ComPort
::
Parity
parity
=
{
ComPort
::
NoParity
};
std
::
string
getShortInfo
()
const
;
};
...
...
extensions/ModbusMaster/MBTCPMaster.cc
View file @
bbcf1069
...
...
@@ -225,8 +225,8 @@ std::shared_ptr<MBTCPMaster> MBTCPMaster::init_mbmaster(int argc, const char* co
if
(
ID
==
uniset
::
DefaultObjectId
)
{
cerr
<<
"(MBTCPMaster): идентификатор '"
<<
name
<<
"' не найден в конф. файле!"
<<
" в секции "
<<
conf
->
getObjectsSection
()
<<
endl
;
<<
"' не найден в конф. файле!"
<<
" в секции "
<<
conf
->
getObjectsSection
()
<<
endl
;
return
0
;
}
...
...
extensions/ModbusMaster/MBTCPMultiMaster.cc
View file @
bbcf1069
...
...
@@ -714,8 +714,8 @@ std::shared_ptr<MBTCPMultiMaster> MBTCPMultiMaster::init_mbmaster( int argc, con
if
(
ID
==
uniset
::
DefaultObjectId
)
{
cerr
<<
"(MBTCPMultiMaster): идентификатор '"
<<
name
<<
"' не найден в конф. файле!"
<<
" в секции "
<<
conf
->
getObjectsSection
()
<<
endl
;
<<
"' не найден в конф. файле!"
<<
" в секции "
<<
conf
->
getObjectsSection
()
<<
endl
;
return
0
;
}
...
...
extensions/ModbusMaster/RTUExchange.cc
View file @
bbcf1069
...
...
@@ -76,6 +76,10 @@ RTUExchange::RTUExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const s
use485F
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
transmitCtl
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
defSpeed
=
ComPort
::
getSpeed
(
speed
);
auto
p
=
conf
->
getArgParam
(
"--"
+
mbconf
->
prefix
+
"-parity"
,
it
.
getProp
(
"parity"
));
if
(
!
p
.
empty
()
)
parity
=
ComPort
::
getParity
(
p
);
mbconf
->
sleepPause_msec
=
conf
->
getArgPInt
(
"--"
+
mbconf
->
prefix
+
"-sleepPause-usec"
,
it
.
getProp
(
"slepePause"
),
100
);
...
...
@@ -227,6 +231,7 @@ bool RTUExchange::poll()
ncycle
++
;
bool
allNotRespond
=
true
;
ComPort
::
Speed
s
=
mbrtu
->
getSpeed
();
ComPort
::
Parity
p
=
mbrtu
->
getParity
();
for
(
auto
it1
:
mbconf
->
devices
)
{
...
...
@@ -241,6 +246,12 @@ bool RTUExchange::poll()
mbrtu
->
setSpeed
(
d
->
speed
);
}
if
(
d
->
parity
!=
p
)
{
p
=
d
->
parity
;
mbrtu
->
setParity
(
p
);
}
d
->
prev_numreply
.
store
(
d
->
numreply
);
if
(
d
->
dtype
==
MBConfig
::
dtRTU188
)
...
...
extensions/ModbusMaster/RTUExchange.h
View file @
bbcf1069
...
...
@@ -48,6 +48,7 @@ namespace uniset
std
::
mutex
mbMutex
;
std
::
string
devname
;
ComPort
::
Speed
defSpeed
;
ComPort
::
Parity
parity
;
bool
use485F
;
bool
transmitCtl
;
...
...
extensions/ModbusMaster/tests/run_test_mbtcpmaster.cc
View file @
bbcf1069
...
...
@@ -34,8 +34,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
);
dlog
()
->
logFile
(
"./smtest.log"
);
...
...
extensions/ModbusMaster/tests/run_test_mbtcpmultimaster.cc
View file @
bbcf1069
...
...
@@ -32,8 +32,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
);
dlog
()
->
logFile
(
"./smtest.log"
);
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
bbcf1069
...
...
@@ -165,16 +165,19 @@ namespace uniset
if
(
dev
.
empty
()
)
throw
uniset
::
SystemError
(
myname
+
"(MBSlave): Unknown device..."
);
string
speed
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-speed"
,
it
.
getProp
(
"speed"
));
string
speed
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-speed"
,
it
.
getProp
(
"speed"
));
if
(
speed
.
empty
()
)
speed
=
"38400"
;
string
parity
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-parity"
,
it
.
getProp
(
"parity"
));
bool
use485F
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
bool
transmitCtl
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
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
);
...
...
@@ -1580,6 +1583,7 @@ 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
<<
" Настройки протокола TCP: "
<<
endl
;
cout
<<
"--prefix-inet-addr [xxx.xxx.xxx.xxx | hostname ] - this modbus server address"
<<
endl
;
...
...
include/ComPort.h
View file @
bbcf1069
...
...
@@ -99,8 +99,12 @@ namespace uniset
static
Speed
getSpeed
(
const
std
::
string
&
s
);
static
std
::
string
getSpeed
(
Speed
s
);
static
Parity
getParity
(
const
std
::
string
&
s
);
void
setParity
(
Parity
);
void
setParity
(
const
std
::
string
&
s
);
Parity
getParity
();
void
setCharacterSize
(
CharacterSize
);
void
setStopBits
(
StopBits
sBit
);
...
...
@@ -132,6 +136,7 @@ namespace uniset
bool
waiting
=
{
false
};
Speed
speed
=
ComSpeed38400
;
std
::
string
dev
=
{
""
};
Parity
parity
=
NoParity
;
virtual
unsigned
char
m_receiveByte
(
bool
wait
);
...
...
include/modbus/ModbusRTUMaster.h
View file @
bbcf1069
...
...
@@ -33,6 +33,7 @@ namespace uniset
ComPort
::
Speed
getSpeed
();
void
setParity
(
ComPort
::
Parity
parity
);
ComPort
::
Parity
getParity
();
void
setCharacterSize
(
ComPort
::
CharacterSize
csize
);
void
setStopBits
(
ComPort
::
StopBits
sBit
);
...
...
include/modbus/ModbusRTUSlave.h
View file @
bbcf1069
...
...
@@ -35,6 +35,9 @@ namespace uniset
void
setSpeed
(
const
std
::
string
&
s
);
ComPort
::
Speed
getSpeed
();
void
setParity
(
ComPort
::
Parity
p
);
void
setParity
(
const
std
::
string
&
p
);
virtual
void
cleanupChannel
()
override
{
if
(
port
)
port
->
cleanupChannel
();
...
...
src/Communications/ComPort.cc
View file @
bbcf1069
...
...
@@ -128,6 +128,41 @@ void ComPort::setSpeed( Speed s )
tcsetattr
(
fd
,
TCSADRAIN
,
&
options
);
}
// --------------------------------------------------------------------------------
ComPort
::
Parity
ComPort
::
getParity
(
const
std
::
string
&
s
)
{
if
(
s
==
"odd"
)
return
Odd
;
if
(
s
==
"even"
)
return
Even
;
if
(
s
==
"noparity"
)
return
NoParity
;
if
(
s
==
"space"
)
return
Space
;
if
(
s
==
"mark"
)
return
Mark
;
return
NoParity
;
}
// --------------------------------------------------------------------------------
ComPort
::
Parity
ComPort
::
getParity
()
{
return
parity
;
}
// --------------------------------------------------------------------------------
void
ComPort
::
setParity
(
const
std
::
string
&
s
)
{
if
(
s
==
"odd"
)
setParity
(
Odd
);
else
if
(
s
==
"even"
)
setParity
(
Even
);
else
if
(
s
==
"noparity"
)
setParity
(
NoParity
);
else
if
(
s
==
"space"
)
setParity
(
Space
);
else
if
(
s
==
"mark"
)
setParity
(
Mark
);
}
// --------------------------------------------------------------------------------
void
ComPort
::
setParity
(
Parity
parity
)
{
struct
termios
options
;
...
...
@@ -137,28 +172,33 @@ void ComPort::setParity(Parity parity)
switch
(
parity
)
{
case
Odd
:
parity
=
Odd
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
|=
PARODD
;
break
;
case
Even
:
parity
=
Even
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
&=
~
PARODD
;
break
;
case
NoParity
:
parity
=
NoParity
;
options
.
c_cflag
&=
~
PARENB
;
break
;
case
Space
:
parity
=
Space
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
|=
PARODD
;
break
;
case
Mark
:
parity
=
Mark
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
&=
~
PARODD
;
...
...
src/Communications/Modbus/ModbusRTUMaster.cc
View file @
bbcf1069
...
...
@@ -111,6 +111,14 @@ namespace uniset
return
port
->
getSpeed
();
}
// -------------------------------------------------------------------------
ComPort
::
Parity
ModbusRTUMaster
::
getParity
()
{
if
(
port
!=
NULL
)
port
->
getParity
();
return
ComPort
::
NoParity
;
}
// -------------------------------------------------------------------------
void
ModbusRTUMaster
::
setParity
(
ComPort
::
Parity
parity
)
{
if
(
port
!=
NULL
)
...
...
src/Communications/Modbus/ModbusRTUSlave.cc
View file @
bbcf1069
...
...
@@ -94,7 +94,17 @@ namespace uniset
return
port
->
getSpeed
();
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setParity
(
ComPort
::
Parity
p
)
{
if
(
port
!=
NULL
)
port
->
setParity
(
p
);
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setParity
(
const
std
::
string
&
p
)
{
setParity
(
ComPort
::
getParity
(
p
));
}
// -------------------------------------------------------------------------
void
ModbusRTUSlave
::
setSpeed
(
ComPort
::
Speed
s
)
{
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