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

From Flowcode Help
Jump to navigationJump to search
(XML import)
Line 7: Line 7:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 1.3 (Release)
+
| 2.0 (Release)
 
|-
 
|-
 
| width="20%" style="color: gray;" | Category
 
| width="20%" style="color: gray;" | Category
Line 74: Line 74:
  
 
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==
 
==Downloadable macro reference==
Line 218: Line 217:
  
 
:[[Variable Types|BYTE]]
 
:[[Variable Types|BYTE]]
 +
 +
 +
===<span style="font-weight: normal;"><u><tt>ChangeFrameType</tt></u></span>===
 +
Default frame type is the type set in the component properties.
 +
 +
'''Parameters'''
 +
 +
:[[Variable Types|BYTE]] ''Type''
 +
::0 = Modbus RTU / 1 = Modbus ASCII
 +
 +
 +
'''Return value'''
 +
 +
:''This call does not return a value''
  
  
Line 287: Line 300:
  
 
:[[Variable Types|BYTE]]
 
:[[Variable Types|BYTE]]
 +
 +
 +
===<span style="font-weight: normal;"><u><tt>ChangeBaud</tt></u></span>===
 +
Changes the UART Baud rate.
 +
 +
1 = 1200 / 2 = 2400 / 3 = 4800 / 4 = 9600 / 5 = 19200 / 6 = 31250
 +
 +
7 = 38400 / 8 = 57600 / 9 = 115200
 +
 +
'''Parameters'''
 +
 +
:[[Variable Types|BYTE]] ''Baud''
 +
::The new baud rate (0=1200, 9=115200)
 +
 +
 +
'''Return value'''
 +
 +
:''This call does not return a value''
  
  
Line 311: Line 342:
 
<span style="font-weight: normal;"><u>Channel</u></span>
 
<span style="font-weight: normal;"><u>Channel</u></span>
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''CHANNEL''.
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::CHANNEL''.
  
UART channel to specify a software channel or an onboard hardware 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.
  
 
<span style="font-weight: normal;"><u>TX</u></span>
 
<span style="font-weight: normal;"><u>TX</u></span>
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''TX''.
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_uart::TX''.
  
UART transmit pin
+
Pin to be used for Transmit data
  
 
<span style="font-weight: normal;"><u>RX</u></span>
 
<span style="font-weight: normal;"><u>RX</u></span>
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''RX''.
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_uart::RX''.
 +
 
 +
Pin to be used for Receive data
 +
 
 +
<span style="font-weight: normal;"><u>Baud Options</u></span>
  
UART receive pin
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::BAUD_LIST''.
 +
 
 +
Baud rate option selector
  
 
<span style="font-weight: normal;"><u>Baud Rate</u></span>
 
<span style="font-weight: normal;"><u>Baud Rate</u></span>
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''BAUD_LIST''.
+
This property is of type ''Signed integer'' and can be referenced with the variable name ''cal_uart::BAUD''.
 +
 
 +
''<span style="color:red;">No additional information</span>''
 +
 
  
Data rate in bits per second
 
  
 
<span style="font-weight: normal;"><u>Bus</u></span>
 
<span style="font-weight: normal;"><u>Bus</u></span>
Line 410: Line 453:
  
 
A text label to appear on the Modbus panel object.
 
A text label to appear on the Modbus panel object.
 +
 +
<span style="font-weight: normal;"><u>Scope Traces</u></span>
 +
 +
This property is of type ''True or false'' and can be referenced with the variable name ''cal_uart::ScopeTraces''.
 +
 +
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.
 +
 +
<span style="font-weight: normal;"><u>Console Data</u></span>
 +
 +
This property is of type ''True or false'' and can be referenced with the variable name ''cal_uart::ConsoleData''.
 +
 +
Selects if the console data is automatically generated or not
 +
 +
<span style="font-weight: normal;"><u>Console Columns</u></span>
 +
 +
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''cal_uart::ConsoleColumns''.
 +
 +
Number of characters that can be displayed on a single line of the console.
  
 
<span style="font-weight: normal;"><u>Data Source</u></span>
 
<span style="font-weight: normal;"><u>Data Source</u></span>
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''DataSource''.
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_uart::DataSource''.
  
Simulation data source used to allow the component to connect to COM port hardware or the the data injector components.
+
Simulation data source used to allow the component to connect to various remote devices
  
<span style="font-weight: normal;"><u>COM Port</u></span>
+
    Nothing - Simulation data is ignored
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''COM_port''.
+
    COM port - Routes the communication data to and from a physical or virtual COM port
  
COM port assigned to allow the simulation to communicate with actual Modbus hardware.
+
    Injector - Routes the communication data via a data injector component on the Panel.

Revision as of 10:31, 9 May 2018


Author Matrix Ltd.
Version 2.0 (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 running in the simulation and communicating via the COM port.

ModbusConsole.jpg


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

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


ForceMultipleCoils

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

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
BYTE CoilData
An array of bytes each containing 8 1-bit coil values


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


ChangeFrameType

Default frame type is the type set in the component properties.

Parameters

BYTE Type
0 = Modbus RTU / 1 = Modbus ASCII


Return value

This call does not return a value


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


ChangeBaud

Changes the UART Baud rate.

1 = 1200 / 2 = 2400 / 3 = 4800 / 4 = 9600 / 5 = 19200 / 6 = 31250

7 = 38400 / 8 = 57600 / 9 = 115200

Parameters

BYTE Baud
The new baud rate (0=1200, 9=115200)


Return value

This call does not return a value


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 cal_uart::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.

TX

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

Pin to be used for Transmit data

RX

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

Pin to be used for Receive data

Baud Options

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

Baud rate option selector

Baud Rate

This property is of type Signed integer and can be referenced with the variable name cal_uart::BAUD.

No additional information


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

Silent Interval

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

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

UART Receive Timeout

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

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

Receive Timeout Count

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

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

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.

Scope Traces

This property is of type True or false and can be referenced with the variable name cal_uart::ScopeTraces.

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.

Console Data

This property is of type True or false and can be referenced with the variable name cal_uart::ConsoleData.

Selects if the console data is automatically generated or not

Console Columns

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

Number of characters that can be displayed on a single line of the console.

Data Source

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

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 
   Injector - Routes the communication data via a data injector component on the Panel.