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

From Flowcode Help
Jump to navigationJump to search
(XML import)
 
Line 19: Line 19:
  
 
==Examples==
 
==Examples==
''<span style="color:red;">No additional examples</span>''
+
 
 +
Example to talk to a CT-2EA Modbus Electronic kWh Meter
 +
{{Fcfile|ModbusDemo.fcfx|ModbusDemo}}
 +
Setup to communicate via Embedded UART1 or Simulated COM3
 +
 
 +
[[File:ModbusConns.jpg]]
 +
 
 +
 
 +
Console data generated by the working example
 +
 
 +
[[File:ModbusConsole.jpg]]
 +
 
  
  

Revision as of 09:10, 28 July 2016


Author Matrix Ltd.
Version 1.2 (Release)
Category Comms: System


Image Modbus Master component

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

Examples

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

ModbusConsole.jpg


Downloadable macro reference

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.

Parameters

UINT SlaveID
The ID of the MODBUS slave
UINT RegAddress
Address: 0=40001, 1=40002, ...
UINT RegCount
Number of consecutive registers to read, starting from RegAddress


Return value

BYTE


ForceSingleCoil

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.

Parameters

UINT SlaveID
The ID of the MODBUS slave
UINT CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...
BYTE CoilState
0=Off, 1=On


Return value

BYTE


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

Parameters

This macro has no parameters


Return value

BYTE


ReadCoilStatus

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.

Parameters

UINT SlaveID
The ID of the MODBUS slave
UINT CoilAddress
Coil Address: 0=Coil1, 1=Coil2, 2=Coil3, ...
UINT CoilCount
Number of consecutive coils to try and read


Return value

BYTE


GetResponseByte

Reads a byte from the last received response. The Index parametes specifies which byte to read back.

Parameters

BYTE Index
0=NumBytes, 1=SlaveAddress, 2=FunctionCode/ExceptionCode, .....


Return value

BYTE


ReadInputStatus

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.

Parameters

UINT SlaveID
The ID of the MODBUS slave
UINT DataAddress
Input Address: 0=10001, 1=10002, 2=10003, ...
UINT DataCount
Number of consecutive inputs to read, starting from RegAddress


Return value

BYTE


PresetSingleRegister

This command writes the contents of a analogue output holding registerl at the location RegAddress.

Returns 0 for success, 1 for CRC fail and 255 for no reply.

Parameters

UINT SlaveID
The ID of the MODBUS slave
UINT RegAddress
Address: 0=40001, 1=40002, ...
UINT RegValue
Value to send to the selected register


Return value

BYTE


ReadInputRegister

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

UINT SlaveID
The ID of the MODBUS slave
UINT RegAddress
Input Address: 0=10001, 1=10002, 2=10003, ...
UINT RegCount
Number of consecutive inputs to read, starting from RegAddress


Return value

BYTE


PresetMultipleRegisters

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

UINT SlaveID
The ID of the MODBUS slave
UINT RegAddress
Address: 0=40001, 1=40002, ...
UINT RegCount
Number of consecutive registers to write, starting from RegAddress
UINT RegValue
Array of values to send to the registers


Return value

BYTE


Initialise

Starts up the UART to allow communications

Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Channel

This property is of type Fixed list of ints and can be referenced with the variable name CHANNEL.

UART channel to specify a software channel or an onboard hardware channel

TX

This property is of type Single digital pin and can be referenced with the variable name TX.

UART transmit pin

RX

This property is of type Single digital pin and can be referenced with the variable name RX.

UART receive pin

Baud Rate

This property is of type Fixed list of ints and can be referenced with the variable name BAUD_LIST.

Data rate in bits per second

Bus

This property is of type Fixed list of ints and can be referenced with the variable name BusType.

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.

Frame Type

This property is of type Fixed list of ints and can be referenced with the variable name FrameType.

Switches between RTU and ASCII forms of Modbus

Receive Buffer Size

This property is of type Unsigned integer and can be referenced with the variable name ReceiveBufferSize.

Maximum number of bytes the receive buffer can hold

Slave ID Bytes

This property is of type Unsigned integer and can be referenced with the variable name AddressBytes.

Number of bytes used when passing a slave ID, usually 1 but sometimes 2

Label

This property is of type Line of text and can be referenced with the variable name label.

A text label to appear on the Modbus panel object.

Data Source

This property is of type Fixed list of ints and can be referenced with the variable name DataSource.

Simulation data source used to allow the component to connect to COM port hardware or the the data injector components.

COM Port

This property is of type Fixed list of ints and can be referenced with the variable name COM_port.

COM port assigned to allow the simulation to communicate with actual Modbus hardware.