modbus_slave
Purpose:
-
Create a modbus slave which can then interact with a modbus server and can store data directly from CyFlex variables from the modbus protocol registers.
Enter:
-
modbus_slave <priority> <specification_filename> &
Where:
-
priority
Specify the real-time task priority.
specification_filename
Specify the modbus slave specification filename.
Example:
-
modbus_slave 17 /specs/modbus_slave.spec &
Sample spec file:
@REG_NAME
modbus_slave
# serail port:baud,bits,stobits,parity,
$Device
#/dev/ttyS0:9600,8,1,0
#127.0.0.1:502
143.222.168.84:32070
$modbusaddress
1
$TimeOut
1500
$Debug
True
#Write to holdings
#Supporting short, unsigned short, long, unsigned long ,float
#CyFlex Variable, CyFlex Units, type, register 1 – 256, scale slope, scale offset
#takes 2 registers for floats
$Write
#float
mbus_write_f1 none f 1 1.0 0.0
mbus_write_f2 none f 3 1.0 0.0
mbus_write_f3 none f 5 1.0 0.0
mbus_write_f4 none f 10 1.0 0.0
#short
mbus_write_s1 none s 7 1.0 0.0
mbus_write_s2 none s 12 1.0 0.0
#ushort
mbus_write_u1 none us 13 1.0 0.0
mbus_write_u2 none us 15 1.0 0.0
#long
mbus_write_l1 none l 28 1.0 0.0
mbus_write_l2 none l 110 1.0 0.0
#double
mbus_write_d1 none d 120 1.0 0.0
mbus_write_d2 none d 140 1.0 0.0
$
#Read Input
#Supporting short, unsigned short, long, unsigned long ,float
#ASSET Variable, Asset Units, type, register 1 – 256, scale slope, scale offset
$Input
#ushort
mbus_read_u1 none us 21 1.0 0.0
mbus_read_u2 none us 24 1.0 0.0
#short
mbus_read_s1 none s 33 1.0 0.0
mbus_read_s2 none s 35 1.0 0.0
#floats
mbus_read_f1 none f 69 1.0 0.0
mbus_read_f2 none f 72 1.0 0.0
mbus_read_f3 none f 74 1.0 0.0
mbus_read_f4 none f 80 1.0 0.0
#doubles
mbus_read_d1 none d 110 1.0 0.0
mbus_read_d2 none d 150 1.0 0.0
#long
mbus_read_l1 none l 16 1.0 0.0
mbus_read_l2 none l 100 1.0 0.0
$
#Write coil
#Will be read as a logical regardless of type
# ASSET Variable, register offset 1 – 256
$WriteCoil
mbus_write_b1 1
mbus_write_b2 3
mbus_write_b3 5
mbus_write_b4 7
$
#Read coil
#Will be read as a logical regardless of type
# ASSET Variable, register offset 1 – 256
$ReadCoil
mbus_read_b1 9
mbus_read_b2 11
mbus_read_b3 13
mbus_read_b4 15
$