Siemens S7 PLC Plugin
Purpose
This is a plugin to read data from a Siemens S7 PLC.
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.
NOTES:
Anything that starts with
#
is a comment line, and will be ignoredThe
Memory Area
is sometimes referred to as the "block". Valid values can be things likeOB
,DB
,SDB
,FC
,SFC
,FB
,SFB
. However, they can also be customised implementations.In
Block Number
, this is an integer value, usually in the range [0...127]. Check with the PLC project manager.Memory Address
MUST be formatted as follows:Boolean values: eg;
MX13.1
. The valueM
is ignored, but theX
denotes a bit wise mapping.13
is the memory location, and.1
is bit 1.Integer values: eg;
MW2
. The valueM
is ignored, but theW
denotes a WORD (2 byte) entry, orb
denotes a byte.2
is the memory location, in this case.Real (decimal) values: eg;
freal334
. The valuefreal
is used to denote a real (4 bytes value).334
is the memory location, in this case.DWORD: The use of
dd
(where the second letter is ad
indicates a double word. In these cases, the result may be interpreted as a floating point number or an integer. - To interpret the result as a floating point number, use the--use_float_dword
argument discussed below. Otherwise the result will be treated as an integer.
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.Invalidate
. This column will only do the following task": If an entry starts with>
, it will invalidate ALL entries in a configuration file, if the value for this entry is greater than the specified amount. For example; if theInvalidate
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
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, or the string length. See examples below.Allowable
Type
column values are as follows:dec
... Converts the S7 location to a decimal. Can be scaled (including division).int
... Converts the S7 location 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.bool
... S7 location is converted to an INT. This value is then check as follows: Anything other than0
will output aTrue
. Else, output will beFalse
.int_bool
... S7 location 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 S7 location to an integer, then to a binary representation.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 S7 location is turned on/off, it will reflect a boolean ("True"/"False") output.bitb_int
... If a bit in the S7 location 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.str_raw
... Treated as raw characters without ANY conversion. Note the INTEGER in the example above specifies the LENGTH of the string to the PLC
Arguments
ip_address
This is the IP Address of the S7 PLC. Make sure that Port 102 is open.config_path
. This is the config file location--attempts
Is the number of attempts to make to get data from the PLC. The default=2--rack
and--slot
values are both integers. They default torack=0
andslot=1
. The Rack (0..7) and Slot (1..31) can be found in the hardware configuration of the project. There is however some special cases for which those values are fixed or can work with a defaults, as shown:
--use_float_dword
Use this flag to treat a DWORD as a floating point number. Otherwise it will be treated as an integer.
Write Arguments
This plugin can be used to write to an S7 PLC. Only a single value can be written at any one time. A log record is written anytime a memory location is written. This log record is written to the S7_write
table, and is available in SEARCHES on the Ardexa front end. The command is s7_ardexa set_command {arguments}
. The arguments for the write capability include, in order:
The
IP address
if the IP Address of the S7 PLCThe
area
(eg;DB
)The
block
(eg;99
)The
memory address
(eg;MW916
)The
--rack
and--slot
values are both optional integers. See the aboveRead Arguments
For example: s7_ardexa set_command 192.168.1.2 db 2 MW876 1193
Example of "bit" lookup
Bit starts at 1
. Include a 0
value to display something (or blank) if no bits are turned on
Example of "str" lookup file
Numbers can be anything, since they are read from a single modbus (16 bit) register
Last updated