Difference between revisions of "Component: Modbus Slave (Comms: System)"
(XML import) |
|||
Line 7: | Line 7: | ||
|- | |- | ||
| width="20%" style="color: gray;" | Version | | width="20%" style="color: gray;" | Version | ||
− | | | + | | 2.0 (Release) |
|- | |- | ||
| width="20%" style="color: gray;" | Category | | width="20%" style="color: gray;" | Category | ||
Line 19: | Line 19: | ||
==Examples== | ==Examples== | ||
− | |||
Example master program to control the slave. The example reads the 8 switches connected to PortD. If the switch values change then the new value is send to the slave. | Example master program to control the slave. The example reads the 8 switches connected to PortD. If the switch values change then the new value is send to the slave. | ||
− | |||
{{Fcfile|ModBus_Master_Example1.fcfx|Modbus Master Example}} | {{Fcfile|ModBus_Master_Example1.fcfx|Modbus 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-7 state to eight LEDs connected to PortD. | 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-7 state to eight LEDs connected to PortD. | ||
− | |||
{{Fcfile|ModBus_Slave_Example1.fcfx|Modbus Slave Example}} | {{Fcfile|ModBus_Slave_Example1.fcfx|Modbus Slave Example}} | ||
− | |||
− | |||
===Addressing=== | ===Addressing=== | ||
Line 73: | Line 66: | ||
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 170: | Line 162: | ||
:[[Variable Types|BYTE]] ''State'' | :[[Variable Types|BYTE]] ''State'' | ||
::0=off, 1=on | ::0=off, 1=on | ||
+ | |||
+ | |||
+ | '''Return value''' | ||
+ | |||
+ | :''This call does not return a value'' | ||
+ | |||
+ | |||
+ | ===<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 | ||
Line 240: | Line 246: | ||
:[[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 283: | Line 307: | ||
<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 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''. |
− | + | 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> | ||
+ | |||
+ | 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 '' | + | 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>'' | ||
+ | |||
− | |||
<span style="font-weight: normal;"><u>Bus</u></span> | <span style="font-weight: normal;"><u>Bus</u></span> | ||
Line 362: | Line 396: | ||
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 | + | 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. | |
<span style="font-weight: normal;"><u>Starting Address</u></span> | <span style="font-weight: normal;"><u>Starting Address</u></span> |
Revision as of 10:31, 9 May 2018
Author | Matrix Ltd. |
Version | 2.0 (Release) |
Category | Comms: System |
Contents
Modbus Slave component
Modbus component for creating Modbus compatible slave hardware via RS232 or RS485.
Examples
Example master program to control the slave. The example reads the 8 switches connected to PortD. If the switch values change then the new value is send to the slave. Modbus 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-7 state to eight LEDs connected to PortD. Modbus 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
ReadHoldingRegister
Reads the value of a single holding register.
Parameters
- UINT Address
- Coil Address
Return value
ReadCoilStates
Reads the state of a single digital coil.
Can pack a max of 8-bits together in a single operation
Parameters
- UINT StartAddress
- Coil Address Range 0 to (NumCoils - 1)
- BYTE AddressCount
- Range 1-8
Return value
ReadAnalogueInput
Reads the value of a single analogue input.
Parameters
- UINT Address
- Coil Address
Return value
ReadInputStates
Reads the state of a single digital input.
Can pack a max of 8-bits together in a single operation
Parameters
- UINT StartAddress
- Coil Address Range 0 to (NumCoils - 1)
- BYTE AddressCount
- Range 1-8
Return value
SetSlaveAddress
Allows the slave address to be overridden from the default slave address specified
in the component property. The number of bytes used for the address is fixed by the
Slave ID Bytes property to save on RAM usage.
Parameters
- UINT SlaveAddress
Return value
- This call does not return a value
SetCoilState
Sets the state of a single digital coil.
Parameters
- UINT Address
- Coil Address
- BYTE State
- 0=off, 1=on
Return value
- This call does not return a value
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
SetInputState
Sets the state of a single digital input.
Parameters
- UINT Address
- Coil Address
- BYTE State
- 0=off, 1=on
Return value
- This call does not return a value
SetBaudRate
Allows the Baud Rate to be controlled dynamically overriding the default
rate specified by the Baud component property.
Parameters
- BYTE Rate
- 0=1200, 1=2400, 2=4800, 3=9600, 4=19200, 5=38400, 6=57600, 7=115200
Return value
- This call does not return a value
SetHoldingRegister
Sets the state of a single holding register.
Parameters
- UINT Address
- Coil Address
- UINT Value
- Analogue Value range 0 - 65535
Return value
- This call does not return a value
CheckForIncoming
Checks for an incoming message and if the data address is within range then also automatically replies with the correct reply.
Returns 0 if no comms received, 1 for a succesful transaction, 255 for an error.
Parameters
- This macro has no parameters
Return value
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
SetAnalogueInput
Sets the state of a single analogue input.
Parameters
- UINT Address
- Coil Address
- UINT Value
- Analogue Value range 0 - 65535
Return value
- This call does not return a value
Initialise
Starts up the UART to allow communications and initialises the states of the various
Modbus Coils, Inputs and Registers to 0.
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.
Timeout
This property is of type Unsigned integer and can be referenced with the variable name Timeout.
Timeout in milliseconds used to dictate the maximum time to wait in milliseconds between bytes in a packet.
Range: 1 - 255
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
Slave Address
This property is of type Unsigned integer and can be referenced with the variable name SlaveAddress.
No additional information
Reply Delay
This property is of type Unsigned integer and can be referenced with the variable name ReplyDelay.
Delay in micro seconds to wait before transmitting a reply
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.
Starting Address
This property is of type Unsigned integer and can be referenced with the variable name StartAdrCoil.
Start address of the Modbus coils. Referenced from 0.
For example
Slave 1 might have 100 coils addressed 0-99 Start Address = 0
Slave 2 might have 100 coils addressed 100-199 Start Address = 100
Number of Addresses
This property is of type Unsigned integer and can be referenced with the variable name NumAdrCoil.
Specifies how many Coils are available on the slave.
Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte.
Starting Address
This property is of type Unsigned integer and can be referenced with the variable name StartAdrDI.
Start address of the Modbus digital inputs. Referenced from 0.
For example
Slave 1 might have 100 inputs addressed 0-99 Start Address = 0
Slave 2 might have 100 inputs addressed 100-199 Start Address = 100
Number of Addresses
This property is of type Unsigned integer and can be referenced with the variable name NumAdrDI.
Specifies how many Digital Inputs are available on the slave.
Each address consumes a single bit of RAM, 8 Addresses are packed together into a single RAM Byte.
Starting Address
This property is of type Unsigned integer and can be referenced with the variable name StartAdrAI.
Start address of the Modbus analogue inputs. Referenced from 0.
For example
Slave 1 might have 100 inputs addressed 0-99 Start Address = 0
Slave 2 might have 100 inputs addressed 100-199 Start Address = 100
Number of Addresses
This property is of type Unsigned integer and can be referenced with the variable name NumAdrAI.
Specifies how many 16-bit analogue inputs are available on the slave.
Each address consumes two RAM Bytes.
Starting Address
This property is of type Unsigned integer and can be referenced with the variable name StartAdrReg.
Start address of the Modbus registers. Referenced from 0.
For example
Slave 1 might have 100 registers addressed 0-99 Start Address = 0
Slave 2 might have 100 registers addressed 100-199 Start Address = 100
Number of Addresses
This property is of type Unsigned integer and can be referenced with the variable name NumAdrReg.
Specifies how many 16-bit holding registers are available on the slave.
Each address consumes two RAM Bytes.