Component: Modbus Master (Comms: System): Difference between revisions
No edit summary |
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 14: | Line 14: | ||
==Modbus Master component== | ==Modbus Master component== | ||
Modbus component for talking to Modbus compatible hardware via RS232 or RS485. | Modbus component for talking to Modbus compatible hardware via RS232 or RS485. | ||
==Detailed description== | ==Detailed description== | ||
| Line 156: | Line 150: | ||
===ChangeBaud=== | ===ChangeBaud=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ChangeBaud''' | ||
|- | |- | ||
| colspan="2" | Changes the UART Baud rate. 1 = 1200 / 2 = 2400 / 3 = 4800 / 4 = 9600 / 5 = 19200 / 6 = 31250 7 = 38400 / 8 = 57600 / 9 = 115200 | | colspan="2" | Changes the UART Baud rate. 1 = 1200 / 2 = 2400 / 3 = 4800 / 4 = 9600 / 5 = 19200 / 6 = 31250 7 = 38400 / 8 = 57600 / 9 = 115200 | ||
| Line 175: | Line 169: | ||
===ChangeFrameType=== | ===ChangeFrameType=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ChangeFrameType''' | ||
|- | |- | ||
| colspan="2" | Default frame type is the type set in the component properties. | | colspan="2" | Default frame type is the type set in the component properties. | ||
| Line 194: | Line 188: | ||
===GetResponse=== | ===GetResponse=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetResponse''' | ||
|- | |- | ||
| colspan="2" | Collects as much incoming data as possible and stored into the response buffer. The number of bytes received will be stored into location 0 of the response buffer. Return value indicates validity of incoming CRC. 0 = OK, 1 = CRC fail, 255 = No Data | | colspan="2" | Collects as much incoming data as possible and stored into the response buffer. The number of bytes received will be stored into location 0 of the response buffer. Return value indicates validity of incoming CRC. 0 = OK, 1 = CRC fail, 255 = No Data | ||
|- | |- | ||
|- | |||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | |||
| width="90%" | NumBytes | |||
|- | |||
| colspan="2" | | |||
|- | |- | ||
| 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-u8-icon.png]] - BYTE | ||
| Line 208: | Line 207: | ||
===GetResponseByte=== | ===GetResponseByte=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetResponseByte''' | ||
|- | |- | ||
| colspan="2" | Reads a byte from the last received response. The Index parametes specifies which byte to read back. | | colspan="2" | Reads a byte from the last received response. The Index parametes specifies which byte to read back. | ||
| Line 227: | Line 226: | ||
===GetResponseInt=== | ===GetResponseInt=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetResponseInt''' | ||
|- | |- | ||
| colspan="2" | Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back. | | colspan="2" | Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back. | ||
| Line 246: | Line 245: | ||
===Initialise=== | ===Initialise=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Initialise''' | ||
|- | |- | ||
| colspan="2" | Starts up the UART to allow communications | | colspan="2" | Starts up the UART to allow communications | ||
| Line 260: | Line 259: | ||
===ReadAnalogInput=== | ===ReadAnalogInput=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadAnalogInput''' | ||
|- | |- | ||
| colspan="2" | This command requests the analogue input register values starting from the start RegAddress and going through to RegAddress plus RegCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command requests the analogue input register values starting from the start RegAddress and going through to RegAddress plus RegCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 289: | Line 288: | ||
===ReadCoil=== | ===ReadCoil=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadCoil''' | ||
|- | |- | ||
| colspan="2" | This command requests the ON/OFF status of discrete coils starting from the start CoilAddress and going through to CoilAddress plus CoilCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command requests the ON/OFF status of discrete coils starting from the start CoilAddress and going through to CoilAddress plus CoilCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 318: | Line 317: | ||
===ReadDigitalInput=== | ===ReadDigitalInput=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadDigitalInput''' | ||
|- | |- | ||
| colspan="2" | This command requests the ON/OFF status of discrete inputs starting from the start DataAddress and going through to DataAddress plus DataCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command requests the ON/OFF status of discrete inputs starting from the start DataAddress and going through to DataAddress plus DataCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 347: | Line 346: | ||
===ReadHoldingRegister=== | ===ReadHoldingRegister=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadHoldingRegister''' | ||
|- | |- | ||
| colspan="2" | This command requests the analogue holding register values starting from the start RegAddress and going through to RegAddress plus RegCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command requests the analogue holding register values starting from the start RegAddress and going through to RegAddress plus RegCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 376: | Line 375: | ||
===SetCoil=== | ===SetCoil=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetCoil''' | ||
|- | |- | ||
| colspan="2" | This command writes the contents of a discrete coil at the location CoilAddress. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command writes the contents of a discrete coil at the location CoilAddress. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 405: | Line 404: | ||
===SetCoils=== | ===SetCoils=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetCoils''' | ||
|- | |- | ||
| colspan="2" | This command writes the contents of a series of discrete coils at the location starting at CoilAddress through to CoilAddress + CoilCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command writes the contents of a series of discrete coils at the location starting at CoilAddress through to CoilAddress + CoilCount. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 439: | Line 438: | ||
===SetHoldingRegister=== | ===SetHoldingRegister=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetHoldingRegister''' | ||
|- | |- | ||
| colspan="2" | This command writes the contents of a holding register at the location RegAddress. Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command writes the contents of a holding register at the location RegAddress. Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 468: | Line 467: | ||
===SetHoldingRegisters=== | ===SetHoldingRegisters=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''SetHoldingRegisters''' | ||
|- | |- | ||
| colspan="2" | This command writes the contents of several holding registers starting at the location RegAddress through to location RegAddress + RegCount . Returns 0 for success, 1 for CRC fail and 255 for no reply. | | colspan="2" | This command writes the contents of several holding registers starting at the location RegAddress through to location RegAddress + RegCount . Returns 0 for success, 1 for CRC fail and 255 for no reply. | ||
| Line 503: | Line 502: | ||
==Property reference== | ==Property reference== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | UART Properties | ||
|- | |- | ||
|- | |- | ||
| Line 543: | Line 542: | ||
| colspan="2" | Specifies the bus mode being used, RS232 allows you to connect a single master node to a single slave node. RS485 allows you to connect a single master node to multiple slave nodes. | | colspan="2" | Specifies the bus mode being used, RS232 allows you to connect a single master node to a single slave node. RS485 allows you to connect a single master node to multiple slave nodes. | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Modbus Properties | ||
|- | |- | ||
|- | |- | ||
| Line 577: | Line 576: | ||
| colspan="2" | Number of timeouts in a row to wait for until we decide the slave is not responding or finished responding to a message. Range: 0 - 255 0 = First Timeout Only 1 = First Timeout + 1 2 = First Timeout + 2 | | colspan="2" | Number of timeouts in a row to wait for until we decide the slave is not responding or finished responding to a message. Range: 0 - 255 0 = First Timeout Only 1 = First Timeout + 1 2 = First Timeout + 2 | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Simulation Properties | ||
|- | |- | ||
|- | |- | ||
| Line 607: | Line 606: | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
| width="90%" | | | width="90%" | COM Port | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | Lists all the current available COM port hardware on your PC. | ||
|} | |} | ||
==Component Source Code== | |||
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Modbus.fcfx FC_Comp_Source_Modbus.fcfx] | |||
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Modbus.fcfx FC_Comp_Source_Modbus.fcfx] | |||
Latest revision as of 14:37, 13 July 2026
| Author | Matrix Ltd. |
| Version | 2.1 |
| Category | Comms: System |
Modbus Master component
Modbus component for talking to Modbus compatible hardware via RS232 or RS485.
Detailed description
No detailed description exists yet for this component
Examples
CT-2EA Modbus Electronic kWh Meter
Example to talk to a CT-2EA Modbus Electronic kWh Meter
Setup to communicate via Embedded UART1 or Simulated COM3
Console data generated by the working example running in the simulation and communicating via the COM port.
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.
Macro reference
ChangeBaud
ChangeFrameType
| ChangeFrameType | |
| Default frame type is the type set in the component properties. | |
| Type | |
| 0 = Modbus RTU / 1 = Modbus ASCII | |
| Return | |
GetResponse
GetResponseByte
GetResponseInt
| GetResponseInt | |
| Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back. | |
| Index | |
| 4=data0, 6=data1, 8=data2, .. | |
| Return | |
Initialise
| Initialise | |
| Starts up the UART to allow communications | |
| Return | |
ReadAnalogInput
ReadCoil
ReadDigitalInput
ReadHoldingRegister
SetCoil
SetCoils
SetHoldingRegister
SetHoldingRegisters
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Modbus.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Modbus.fcfx

