Difference between revisions of "Component: Modbus Slave (Comms: System)"
Line 15: | Line 15: | ||
Modbus component for creating Modbus compatible slave hardware via RS232 or RS485. | Modbus component for creating Modbus compatible slave hardware via RS232 or RS485. | ||
− | ==Component | + | ==Component Source Code== |
− | + | Please click here for the component source code: [https://www.flowcode.co.uk/wikicopy/componentsource/FC_Comp_Source_ModbusSlave.fcfx FC_Comp_Source_ModbusSlave.fcfx] | |
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
Line 32: | Line 34: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
Line 406: | Line 410: | ||
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | UART Properties | ||
|- | |- | ||
|- | |- | ||
Line 442: | Line 450: | ||
|- | |- | ||
| colspan="2" | Timeout in milliseconds used to dictate the maximum time to wait in milliseconds between bytes in a packet. Range: 1 - 255 | | colspan="2" | Timeout in milliseconds used to dictate the maximum time to wait in milliseconds between bytes in a packet. Range: 1 - 255 | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus Properties | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
Line 472: | Line 484: | ||
|- | |- | ||
| colspan="2" | Controls if the last command from the master is logged allowing for easier value updates. No - Do not log commands Yes - Commands are logged and available via the GetLastIncoming macro | | colspan="2" | Controls if the last command from the master is logged allowing for easier value updates. No - Do not log commands Yes - Commands are logged and available via the GetLastIncoming macro | ||
+ | |- | ||
+ | | 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 502: | Line 518: | ||
|- | |- | ||
| colspan="2" | Selects which API component to route the communication data via. Add API components to the panel before they will be available in this list. API components are available from the Comms component category. | | colspan="2" | Selects which API component to route the communication data via. Add API components to the panel before they will be available in this list. API components are available from the Comms component category. | ||
+ | |- | ||
+ | | 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 512: | Line 532: | ||
|- | |- | ||
| 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 522: | Line 546: | ||
|- | |- | ||
| 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 532: | Line 560: | ||
|- | |- | ||
| 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 542: | Line 574: | ||
|- | |- | ||
| 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. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} |
Revision as of 17:49, 9 November 2022
Author | Matrix Ltd. |
Version | 2.0 |
Category | Comms: System |
Contents
Modbus Slave component
Modbus component for creating Modbus compatible slave hardware via RS232 or RS485.
Component Source Code
Please click here for the component source code: FC_Comp_Source_ModbusSlave.fcfx
Detailed description
No detailed description exists yet for this component
Examples
Example master program to control the slave. The example reads the 8 switches connected to PortD. If the switch values change then the new value is send to the slave.
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-7 state to eight LEDs connected to PortD.
Master and Slave example using vNet
Example of communicating using Modbus Master and Slave using two instances of Flowcode and the vNet injector component.
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.
Downloadable macro reference
ReadHoldingRegister | |
Reads the value of a single holding register. | |
- UINT | Address |
Coil Address | |
- UINT | Return |
SetCoil | |
Sets the state of a single digital coil. | |
- UINT | Address |
Coil Address | |
- BYTE | State |
0=off, 1=on | |
- VOID | Return |
SetDigitalInput | |
Sets the state of a single digital input. | |
- UINT | Address |
Coil Address | |
- BYTE | State |
0=off, 1=on | |
- VOID | Return |
ChangeFrameType | |
Default frame type is the type set in the component properties. | |
- BYTE | Type |
0 = Modbus RTU / 1 = Modbus ASCII | |
- VOID | Return |
SetHoldingRegister | |
Sets the state of a single holding register. | |
- UINT | Address |
Coil Address | |
- UINT | Value |
Analogue Value range 0 - 65535 | |
- VOID | Return |
ReadAnalogInput | |
Reads the value of a single analogue input. | |
- UINT | Address |
Coil Address | |
- UINT | Return |
SetAnalogInput | |
Sets the state of a single analogue input. | |
- UINT | Address |
Coil Address | |
- UINT | Value |
Analogue Value range 0 - 65535 | |
- VOID | Return |
Initialise | |
Starts up the UART to allow communications and initialises the states of the various Modbus Coils, Inputs and Registers to 0. | |
- VOID | Return |