Component: Modbus Master (Comms: System): Difference between revisions
m Text replacement - "width="10%" align="center" style="background-color:#D8C9D8;" align="center"" to "width="10%" align="center" class="mtx-class-macrohead"" |
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 153: | Line 153: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 172: | Line 172: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 191: | Line 191: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 | ||
| Line 210: | Line 210: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 229: | Line 229: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 248: | Line 248: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 262: | Line 262: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 291: | Line 291: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 320: | Line 320: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 349: | Line 349: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 378: | Line 378: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 407: | Line 407: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 441: | Line 441: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 470: | Line 470: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | 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 504: | Line 504: | ||
{| class="mtx-class-macrotable 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 542: | 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 576: | 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 | ||
|- | |- | ||
|- | |- | ||
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

