Difference between revisions of "Component: Modbus TCP Slave (Comms: System)"
(One intermediate revision by one other user not shown) | |||
Line 17: | Line 17: | ||
==Component Source Code== | ==Component Source Code== | ||
− | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/ | + | 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/ | + | 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 43: | 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== | ==Macro reference== |
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