Component: Modbus TCP Master (Comms: System)

From Flowcode Help
Revision as of 13:12, 7 February 2023 by Wiki bot (talk | contribs)
Jump to navigationJump to search
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 Source Code

Please click here to download the component source project: FC_Comp_Source_ModbusTCP.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_ModbusTCP.fcfx

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.







Macro reference

GetResponseByte

Error creating thumbnail: Unable to save thumbnail to destination
GetResponseByte
Reads a byte from the last received response. The Index parametes specifies which byte to read back.  
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Index
0=SlaveAddress, 1=FunctionCode/ExceptionCode, 2=DataBytes, 3=data0, 4=data1, .. 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


GetResponseInt

Error creating thumbnail: Unable to save thumbnail to destination
GetResponseInt
Reads a 16-bit value from the last received response. The Index parametes specifies the byte index of the value to read back.  
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Index
3=data0, 5=data1, 7=data2, .. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
Return


ReadAnalogInput

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegAddress
Input Address: 0=10001, 1=10002, 2=10003, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegCount
Number of consecutive inputs to read, starting from RegAddress 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


ReadCoils

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
CoilCount
Number of consecutive coils to try and read 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


ReadDigitalInputs

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
DataAddress
Input Address: 0=10001, 1=10002, 2=10003, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
DataCount
Number of consecutive inputs to read, starting from RegAddress 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


ReadHoldingRegister

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegAddress
Address: 0=40001, 1=40002, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegCount
Number of consecutive registers to read, starting from RegAddress 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


SetCoil

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
CoilState
0=Off, 1=On 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


SetCoils

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
SlaveID
The ID of the MODBUS slave - Used for TCP to Serial forwarders 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
CoilCount
Number of consecutive coils to try and read 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
CoilData
An array of bytes each containing 8 1-bit coil values 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


SetHoldingRegister

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegAddress
Address: 0=40001, 1=40002, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegValue
Value to send to the selected register 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


SetHoldingRegisters

Error creating thumbnail: Unable to save thumbnail to destination
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. 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
SlaveID
The ID of the MODBUS slave 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegAddress
Address: 0=40001, 1=40002, ... 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegCount
Number of consecutive registers to write, starting from RegAddress 
Error creating thumbnail: Unable to save thumbnail to destination
- UINT
RegValue
Array of values to send to the registers 
Error creating thumbnail: Unable to save thumbnail to destination
- BYTE
Return


SetTCPAddress

Error creating thumbnail: Unable to save thumbnail to destination
SetTCPAddress
Sets the address of the remote TCP Slave that we wish to control. 
Error creating thumbnail: Unable to save thumbnail to destination
- STRING
Address
e.g. "192.168.1.1" 
Error creating thumbnail: Unable to save thumbnail to destination
- VOID
Return


Property reference

Error creating thumbnail: Unable to save thumbnail to destination
Properties
Error creating thumbnail: Unable to save thumbnail to destination
Modbus TCP/IP Properties
Error creating thumbnail: Unable to save thumbnail to destination
LinkTo
 
Error creating thumbnail: Unable to save thumbnail to destination
Status
Shows the state of the network comms component to verify everything is configured correctly. 
Error creating thumbnail: Unable to save thumbnail to destination
TCP/IP Port
Port used for network communications Range: 0-65535 
Error creating thumbnail: Unable to save thumbnail to destination
Receive Buffer Size
Maximum number of bytes the receive buffer can hold 
Error creating thumbnail: Unable to save thumbnail to destination
Receive Timeout
Maximum time to wait for network reply, in mS 
Error creating thumbnail: Unable to save thumbnail to destination
Simulation Properties
Error creating thumbnail: Unable to save thumbnail to destination
Label
A text label to appear on the Modbus panel object.