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
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
94 additions
and
5 deletions
+94
-5
MBConfig.cc
extensions/ModbusMaster/MBConfig.cc
+5
-0
MBConfig.h
extensions/ModbusMaster/MBConfig.h
+1
-0
MBTCPMaster.cc
extensions/ModbusMaster/MBTCPMaster.cc
+0
-0
MBTCPMultiMaster.cc
extensions/ModbusMaster/MBTCPMultiMaster.cc
+0
-0
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
+4
-0
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
...
@@ -1078,6 +1078,11 @@ namespace uniset
}
}
}
}
auto
p
=
it
.
getProp
(
"parity"
);
if
(
!
p
.
empty
()
)
d
->
second
->
parity
=
ComPort
::
getParity
(
p
);
return
true
;
return
true
;
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
...
...
extensions/ModbusMaster/MBConfig.h
View file @
bbcf1069
...
@@ -200,6 +200,7 @@ namespace uniset
...
@@ -200,6 +200,7 @@ namespace uniset
// специфические поля для RS
// специфические поля для RS
ComPort
::
Speed
speed
=
{
ComPort
::
ComSpeed38400
};
ComPort
::
Speed
speed
=
{
ComPort
::
ComSpeed38400
};
std
::
shared_ptr
<
RTUStorage
>
rtu188
;
std
::
shared_ptr
<
RTUStorage
>
rtu188
;
ComPort
::
Parity
parity
=
{
ComPort
::
NoParity
};
std
::
string
getShortInfo
()
const
;
std
::
string
getShortInfo
()
const
;
};
};
...
...
extensions/ModbusMaster/MBTCPMaster.cc
View file @
bbcf1069
extensions/ModbusMaster/MBTCPMultiMaster.cc
View file @
bbcf1069
extensions/ModbusMaster/RTUExchange.cc
View file @
bbcf1069
...
@@ -76,6 +76,10 @@ RTUExchange::RTUExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const s
...
@@ -76,6 +76,10 @@ RTUExchange::RTUExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const s
use485F
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
use485F
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
transmitCtl
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
transmitCtl
=
conf
->
getArgInt
(
"--"
+
mbconf
->
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
defSpeed
=
ComPort
::
getSpeed
(
speed
);
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
);
mbconf
->
sleepPause_msec
=
conf
->
getArgPInt
(
"--"
+
mbconf
->
prefix
+
"-sleepPause-usec"
,
it
.
getProp
(
"slepePause"
),
100
);
...
@@ -227,6 +231,7 @@ bool RTUExchange::poll()
...
@@ -227,6 +231,7 @@ bool RTUExchange::poll()
ncycle
++
;
ncycle
++
;
bool
allNotRespond
=
true
;
bool
allNotRespond
=
true
;
ComPort
::
Speed
s
=
mbrtu
->
getSpeed
();
ComPort
::
Speed
s
=
mbrtu
->
getSpeed
();
ComPort
::
Parity
p
=
mbrtu
->
getParity
();
for
(
auto
it1
:
mbconf
->
devices
)
for
(
auto
it1
:
mbconf
->
devices
)
{
{
...
@@ -241,6 +246,12 @@ bool RTUExchange::poll()
...
@@ -241,6 +246,12 @@ bool RTUExchange::poll()
mbrtu
->
setSpeed
(
d
->
speed
);
mbrtu
->
setSpeed
(
d
->
speed
);
}
}
if
(
d
->
parity
!=
p
)
{
p
=
d
->
parity
;
mbrtu
->
setParity
(
p
);
}
d
->
prev_numreply
.
store
(
d
->
numreply
);
d
->
prev_numreply
.
store
(
d
->
numreply
);
if
(
d
->
dtype
==
MBConfig
::
dtRTU188
)
if
(
d
->
dtype
==
MBConfig
::
dtRTU188
)
...
...
extensions/ModbusMaster/RTUExchange.h
View file @
bbcf1069
...
@@ -48,6 +48,7 @@ namespace uniset
...
@@ -48,6 +48,7 @@ namespace uniset
std
::
mutex
mbMutex
;
std
::
mutex
mbMutex
;
std
::
string
devname
;
std
::
string
devname
;
ComPort
::
Speed
defSpeed
;
ComPort
::
Speed
defSpeed
;
ComPort
::
Parity
parity
;
bool
use485F
;
bool
use485F
;
bool
transmitCtl
;
bool
transmitCtl
;
...
...
extensions/ModbusMaster/tests/run_test_mbtcpmaster.cc
View file @
bbcf1069
...
@@ -34,8 +34,8 @@ int main( int argc, const char* argv[] )
...
@@ -34,8 +34,8 @@ int main( int argc, const char* argv[] )
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
);
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
);
// if( returnCode != 0 ) // Indicates a command line error
// if( returnCode != 0 ) // Indicates a command line error
// return returnCode;
// return returnCode;
auto
conf
=
uniset_init
(
argc
,
argv
);
auto
conf
=
uniset_init
(
argc
,
argv
);
dlog
()
->
logFile
(
"./smtest.log"
);
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[] )
...
@@ -32,8 +32,8 @@ int main(int argc, const char* argv[] )
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
);
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
);
// if( returnCode != 0 ) // Indicates a command line error
// if( returnCode != 0 ) // Indicates a command line error
// return returnCode;
// return returnCode;
auto
conf
=
uniset_init
(
argc
,
argv
);
auto
conf
=
uniset_init
(
argc
,
argv
);
dlog
()
->
logFile
(
"./smtest.log"
);
dlog
()
->
logFile
(
"./smtest.log"
);
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
bbcf1069
...
@@ -170,11 +170,14 @@ namespace uniset
...
@@ -170,11 +170,14 @@ namespace uniset
if
(
speed
.
empty
()
)
if
(
speed
.
empty
()
)
speed
=
"38400"
;
speed
=
"38400"
;
string
parity
=
conf
->
getArgParam
(
"--"
+
prefix
+
"-parity"
,
it
.
getProp
(
"parity"
));
bool
use485F
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
bool
use485F
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-use485F"
,
it
.
getProp
(
"use485F"
));
bool
transmitCtl
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
bool
transmitCtl
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-transmit-ctl"
,
it
.
getProp
(
"transmitCtl"
));
auto
rs
=
make_shared
<
ModbusRTUSlaveSlot
>
(
dev
,
use485F
,
transmitCtl
);
auto
rs
=
make_shared
<
ModbusRTUSlaveSlot
>
(
dev
,
use485F
,
transmitCtl
);
rs
->
setSpeed
(
speed
);
rs
->
setSpeed
(
speed
);
if
(
!
parity
.
empty
()
)
rs
->
setParity
(
parity
);
rs
->
setRecvTimeout
(
2000
);
rs
->
setRecvTimeout
(
2000
);
rs
->
setAfterSendPause
(
aftersend_pause
);
rs
->
setAfterSendPause
(
aftersend_pause
);
rs
->
setReplyTimeout
(
reply_tout
);
rs
->
setReplyTimeout
(
reply_tout
);
...
@@ -1580,6 +1583,7 @@ namespace uniset
...
@@ -1580,6 +1583,7 @@ namespace uniset
cout
<<
" Настройки протокола RTU: "
<<
endl
;
cout
<<
" Настройки протокола RTU: "
<<
endl
;
cout
<<
"--prefix-dev devname - файл устройства"
<<
endl
;
cout
<<
"--prefix-dev devname - файл устройства"
<<
endl
;
cout
<<
"--prefix-speed - Скорость обмена (9600,19920,38400,57600,115200)."
<<
endl
;
cout
<<
"--prefix-speed - Скорость обмена (9600,19920,38400,57600,115200)."
<<
endl
;
cout
<<
"--prefix-parity - Контроль чётности (odd,even,noparity,space,mark)."
<<
endl
;
cout
<<
" Настройки протокола TCP: "
<<
endl
;
cout
<<
" Настройки протокола TCP: "
<<
endl
;
cout
<<
"--prefix-inet-addr [xxx.xxx.xxx.xxx | hostname ] - this modbus server address"
<<
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
...
@@ -99,8 +99,12 @@ namespace uniset
static
Speed
getSpeed
(
const
std
::
string
&
s
);
static
Speed
getSpeed
(
const
std
::
string
&
s
);
static
std
::
string
getSpeed
(
Speed
s
);
static
std
::
string
getSpeed
(
Speed
s
);
static
Parity
getParity
(
const
std
::
string
&
s
);
void
setParity
(
Parity
);
void
setParity
(
Parity
);
void
setParity
(
const
std
::
string
&
s
);
Parity
getParity
();
void
setCharacterSize
(
CharacterSize
);
void
setCharacterSize
(
CharacterSize
);
void
setStopBits
(
StopBits
sBit
);
void
setStopBits
(
StopBits
sBit
);
...
@@ -132,6 +136,7 @@ namespace uniset
...
@@ -132,6 +136,7 @@ namespace uniset
bool
waiting
=
{
false
};
bool
waiting
=
{
false
};
Speed
speed
=
ComSpeed38400
;
Speed
speed
=
ComSpeed38400
;
std
::
string
dev
=
{
""
};
std
::
string
dev
=
{
""
};
Parity
parity
=
NoParity
;
virtual
unsigned
char
m_receiveByte
(
bool
wait
);
virtual
unsigned
char
m_receiveByte
(
bool
wait
);
...
...
include/modbus/ModbusRTUMaster.h
View file @
bbcf1069
...
@@ -33,6 +33,7 @@ namespace uniset
...
@@ -33,6 +33,7 @@ namespace uniset
ComPort
::
Speed
getSpeed
();
ComPort
::
Speed
getSpeed
();
void
setParity
(
ComPort
::
Parity
parity
);
void
setParity
(
ComPort
::
Parity
parity
);
ComPort
::
Parity
getParity
();
void
setCharacterSize
(
ComPort
::
CharacterSize
csize
);
void
setCharacterSize
(
ComPort
::
CharacterSize
csize
);
void
setStopBits
(
ComPort
::
StopBits
sBit
);
void
setStopBits
(
ComPort
::
StopBits
sBit
);
...
...
include/modbus/ModbusRTUSlave.h
View file @
bbcf1069
...
@@ -35,6 +35,9 @@ namespace uniset
...
@@ -35,6 +35,9 @@ namespace uniset
void
setSpeed
(
const
std
::
string
&
s
);
void
setSpeed
(
const
std
::
string
&
s
);
ComPort
::
Speed
getSpeed
();
ComPort
::
Speed
getSpeed
();
void
setParity
(
ComPort
::
Parity
p
);
void
setParity
(
const
std
::
string
&
p
);
virtual
void
cleanupChannel
()
override
virtual
void
cleanupChannel
()
override
{
{
if
(
port
)
port
->
cleanupChannel
();
if
(
port
)
port
->
cleanupChannel
();
...
...
src/Communications/ComPort.cc
View file @
bbcf1069
...
@@ -128,6 +128,41 @@ void ComPort::setSpeed( Speed s )
...
@@ -128,6 +128,41 @@ void ComPort::setSpeed( Speed s )
tcsetattr
(
fd
,
TCSADRAIN
,
&
options
);
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
)
void
ComPort
::
setParity
(
Parity
parity
)
{
{
struct
termios
options
;
struct
termios
options
;
...
@@ -137,28 +172,33 @@ void ComPort::setParity(Parity parity)
...
@@ -137,28 +172,33 @@ void ComPort::setParity(Parity parity)
switch
(
parity
)
switch
(
parity
)
{
{
case
Odd
:
case
Odd
:
parity
=
Odd
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
|=
PARODD
;
options
.
c_cflag
|=
PARODD
;
break
;
break
;
case
Even
:
case
Even
:
parity
=
Even
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
&=
~
CMSPAR
;
options
.
c_cflag
&=
~
PARODD
;
options
.
c_cflag
&=
~
PARODD
;
break
;
break
;
case
NoParity
:
case
NoParity
:
parity
=
NoParity
;
options
.
c_cflag
&=
~
PARENB
;
options
.
c_cflag
&=
~
PARENB
;
break
;
break
;
case
Space
:
case
Space
:
parity
=
Space
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
|=
PARODD
;
options
.
c_cflag
|=
PARODD
;
break
;
break
;
case
Mark
:
case
Mark
:
parity
=
Mark
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
PARENB
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
|=
CMSPAR
;
options
.
c_cflag
&=
~
PARODD
;
options
.
c_cflag
&=
~
PARODD
;
...
...
src/Communications/Modbus/ModbusRTUMaster.cc
View file @
bbcf1069
...
@@ -111,6 +111,14 @@ namespace uniset
...
@@ -111,6 +111,14 @@ namespace uniset
return
port
->
getSpeed
();
return
port
->
getSpeed
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ComPort
::
Parity
ModbusRTUMaster
::
getParity
()
{
if
(
port
!=
NULL
)
port
->
getParity
();
return
ComPort
::
NoParity
;
}
// -------------------------------------------------------------------------
void
ModbusRTUMaster
::
setParity
(
ComPort
::
Parity
parity
)
void
ModbusRTUMaster
::
setParity
(
ComPort
::
Parity
parity
)
{
{
if
(
port
!=
NULL
)
if
(
port
!=
NULL
)
...
...
src/Communications/Modbus/ModbusRTUSlave.cc
View file @
bbcf1069
...
@@ -94,7 +94,17 @@ namespace uniset
...
@@ -94,7 +94,17 @@ namespace uniset
return
port
->
getSpeed
();
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
)
void
ModbusRTUSlave
::
setSpeed
(
ComPort
::
Speed
s
)
{
{
if
(
port
!=
NULL
)
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