Difference between revisions of "Component: Modbus Master (Comms: System)"

From Flowcode Help
Jump to navigationJump to search
 
(12 intermediate revisions by the same user 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.  
 +
 +
==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]
  
 
==Detailed description==
 
==Detailed description==
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
  
  
Line 24: Line 48:
  
 
==Examples==
 
==Examples==
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
  
  
Line 101: Line 143:
 
In Flowcode each section starts from 0 so the address range is as shown.
 
In Flowcode each section starts from 0 so the address range is as shown.
  
==Downloadable macro reference==
 
  
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
==Macro reference==
 +
 +
===ChangeBaud===
 
{| 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;" | '''ReadHoldingRegister'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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" | 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. 
+
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Baud
 
|-
 
|-
 +
| colspan="2" | The new baud rate (0=1200, 9=115200) 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" | SlaveID
+
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
 +
 
 +
 
 +
===ChangeFrameType===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
|-
| colspan="2" | The ID of the MODBUS slave 
+
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ChangeFrameType'''
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| colspan="2" | Default frame type is the type set in the component properties. 
| width="90%" | RegAddress
 
 
|-
 
|-
| colspan="2" | Address: 0=40001, 1=40002, ... 
 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | RegCount
+
| width="90%" | Type
 
|-
 
|-
| colspan="2" | Number of consecutive registers to read, starting from RegAddress 
+
| colspan="2" | 0 = Modbus RTU / 1 = Modbus ASCII 
 
|-
 
|-
| 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-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
  
  
 +
===GetResponse===
 
{| 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;" | '''ReadCoil'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetResponse'''
 
|-
 
|-
| 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" | 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-u16-icon.png]] - UINT
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | SlaveID
+
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
 +
 
 +
 
 +
===GetResponseByte===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
|-
 
|-
| colspan="2" | The ID of the MODBUS slave 
+
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetResponseByte'''
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| colspan="2" | Reads a byte from the last received response. The Index parametes specifies which byte to read back.  
| width="90%" | CoilAddress
 
 
|-
 
|-
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | CoilCount
+
| width="90%" | Index
 
|-
 
|-
| colspan="2" | Number of consecutive coils to try and read 
+
| colspan="2" | 0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, 3=DataBytes, 4=data0, 5=data1, .. 
 
|-
 
|-
 
| 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 159: Line 226:
  
  
 +
===GetResponseInt===
 
{| 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;" | '''SetCoil'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetResponseInt'''
 
|-
 
|-
| 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" | Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back.  
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | SlaveID
 
|-
 
| colspan="2" | The ID of the MODBUS slave 
 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | CoilAddress
 
|-
 
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | CoilState
+
| width="90%" | Index
 
|-
 
|-
| colspan="2" | 0=Off, 1=On 
+
| colspan="2" | 4=data0, 6=data1, 8=data2, .. 
 
|-
 
|-
| 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-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;" | '''GetResponse'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 
|-
 
|-
| 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" | Starts up the UART to allow communications 
 
|-
 
|-
 
|-
 
|-
| 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-void-icon.png]] - VOID
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
  
  
 +
===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;" | '''SetCoils'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadAnalogInput'''
 
|-
 
|-
| 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 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 214: Line 274:
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | CoilAddress
+
| width="90%" | RegAddress
 
|-
 
|-
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
+
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ... 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | CoilCount
+
| width="90%" | RegCount
 
|-
 
|-
| colspan="2" | Number of consecutive coils to try and read 
+
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | CoilData
 
|-
 
| colspan="2" | An array of bytes each containing 8 1-bit coil values 
 
 
|-
 
|-
 
| 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 233: Line 288:
  
  
 +
===ReadCoil===
 
{| 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;" | '''GetResponseByte'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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. 
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave 
 
|-
 
|-
| colspan="2" | Reads a byte from the last received response. The Index parametes specifies which byte to read back.  
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilAddress
 
|-
 
|-
 +
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Index
+
| width="90%" | CoilCount
 
|-
 
|-
| colspan="2" | 0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, 3=DataBytes, 4=data0, 5=data1, .. 
+
| colspan="2" | Number of consecutive coils to try and read 
 
|-
 
|-
 
| 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 251: Line 317:
  
  
 +
===ReadDigitalInput===
 
{| 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;" | '''ChangeFrameType'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadDigitalInput'''
 
|-
 
|-
| colspan="2" | Default frame type is the type set in the component properties. 
+
| 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. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Type
+
| width="90%" | SlaveID
 
|-
 
|-
| colspan="2" | 0 = Modbus RTU / 1 = Modbus ASCII 
+
| colspan="2" | The ID of the MODBUS slave 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | DataAddress
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
 
|-
 
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
+
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ... 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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.  
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | DataCount
 
|-
 
|-
 +
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Index
 
|-
 
| colspan="2" | 4=data0, 6=data1, 8=data2, .. 
 
|-
 
| 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''
 
|}
 
|}
  
  
 +
===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;" | '''SetHoldingRegisters'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadHoldingRegister'''
 
|-
 
|-
| 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 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 308: Line 368:
 
| width="90%" | RegCount
 
| width="90%" | RegCount
 
|-
 
|-
| colspan="2" | Number of consecutive registers to write, starting from RegAddress 
+
| colspan="2" | Number of consecutive registers to read, starting from RegAddress 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="90%" | RegValue
 
|-
 
| colspan="2" | Array of values to send to the registers 
 
 
|-
 
|-
 
| 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 320: Line 375:
  
  
 +
===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;" | '''ReadAnalogInput'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetCoil'''
 
|-
 
|-
| 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 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 334: Line 390:
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | RegAddress
+
| width="90%" | CoilAddress
 
|-
 
|-
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ... 
+
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
+
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | RegCount
+
| width="90%" | CoilState
 
|-
 
|-
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress 
+
| colspan="2" | 0=Off, 1=On 
 
|-
 
|-
 
| 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 348: Line 404:
  
  
 +
===SetCoils===
 
{| 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;" | '''SetHoldingRegister'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetCoils'''
 
|-
 
|-
| 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 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 362: Line 419:
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | RegAddress
+
| width="90%" | CoilAddress
 
|-
 
|-
| colspan="2" | Address: 0=40001, 1=40002, ... 
+
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | RegValue
+
| width="90%" | CoilCount
 +
|-
 +
| colspan="2" | Number of consecutive coils to try and read 
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | CoilData
 
|-
 
|-
| colspan="2" | Value to send to the selected register 
+
| colspan="2" | An array of bytes each containing 8 1-bit coil values 
 
|-
 
|-
 
| 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 376: Line 438:
  
  
 +
===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;" | '''ChangeBaud'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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. 
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave 
 
|-
 
|-
| 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 
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegAddress
 
|-
 
|-
 +
| colspan="2" | Address: 0=40001, 1=40002, ... 
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Baud
+
| width="90%" | RegValue
 
|-
 
|-
| colspan="2" | The new baud rate (0=1200, 9=115200) 
+
| colspan="2" | Value to send to the selected register 
 
|-
 
|-
| 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-u8-icon.png]] - BYTE
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
  
  
 +
===SetHoldingRegisters===
 
{| 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;" | '''ReadDigitalInput'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetHoldingRegisters'''
 
|-
 
|-
| 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 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 408: Line 482:
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | DataAddress
+
| width="90%" | RegAddress
 
|-
 
|-
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ... 
+
| colspan="2" | Address: 0=40001, 1=40002, ... 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | DataCount
+
| width="90%" | RegCount
 
|-
 
|-
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress 
+
| colspan="2" | Number of consecutive registers to write, starting from RegAddress 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | RegValue
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
 
|-
 
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
+
| colspan="2" | Array of values to send to the registers 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 
 
|-
 
|-
| colspan="2" | Starts up the UART to allow communications 
+
| 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-void-icon.png]] - VOID
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
 
 
  
  
Line 443: Line 507:
 
| 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 474: 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" 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 504: 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" 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 534: Line 610:
 
|-
 
|-
 
| 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:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections'''
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]]
 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations'''
 
|-
 
 
|}
 
|}

Latest revision as of 13:12, 7 February 2023

Author Matrix Ltd.
Version 2.1
Category Comms: System


Modbus Master component

Modbus component for talking to Modbus compatible hardware via RS232 or RS485.

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

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

FC6 Icon.png ModbusDemo

Setup to communicate via Embedded UART1 or Simulated COM3

ModbusConns.jpg


Console data generated by the working example running in the simulation and communicating via the COM port.

ModbusConsole.jpg


Master and Slave example using vNet

Example of communicating using Modbus Master and Slave using two instances of Flowcode and the vNet injector component.

FC6 Icon.png ModbusMasterDemo

FC6 Icon.png ModBusSlaveDemo


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

Fc9-comp-macro.png ChangeBaud
Changes the UART Baud rate. 1 = 1200 / 2 = 2400 / 3 = 4800 / 4 = 9600 / 5 = 19200 / 6 = 31250 7 = 38400 / 8 = 57600 / 9 = 115200 
Fc9-u8-icon.png - BYTE Baud
The new baud rate (0=1200, 9=115200) 
Fc9-void-icon.png - VOID Return


ChangeFrameType

Fc9-comp-macro.png ChangeFrameType
Default frame type is the type set in the component properties. 
Fc9-u8-icon.png - BYTE Type
0 = Modbus RTU / 1 = Modbus ASCII 
Fc9-void-icon.png - VOID Return


GetResponse

Fc9-comp-macro.png GetResponse
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 
Fc9-u8-icon.png - BYTE Return


GetResponseByte

Fc9-comp-macro.png GetResponseByte
Reads a byte from the last received response. The Index parametes specifies which byte to read back.  
Fc9-u8-icon.png - BYTE Index
0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, 3=DataBytes, 4=data0, 5=data1, .. 
Fc9-u8-icon.png - BYTE Return


GetResponseInt

Fc9-comp-macro.png GetResponseInt
Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back.  
Fc9-u8-icon.png - BYTE Index
4=data0, 6=data1, 8=data2, .. 
Fc9-u16-icon.png - UINT Return


Initialise

Fc9-comp-macro.png Initialise
Starts up the UART to allow communications 
Fc9-void-icon.png - VOID Return


ReadAnalogInput

Fc9-comp-macro.png ReadAnalogInput
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT RegAddress
Input Address: 0=10001, 1=10002, 2=10003, ... 
Fc9-u16-icon.png - UINT RegCount
Number of consecutive inputs to read, starting from RegAddress 
Fc9-u8-icon.png - BYTE Return


ReadCoil

Fc9-comp-macro.png ReadCoil
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Fc9-u16-icon.png - UINT CoilCount
Number of consecutive coils to try and read 
Fc9-u8-icon.png - BYTE Return


ReadDigitalInput

Fc9-comp-macro.png ReadDigitalInput
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT DataAddress
Input Address: 0=10001, 1=10002, 2=10003, ... 
Fc9-u16-icon.png - UINT DataCount
Number of consecutive inputs to read, starting from RegAddress 
Fc9-u8-icon.png - BYTE Return


ReadHoldingRegister

Fc9-comp-macro.png ReadHoldingRegister
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT RegAddress
Address: 0=40001, 1=40002, ... 
Fc9-u16-icon.png - UINT RegCount
Number of consecutive registers to read, starting from RegAddress 
Fc9-u8-icon.png - BYTE Return


SetCoil

Fc9-comp-macro.png SetCoil
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Fc9-u8-icon.png - BYTE CoilState
0=Off, 1=On 
Fc9-u8-icon.png - BYTE Return


SetCoils

Fc9-comp-macro.png SetCoils
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Fc9-u16-icon.png - UINT CoilCount
Number of consecutive coils to try and read 
Fc9-u8-icon.png - BYTE CoilData
An array of bytes each containing 8 1-bit coil values 
Fc9-u8-icon.png - BYTE Return


SetHoldingRegister

Fc9-comp-macro.png SetHoldingRegister
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT RegAddress
Address: 0=40001, 1=40002, ... 
Fc9-u16-icon.png - UINT RegValue
Value to send to the selected register 
Fc9-u8-icon.png - BYTE Return


SetHoldingRegisters

Fc9-comp-macro.png SetHoldingRegisters
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. 
Fc9-u16-icon.png - UINT SlaveID
The ID of the MODBUS slave 
Fc9-u16-icon.png - UINT RegAddress
Address: 0=40001, 1=40002, ... 
Fc9-u16-icon.png - UINT RegCount
Number of consecutive registers to write, starting from RegAddress 
Fc9-u16-icon.png - UINT RegValue
Array of values to send to the registers 
Fc9-u8-icon.png - BYTE Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png UART Properties
Fc9-type-16-icon.png Channel
UART Channel selector Software channels are bit banged using generic I/O pins but are not as reliable as hardware channels. Hardware channels use the selected peripheral on-board the target microcontroller. 
Fc9-type-5-icon.png TX
Pin to be used for Transmit data 
Fc9-type-5-icon.png RX
Pin to be used for Receive data 
Fc9-type-16-icon.png Baud Options
Baud rate option selector 
Fc9-type-14-icon.png Baud Rate
 
Fc9-type-16-icon.png Bus
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. 
Fc9-conn-icon.png Modbus Properties
Fc9-type-16-icon.png Frame Type
Switches between RTU and ASCII forms of Modbus 
Fc9-type-21-icon.png Receive Buffer Size
Maximum number of bytes the receive buffer can hold 
Fc9-type-21-icon.png Slave ID Bytes
Number of bytes used when passing a slave ID, usually 1 but sometimes 2 
Fc9-type-21-icon.png Silent Interval
Configures how much time to wait after each master modbus command before another command can be sent. A silent interval of 60ms minimum is required in order to guarentee successful reception of the next transmission. 0=No Delay 60 = 60mS - Default Range : 0 - 65535 
Fc9-type-21-icon.png UART Receive Timeout
Amount of time to wait before timing out when listening for a slave's response. Range: 0 - 255. 0 = Don't Wait 1 - 254 = X ms 255 = Wait Forever 
Fc9-type-21-icon.png Receive Timeout Count
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 
Fc9-conn-icon.png Simulation Properties
Fc9-type-10-icon.png Label
A text label to appear on the Modbus panel object. 
Fc9-type-7-icon.png Scope Traces
Selects if the scope traces are automatically added to the data recorder window or not. Simulation - draws an approximation of the UART data onto the scope trace. ICT - sets up the scope trace for incoming data and adds UART packet decoding at the correct BAUD. 
Fc9-type-7-icon.png Console Data
Selects if the console data is automatically generated or not 
Fc9-type-21-icon.png Console Columns
Number of characters that can be displayed on a single line of the console. 
Fc9-type-16-icon.png Data Source
Simulation data source used to allow the component to connect to various remote devices Nothing - Simulation data is ignored COM port - Routes the communication data to and from a physical or virtual COM port API - Routes the communication data via a data API component on the Panel. 
Fc9-type-16-icon.png API
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.