Difference between revisions of "Component: Modbus TCP Slave (Comms: System)"
(11 intermediate revisions by one other user not shown) | |||
Line 15: | Line 15: | ||
Modbus component for creating Modbus compatible slave hardware via Ethernet or WIFI. Ensure TCP/IP or WIFI component is initialised and connected to a network before calling the ModbusSlaveTCP component macros. | Modbus component for creating Modbus compatible slave hardware via Ethernet or WIFI. Ensure TCP/IP or WIFI component is initialised and connected to a network before calling the ModbusSlaveTCP component macros. | ||
− | ==Component | + | ==Component Source Code== |
− | + | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_ModbusSlaveTCP.fcfx FC_Comp_Source_ModbusSlaveTCP.fcfx] | |
+ | |||
+ | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_ModbusSlaveTCP.fcfx FC_Comp_Source_ModbusSlaveTCP.fcfx] | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 27: | Line 43: | ||
==Examples== | ==Examples== | ||
+ | Example master program to control the slave. The example sets coil address 0, clears coil address 0, reads an input register and outputs to the LCD. Be sure to set the IP address of the slave device at the top of the program. If you are simulating then use the IP address of the PC running the Slave simulation. Both programs can be simulated on the same PC using two instances of Flowcode. | ||
+ | |||
+ | {{Fcfile|ModbusTCPMasterExample.fcfx|Modbus TCP Master Example}} | ||
+ | |||
+ | |||
+ | Example slave program to react to the signals from the master. The example listens for Modbus commands from the master and outputs the current coils 0 state to an LED connected to PortA. The input register is loaded with a value which is incremented on each Modbus transaction. | ||
+ | |||
+ | {{Fcfile|ModbusTCPSlaveExample.fcfx|Modbus TCP Slave Example}} | ||
+ | |||
+ | |||
+ | ===Addressing=== | ||
+ | |||
+ | In Modbus the addressing protocol looks like this. | ||
+ | |||
+ | {| width="80%" | ||
+ | |'''Data Type''' | ||
+ | |'''Common name''' | ||
+ | |'''Starting address''' | ||
+ | |'''Ending Address''' | ||
+ | |'''Flowcode Start Address''' | ||
+ | |'''Flowcode End Address''' | ||
+ | |- | ||
+ | |Modbus Coils | ||
+ | |Bits, binary values, flags | ||
+ | |00001 | ||
+ | |10000 | ||
+ | |0 | ||
+ | |9999 | ||
+ | |- | ||
+ | |Digital Inputs | ||
+ | |Binary inputs | ||
+ | |10001 | ||
+ | |30000 | ||
+ | |0 | ||
+ | |19999 | ||
+ | |- | ||
+ | |Analog Inputs | ||
+ | |Binary inputs | ||
+ | |30001 | ||
+ | |40000 | ||
+ | |0 | ||
+ | |9999 | ||
+ | |- | ||
+ | |Modbus Registers | ||
+ | |Analog values, variables | ||
+ | |40001 | ||
+ | |60000 | ||
+ | |0 | ||
+ | |19999 | ||
+ | |} | ||
− | + | In Flowcode each section starts from 0 so the address range is as shown. | |
− | == | + | ==Macro reference== |
+ | ===CheckForIncoming=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CheckForIncoming''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Checks for an incoming message and if the data address is within range then also automatically replies with the correct reply. Returns 0 if no comms received, 1 for a succesful transaction, 255 for an error. |
|- | |- | ||
|- | |- | ||
− | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | |
− | |||
− | |||
− | |||
− | |||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===GetLastIncoming=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetLastIncoming''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Gets a value from the last incoming command. Index 0 = 0 Read / 1 Write Index 1 = 0 Coils / 1 DigInput / 2 AnInput / 3 Register Index 2 = Address Index 3 = Number |
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
− | |||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | | width="90%" | | + | | width="90%" | Index |
|- | |- | ||
− | | colspan="2" | 0 | + | | colspan="2" | Range: 0-3 |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===Initialise=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Starts up the UART to allow communications and initialises the states of the various Modbus Coils, Inputs and Registers to 0. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
− | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
Line 97: | Line 146: | ||
+ | ===ReadAnalogInput=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadAnalogInput''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Reads the value of a single analogue input. |
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
− | | width="90%" | | + | | width="90%" | Address |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Coil Address |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===ReadCoils=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 138: | Line 189: | ||
+ | ===ReadDigitalInputs=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadDigitalInputs''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Reads the state of a single digital input. Can pack a max of 8-bits together in a single operation |
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
− | | width="90%" | | + | | width="90%" | StartAddress |
|- | |- | ||
− | | colspan="2" | Coil Address | + | | colspan="2" | Coil Address Range 0 to (NumCoils - 1) |
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
− | | width="90%" | | + | | width="90%" | AddressCount |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Range 1-8 |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===ReadHoldingRegister=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadHoldingRegister''' |
|- | |- | ||
− | | colspan="2" | Reads the value of a single | + | | colspan="2" | Reads the value of a single holding register. |
|- | |- | ||
|- | |- | ||
Line 179: | Line 232: | ||
+ | ===SetAnalogInput=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetAnalogInput''' |
+ | |- | ||
+ | | colspan="2" | Sets the state of a single analogue input. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Address | ||
+ | |- | ||
+ | | colspan="2" | Coil Address | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT |
+ | | width="90%" | Value | ||
|- | |- | ||
+ | | colspan="2" | Analogue Value range 0 - 65535 | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===SetCoil=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetCoil''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Sets the state of a single digital coil. |
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
− | | width="90%" | | + | | width="90%" | Address |
|- | |- | ||
− | | colspan="2" | Coil Address | + | | colspan="2" | Coil Address |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | | width="90%" | | + | | width="90%" | State |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | 0=off, 1=on |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===SetDigitalInput=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetDigitalInput''' |
+ | |- | ||
+ | | colspan="2" | Sets the state of a single digital input. | ||
+ | |- | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT |
+ | | width="90%" | Address | ||
|- | |- | ||
+ | | colspan="2" | Coil Address | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | | width="90%" | | + | | width="90%" | State |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | 0=off, 1=on |
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===SetHoldingRegister=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetHoldingRegister''' |
|- | |- | ||
− | | colspan="2" | Sets the state of a single | + | | colspan="2" | Sets the state of a single holding register. |
|- | |- | ||
|- | |- | ||
Line 256: | Line 328: | ||
+ | ===SetSlaveAddress=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetSlaveAddress''' |
+ | |- | ||
+ | | colspan="2" | Allows the slave address to be overridden from the default slave address specified in the component property. The number of bytes used for the address is fixed by the Slave ID Bytes property to save on RAM usage. | ||
+ | |- | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT |
+ | | width="90%" | SlaveAddress | ||
|- | |- | ||
+ | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
Line 279: | Line 355: | ||
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] |
− | | width="90%" | | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus TCP/IP Properties |
|- | |- | ||
− | | colspan="2" | | + | |- |
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | LinkTo | ||
+ | |- | ||
+ | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
Line 318: | Line 398: | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation Properties | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
Line 323: | Line 407: | ||
|- | |- | ||
| colspan="2" | A text label to appear on the Modbus panel object. | | colspan="2" | A text label to appear on the Modbus panel object. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus Coils - Single bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 333: | Line 421: | ||
|- | |- | ||
| colspan="2" | Specifies how many Coils are available on the slave. Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte. | | colspan="2" | Specifies how many Coils are available on the slave. Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Digital Inputs - Single bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 343: | Line 435: | ||
|- | |- | ||
| colspan="2" | Specifies how many Digital Inputs are available on the slave. Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte. | | colspan="2" | Specifies how many Digital Inputs are available on the slave. Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Analog Inputs - 16-bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 353: | Line 449: | ||
|- | |- | ||
| colspan="2" | Specifies how many 16-bit analogue inputs are available on the slave. Each address consumes two RAM Bytes. | | colspan="2" | Specifies how many 16-bit analogue inputs are available on the slave. Each address consumes two RAM Bytes. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Holding Registers - 16-bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 363: | Line 463: | ||
|- | |- | ||
| colspan="2" | Specifies how many 16-bit holding registers are available on the slave. Each address consumes two RAM Bytes. | | colspan="2" | Specifies how many 16-bit holding registers are available on the slave. Each address consumes two RAM Bytes. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} |
Latest revision as of 15:13, 18 July 2023
Author | Matrix Ltd. |
Version | 2.1 |
Category | Comms: System |
Contents
Modbus TCP Slave component
Modbus component for creating Modbus compatible slave hardware via Ethernet or WIFI. Ensure TCP/IP or WIFI component is initialised and connected to a network before calling the ModbusSlaveTCP component macros.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_ModbusSlaveTCP.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_ModbusSlaveTCP.fcfx
Detailed description
No detailed description exists yet for this component
Examples
Example master program to control the slave. The example sets coil address 0, clears coil address 0, reads an input register and outputs to the LCD. Be sure to set the IP address of the slave device at the top of the program. If you are simulating then use the IP address of the PC running the Slave simulation. Both programs can be simulated on the same PC using two instances of Flowcode.
Example slave program to react to the signals from the master. The example listens for Modbus commands from the master and outputs the current coils 0 state to an LED connected to PortA. The input register is loaded with a value which is incremented on each Modbus transaction.
Addressing
In Modbus the addressing protocol looks like this.
Data Type | Common name | Starting address | Ending Address | Flowcode Start Address | Flowcode End Address |
Modbus Coils | Bits, binary values, flags | 00001 | 10000 | 0 | 9999 |
Digital Inputs | Binary inputs | 10001 | 30000 | 0 | 19999 |
Analog Inputs | Binary inputs | 30001 | 40000 | 0 | 9999 |
Modbus Registers | Analog values, variables | 40001 | 60000 | 0 | 19999 |
In Flowcode each section starts from 0 so the address range is as shown.
Macro reference
CheckForIncoming
GetLastIncoming
Initialise
![]() |
Initialise |
Starts up the UART to allow communications and initialises the states of the various Modbus Coils, Inputs and Registers to 0. | |
![]() |
Return |
ReadAnalogInput
![]() |
ReadAnalogInput |
Reads the value of a single analogue input. | |
![]() |
Address |
Coil Address | |
![]() |
Return |
ReadCoils
ReadDigitalInputs
ReadHoldingRegister
![]() |
ReadHoldingRegister |
Reads the value of a single holding register. | |
![]() |
Address |
Coil Address | |
![]() |
Return |
SetAnalogInput
![]() |
SetAnalogInput |
Sets the state of a single analogue input. | |
![]() |
Address |
Coil Address | |
![]() |
Value |
Analogue Value range 0 - 65535 | |
![]() |
Return |
SetCoil
![]() |
SetCoil |
Sets the state of a single digital coil. | |
![]() |
Address |
Coil Address | |
![]() |
State |
0=off, 1=on | |
![]() |
Return |
SetDigitalInput
![]() |
SetDigitalInput |
Sets the state of a single digital input. | |
![]() |
Address |
Coil Address | |
![]() |
State |
0=off, 1=on | |
![]() |
Return |
SetHoldingRegister
![]() |
SetHoldingRegister |
Sets the state of a single holding register. | |
![]() |
Address |
Coil Address | |
![]() |
Value |
Analogue Value range 0 - 65535 | |
![]() |
Return |
SetSlaveAddress