Modbus Plugin
Purpose
Purpose of this plugin is to read from Modbus Servers.
Usage
You run a log
to send data to the cloud, or a discover
to only display information. There must be a config file when running log
or a discover
. The config file defines which variables need to be collected, what names they appear on the the Ardexa cloud, units and scaling, what table(s) they variables will be sent to, and the source name(s). Example config file as follows. Always verify data accuracy by running a discover
first, before committing the plugin to collect data. Also note carefully: The configuration file specifies the use of the mbpoll
command. However, this new version of Modbus Ardexa is based on the Rust language and does not use mbpoll
. It remains for compatability purposes.
Notes:
_cmd
is the commands to run. Onlymodpoll
or thembpoll
github command OR theModbus Ruby CLI
(see the readme file) to read and write to modbus registers.mbpoll
is preferred. The registers being collected MUST MATCH the registers listed in the configuration items. If not, you will have empty fields when running adiscover
. If the registers in_cmd
commands overlap, then there could be unexpected errors. Make sure each output of the_cmd
commands do not overlap. The phrase--translate
can be included in a modbus command. It MUST appear in lower case and at the end of the command. If used, it will scale (by adding), all the register values. It will hence have the effect of translating them to another set of registers, so as they do not "collide" with the registers from another command. Also note carefully: The configuration file specifies the use of thembpoll
command. However, this new version of Modbus Ardexa is based on the Rust language and does not usembpoll
. It remains for compatability purposes.Scale
will only be used fordecimal
andinteger
types. An error will be reported if you try and divide an integer, or multiply by anything other than a whole number. The scale can also be a value such as0.75-9
, where the-9
is a BIAS value (addition or subtraction). In which case it will FIRST subtract the 9, THEN multiply by 0.75. If using a bias value, then it can ONLY be used with adecimal
type.RO/RW/INV
. This column will only do the following task": If an entry starts with>
, it will invalidate ALL entries in a configuration file, if the absolute value (+ or -) for this entry is greater than the specified amount. For example; if theRO/RW/INV
column entry is>10000
, then a value of 12,000 will ensure ALL readings in the configuration file are invalidated. Use this item with caution. Also, it will ONLY work ondec
values. This invalidation feature is intended for those machines that have poor quality control, and sometimes transmit wildly wrong values.In
Num of Regs
; Sometimes you may need to read 2 consecutive registers, to form a floating point (32 bit) number, rather than a single register (16 bit). Rarely, we may want to read a number of (perhaps) non-consecutive registers to form a string. Usually, it is best for thembpoll
ormodpoll
to handle this translation. Note that if you use a number value of2e
, it will reverse the endianess, fordec
andint
values.In
Lookup Table
; Sometimes you want to convert an INT to a keyword, through a lookup table. Or you may want to get a register bit and convert it to a keyword.Allowable
Type
are as follows:
dec
... Converts the modbus register to a decimal. Can be scaled (including division).swap16
... Swaps the modbus register's endianness and converts it to a decimal. Can be scaled (including division).udec
... This will convert the register to unsigned first, then convert the modbus register to a decimal. Can be scaled (including division). Only works on 16 bit registers.int
... Converts the modbus register to an integer. Can only be scaled upwards (not divided). So ascale
value that is not a whole number will be rejected. See also the explanation forscale
above, since it can include a bias and scale factor.bit
... Used with a lookup table (in theLookup Table
column) to define a bit being turned or off. See example contents of file below. Bits start at "1" (not "0"), and are defined in theLookup Table
column.bitb
... If a bit in the modbus register is turned on/off, it will reflect a boolean ("True"/"False") output.bitb_int
... If a bit in the modbus register is turned on/off, it will reflect a boolean ("1"/"0") output.str
... Treated as an ASCII character. If it can't be converted, it will output an empty fieldstr_rep
... Same asstr
, but it will clear\0
values in the resultant string.bool
... Modbus register is converted to an INT. This value is then check as follows: Anything other than0
will output aTrue
. Else, output will beFalse
.int_bool
... Modbus register is converted to an INT. This value is then check as follows: Anything other than0
will output a1
. Else, output will be0
.bin
... Converts the modbus register to an integer, then to a binary reprentation.int8
... Mask out the first 8 bits of an Modbus integer, then use a lookup filehi8
... Mask out the first (low) 8 bits of an Modbus integerlo8
... Mask out the last (high) 8 bits of an Modbus integersum
... This is to sum the values of specific registers. In this case theRegister
field MUST be set to0
and the registers to sum is a list in Summation Registers separated by spaces onlyafter
... This is the same assum
, but each register is added AFTER the scale and bias line. You MUST have theregister
set to0
This means 2 things: a. The register to be added must exist as a separate line, and b. Theafter
line must appear AFTER ALL the registers to be added.cond_bit
... This type will use the CONTENTS of the register listed in theSum/Conditional Registers
and whether the bit detailed in theRegister
andConditional Bit
column are 1 to then display the result of the lookup table. See the entry below on how this feature works.mask
... Mask out the Modbus integer based on the bits listed in the last 2 entries (bits 2 to 4 in the example - Bits start at "1" (not "0")) And use the resultant integer to lookup up and keywordlog_scale
... This will log scale the register, based on the contents of another register. In the example above, the final result will be:result = scale * (contents_of_register(365) * 10 ** (contents_of_register(569)-3)))
reg_scale
... This will scale the register, based on the contents of another register. In the example above, the final result will be:result = scale * (contents_of_register(365) * contents_of_register(569))
depend
... This will read the contents of the Lookup Table, the "depend register" (2456/7/8/9
in the above example). If the depend number, which is the next column in the config file, exceeds the value of the contents of the "depend register", then the particular line will be ignored. Otherwise it will collect the data and treat it as a DECIMAL value.master
... This will read the contents of the Lookup Table, the "master register" (110
in the above example). If the master register content is 1, it will collect the data and treat it as a DECIMAL value. If it is 0, then the particular line will be ignored. note. When doing a discovery using a MASTER/SLAVE type, it will show BOTH TYPES, but only one will be populated.slave
... This will read the contents of the Lookup Table, the "master register" (111
in the above example). If the master register content is 0, it will collect the data and treat it as a DECIMAL value. If it is 1, then the particular line will be ignored. note. When doing a discovery using a MASTER/SLAVE type, it will show BOTH TYPES, but only one will be populated.ge_fix
... This is used to convert a modbus integer to a signed integer using the "Signed Magnitude Method" discussed in: https://www.geeksforgeeks.org/representation-of-negative-binary-numbers/ The conversion will be handled during the early parts of processing, and then the value will be converted to DECIMAL
There are up to 11 columns. Only the first 8 (up to and including the
RO/RW
column) are required.A lookup file must be defined for the type
bit
andcond_bit
Encapsulation of RTU over TCP
Arguments
Arguments are as follows:
discover
orlog
. This is the action as to whether discover data or log the data (send it to the cloud)config_path
. This is the path to the configuration fileendpoint
. This is either a serial device like/dev/ttyS0
or an IP or DNS like192.168.1.15
--bus_addresses
. A Modbus address in the range 2-255. This can be a hyphenated list like3-10
or a list like2,5,7,9
. The default is1
--port
. This is an optional parameter used in an Ethernet gateway, and is the TCP port used for the gateway. Default is502
--attempts
. This is an optional parameter, and determines how many times to times to attempt to read an inverter value. Default is3
--delay
. This is the delay in seconds between modbus commands (if there are more than 1) AND ONLY if the first attempts fails. Fractions like0.3
can be used. Default is0.1
(seconds)--timeout
. This is the modbus command timeout in milliseconds. Default is1000
. This is only the timeout value in event of the modbus server not responding. If a modbus server responds sooner, then this value is ignored.--serial_lock
. This argument is included for compatability with older versions, but it is not used.--socket_delay
. Some Huawei equipment needs a delay between establishing a TCP socket and getting data. This feature allows this delay. It is defined in milliseconds.
Example of "bit" lookup
File would be something like:
/home/ardexa/ess_modbus/dict/container_alarm0.dict
Bit starts at
1
. Include a0
value to display something (or blank) if no bits are turned on
Example of "str" lookup file
File would be something like:
/home/ardexa/dict/mode.dict
Numbers can be anything, since they are read from a single modbus (16 bit) register
Example of a "conditional lookup" file
This is a lookup file used by the
cond_bit
type. It operates by using the CONTENTS of the register listed in theSum/Conditional Registers
, and whether the bit detailed in theRegister
andConditional Bit
column are 1/true, to then display the result of the lookup table. The file contents example is as below. There are 2 keys separated by a colon ":". The first item is the contents of theSum/Conditional Registers
, and the second key is the bit detailed in theRegister
andConditional Bit
column. If this bit is true, then the third item is displayed.