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

From Flowcode Help
Jump to navigationJump to search
(XML import)
 
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
+
{| style="width:50%"
 
 
{| width="50%"
 
 
|-
 
|-
| width="20%" style="color: gray;" | Author
+
| width="20%" style="color:gray;" | Author
 
| Matrix Ltd.
 
| Matrix Ltd.
 
|-
 
|-
| width="20%" style="color: gray;" | Version
+
| width="20%" style="color:gray;" | Version
| 2.0 (Release)
+
| 2.1
 
|-
 
|-
| width="20%" style="color: gray;" | Category
+
| width="20%" style="color:gray;" | Category
 
| Comms: System
 
| Comms: System
 
|}
 
|}
  
  
 +
==Modbus TCP Master component==
 +
Modbus component for talking to Modbus compatible hardware via Ethernet or WIFI. Ensure TCP/IP or WIFI component is initialised and connected to a network before calling the ModbusMasterTCP component macros.
  
==[[File:Component Icon 019e3dbb_2bfa_44a7_baf0_17b672d9b8f4.png|Image]] Modbus TCP Master component==
+
==Component Pack==
Modbus component for talking to Modbus compatible hardware via Ethernet or WIFI.
 
Ensure TCP/IP or WIFI component is intialised and connected to a network before calling the ModbusMasterTCP component macros.
 
  
 +
COMMSC
  
==Examples==
+
==Detailed description==
''<span style="color:red;">No additional examples</span>''
 
  
  
==Downloadable macro reference==
 
  
===<span style="font-weight: normal;"><u><tt>ReadHoldingRegister</tt></u></span>===
 
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.
 
  
'''Parameters'''
 
  
:[[Variable Types|UINT]] ''SlaveID''
 
::The ID of the MODBUS slave
 
  
:[[Variable Types|UINT]] ''RegAddress''
 
::Address: 0=40001, 1=40002, ...
 
  
:[[Variable Types|UINT]] ''RegCount''
 
::Number of consecutive registers to read, starting from RegAddress
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
''No detailed description exists yet for this component''
  
 +
==Examples==
  
===<span style="font-weight: normal;"><u><tt>ForceMultipleCoils</tt></u></span>===
 
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.
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''SlaveID''
 
::The ID of the MODBUS slave - Used for TCP to Serial forwarders
 
  
:[[Variable Types|UINT]] ''CoilAddress''
 
::Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...
 
  
:[[Variable Types|UINT]] ''CoilCount''
 
::Number of consecutive coils to try and read
 
  
:[[Variable Types|BYTE]] ''CoilData''
 
::An array of bytes each containing 8 1-bit coil values
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
 
  
  
===<span style="font-weight: normal;"><u><tt>ForceSingleCoil</tt></u></span>===
 
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.
+
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.
  
'''Parameters'''
+
{{Fcfile|ModbusTCPMasterExample.fcfx|Modbus TCP Master Example}}
  
:[[Variable Types|BYTE]] ''SlaveID''
 
::The ID of the MODBUS slave
 
  
:[[Variable Types|UINT]] ''CoilAddress''
+
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.
::Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...
 
  
:[[Variable Types|BYTE]] ''CoilState''
+
{{Fcfile|ModbusTCPSlaveExample.fcfx|Modbus TCP Slave Example}}
::0=Off, 1=On
 
  
  
'''Return value'''
+
===Addressing===
  
:[[Variable Types|BYTE]]
+
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
 +
|}
  
===<span style="font-weight: normal;"><u><tt>ReadCoilStatus</tt></u></span>===
 
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.
+
In Flowcode each section starts from 0 so the address range is as shown.
  
'''Parameters'''
 
  
:[[Variable Types|UINT]] ''SlaveID''
+
==Downloadable macro reference==
::The ID of the MODBUS slave
 
  
:[[Variable Types|UINT]] ''CoilAddress''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegAddress
 +
|-
 +
| colspan="2" | Address: 0=40001, 1=40002, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegCount
 +
|-
 +
| colspan="2" | Number of consecutive registers to read, starting from RegAddress&nbsp;
 +
|-
 +
| 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''
 +
|}
  
:[[Variable Types|UINT]] ''CoilCount''
 
::Number of consecutive coils to try and read
 
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilAddress
 +
|-
 +
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | CoilState
 +
|-
 +
| colspan="2" | 0=Off, 1=On&nbsp;
 +
|-
 +
| 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''
 +
|}
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave - Used for TCP to Serial forwarders&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilAddress
 +
|-
 +
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilCount
 +
|-
 +
| colspan="2" | Number of consecutive coils to try and read&nbsp;
 +
|-
 +
| 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&nbsp;
 +
|-
 +
| 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''
 +
|}
  
  
===<span style="font-weight: normal;"><u><tt>GetResponseByte</tt></u></span>===
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
Reads a byte from the last received response. The Index parametes specifies which byte to read back.
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetResponseByte'''
 +
|-
 +
| colspan="2" | Reads a byte from the last received response. The Index parametes specifies which byte to read back. &nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Index
 +
|-
 +
| colspan="2" | 0=SlaveAddress, 1=FunctionCode/ExceptionCode, 2=DataBytes, 3=data0, 4=data1, ..&nbsp;
 +
|-
 +
| 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''
 +
|}
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Index''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, .....
+
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadCoils'''
 +
|-
 +
| 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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilAddress
 +
|-
 +
| colspan="2" | Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | CoilCount
 +
|-
 +
| colspan="2" | Number of consecutive coils to try and read&nbsp;
 +
|-
 +
| 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''
 +
|}
  
  
'''Return value'''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| 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. &nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Index
 +
|-
 +
| colspan="2" | 3=data0, 5=data1, 7=data2, ..&nbsp;
 +
|-
 +
| 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''
 +
|}
  
:[[Variable Types|BYTE]]
 
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetHoldingRegisters'''
 +
|-
 +
| colspan="2" | This command writes the contents of several analogue output 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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegAddress
 +
|-
 +
| colspan="2" | Address: 0=40001, 1=40002, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegCount
 +
|-
 +
| colspan="2" | Number of consecutive registers to write, starting from RegAddress&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegValue
 +
|-
 +
| colspan="2" | Array of values to send to the registers&nbsp;
 +
|-
 +
| 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''
 +
|}
  
===<span style="font-weight: normal;"><u><tt>ReadInputStatus</tt></u></span>===
 
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.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetHoldingRegister'''
 +
|-
 +
| colspan="2" | This command writes the contents of a analogue output holding register at the location RegAddress. Returns 0 for success, 1 for CRC fail and 255 for no reply.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegAddress
 +
|-
 +
| colspan="2" | Address: 0=40001, 1=40002, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegValue
 +
|-
 +
| colspan="2" | Value to send to the selected register&nbsp;
 +
|-
 +
| 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''
 +
|}
  
'''Parameters'''
 
  
:[[Variable Types|UINT]] ''SlaveID''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::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;" | '''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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegAddress
 +
|-
 +
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | RegCount
 +
|-
 +
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress&nbsp;
 +
|-
 +
| 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''
 +
|}
  
:[[Variable Types|UINT]] ''DataAddress''
 
::Input Address: 0=10001, 1=10002, 2=10003, ...
 
  
:[[Variable Types|UINT]] ''DataCount''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
::Number of consecutive inputs to read, starting from RegAddress
+
|-
 
+
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetTCPAddress'''
'''Return value'''
+
|-
 
+
| colspan="2" | Sets the address of the remote TCP Slave that we wish to control.&nbsp;
:[[Variable Types|BYTE]]
+
|-
 
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
===<span style="font-weight: normal;"><u><tt>PresetSingleRegister</tt></u></span>===
+
| width="90%" | Address
This command writes the contents of a analogue output holding registerl at the location RegAddress.
+
|-
 
+
| colspan="2" | e.g. "192.168.1.1"&nbsp;
Returns 0 for success, 1 for CRC fail and 255 for no reply.
+
|-
 
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
'''Parameters'''
+
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
+
|}
:[[Variable Types|UINT]] ''SlaveID''
 
::The ID of the MODBUS slave
 
 
 
:[[Variable Types|UINT]] ''RegAddress''
 
::Address: 0=40001, 1=40002, ...
 
 
 
:[[Variable Types|UINT]] ''RegValue''
 
::Value to send to the selected register
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|BYTE]]
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>GetResponseInt</tt></u></span>===
 
Reads a 16-bit value from the last received response.
 
 
 
The Index parametes specifies the byte index of the value to read back.
 
 
 
'''Parameters'''
 
 
 
:[[Variable Types|BYTE]] ''Index''
 
::0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, .....
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|UINT]]
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>ReadInputRegister</tt></u></span>===
 
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.
 
 
 
'''Parameters'''
 
 
 
:[[Variable Types|UINT]] ''SlaveID''
 
::The ID of the MODBUS slave
 
 
 
:[[Variable Types|UINT]] ''RegAddress''
 
::Input Address: 0=10001, 1=10002, 2=10003, ...
 
 
 
:[[Variable Types|UINT]] ''RegCount''
 
::Number of consecutive inputs to read, starting from RegAddress
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|BYTE]]
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>PresetMultipleRegisters</tt></u></span>===
 
This command writes the contents of several analogue output 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.
 
 
 
'''Parameters'''
 
 
 
:[[Variable Types|UINT]] ''SlaveID''
 
::The ID of the MODBUS slave
 
 
 
:[[Variable Types|UINT]] ''RegAddress''
 
::Address: 0=40001, 1=40002, ...
 
 
 
:[[Variable Types|UINT]] ''RegCount''
 
::Number of consecutive registers to write, starting from RegAddress
 
 
 
:[[Variable Types|UINT]] ''RegValue''
 
::Array of values to send to the registers
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|BYTE]]
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>SetTCPAddress</tt></u></span>===
 
Sets the address of the remote TCP Slave that we wish to control.
 
 
 
'''Parameters'''
 
 
 
:[[Variable Types|<- STRING]] ''Address''
 
::e.g. "192.168.1.1"
 
::''This parameter may be returned back to the caller''
 
 
 
 
 
'''Return value'''
 
 
 
:''This call does not return a value''
 
  
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadDigitalInputs'''
 +
|-
 +
| 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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | SlaveID
 +
|-
 +
| colspan="2" | The ID of the MODBUS slave&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | DataAddress
 +
|-
 +
| colspan="2" | Input Address: 0=10001, 1=10002, 2=10003, ...&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | DataCount
 +
|-
 +
| colspan="2" | Number of consecutive inputs to read, starting from RegAddress&nbsp;
 +
|-
 +
| 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''
 +
|}
  
==Simulation macro reference==
 
  
''This component does not contain any simulation macros''
 
  
  
 
==Property reference==
 
==Property reference==
<span style="font-weight: normal;"><u>TCP/IP Component</u></span>
 
  
This property is of type ''Panel object'' and can be referenced with the variable name ''NetworkComms1::Component''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
Property to point to the TCP/IP or WIFI component you want to use.
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
If unconnected then default to simulated TCP/IP network communications using the PC network adapter.
+
|-
 
+
|-
<span style="font-weight: normal;"><u>Status</u></span>
+
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus TCP/IP Properties
This property is of type ''Line of text'' and can be referenced with the variable name ''NetworkComms1::Status''.
+
|-
 
+
|-
''<span style="color:red;">No additional information</span>''
+
| width="10%" align="center" | [[File:Fc9-type-17-icon.png]]
 
+
| width="90%" | Network Comms Component
 
+
|-
 
+
| colspan="2" | Redirects communications via the selected component allowing different TCP/IP modules with different macros to work.&nbsp;
<span style="font-weight: normal;"><u>TCP/IP Port</u></span>
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]]
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''Port''.
+
| width="90%" | Status
 
+
|-
Port used for network communications
+
| colspan="2" | Shows the state of the network comms component to verify everything is configured correctly.&nbsp;
 
+
|-
Range: 0-65535
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
+
| width="90%" | TCP/IP Port
<span style="font-weight: normal;"><u>Receive Buffer Size</u></span>
+
|-
 
+
| colspan="2" | Port used for network communications Range: 0-65535&nbsp;
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''ReceiveBufferSize''.
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
Maximum number of bytes the receive buffer can hold
+
| width="90%" | Receive Buffer Size
 
+
|-
<span style="font-weight: normal;"><u>Label</u></span>
+
| colspan="2" | Maximum number of bytes the receive buffer can hold&nbsp;
 
+
|-
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
+
| width="90%" | Receive Timeout
A text label to appear on the Modbus panel object.
+
|-
 +
| colspan="2" | Maximum time to wait for network reply, in mS&nbsp;
 +
|-
 +
| 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="90%" | Label
 +
|-
 +
| colspan="2" | A text label to appear on the Modbus panel object.&nbsp;
 +
|}

Latest revision as of 17:21, 9 November 2022

Author Matrix Ltd.
Version 2.1
Category Comms: System


Modbus TCP Master component

Modbus component for talking to Modbus compatible hardware via Ethernet or WIFI. Ensure TCP/IP or WIFI component is initialised and connected to a network before calling the ModbusMasterTCP component macros.

Component Pack

COMMSC

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.

FC6 Icon.png 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.

FC6 Icon.png Modbus TCP Slave Example


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

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


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-u8-icon.png - BYTE 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


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-u8-icon.png - BYTE SlaveID
The ID of the MODBUS slave - Used for TCP to Serial forwarders 
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


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=SlaveAddress, 1=FunctionCode/ExceptionCode, 2=DataBytes, 3=data0, 4=data1, .. 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png ReadCoils
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


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
3=data0, 5=data1, 7=data2, .. 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png SetHoldingRegisters
This command writes the contents of several analogue output 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


Fc9-comp-macro.png SetHoldingRegister
This command writes the contents of a analogue output 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


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


Fc9-comp-macro.png SetTCPAddress
Sets the address of the remote TCP Slave that we wish to control. 
Fc9-string-icon.png - STRING Address
e.g. "192.168.1.1" 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png ReadDigitalInputs
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



Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png Modbus TCP/IP Properties
Fc9-type-17-icon.png Network Comms Component
Redirects communications via the selected component allowing different TCP/IP modules with different macros to work. 
Fc9-type-10-icon.png Status
Shows the state of the network comms component to verify everything is configured correctly. 
Fc9-type-21-icon.png TCP/IP Port
Port used for network communications Range: 0-65535 
Fc9-type-21-icon.png Receive Buffer Size
Maximum number of bytes the receive buffer can hold 
Fc9-type-21-icon.png Receive Timeout
Maximum time to wait for network reply, in mS 
Fc9-conn-icon.png Simulation Properties
Fc9-type-10-icon.png Label
A text label to appear on the Modbus panel object.