Difference between revisions of "Component: Modbus Slave USB (Comms: System)"
Line 15: | Line 15: | ||
Modbus component for creating Modbus compatible slave hardware via USB Serial. | Modbus component for creating Modbus compatible slave hardware via USB Serial. | ||
− | ==Component | + | ==Component Source Code== |
− | + | Please click here for the component source code: [https://www.flowcode.co.uk/wikicopy/componentsource/FC_Comp_Source_ModbusSlaveUSB.fcfx FC_Comp_Source_ModbusSlaveUSB.fcfx] | |
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
Line 40: | Line 42: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
Line 378: | Line 382: | ||
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | USB Properties | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | USB Properties | ||
|- | |- | ||
|- | |- | ||
Line 419: | Line 431: | ||
|- | |- | ||
| colspan="2" | Specifies if the enumeration (Initialise function) can timeout if taking too long. | | colspan="2" | Specifies if the enumeration (Initialise function) can timeout if taking too long. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | USB Driver | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-20-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-20-icon.png]] | ||
Line 434: | Line 450: | ||
|- | |- | ||
| colspan="2" | Generates a driver file when set to Yes, Automatically jumps back to No when complete. | | colspan="2" | Generates a driver file when set to Yes, Automatically jumps back to No when complete. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus Properties | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 469: | Line 489: | ||
|- | |- | ||
| colspan="2" | Controls if the last command from the master is logged allowing for easier value updates. No - Do not log commands Yes - Commands are logged and available via the GetLastIncoming macro | | colspan="2" | Controls if the last command from the master is logged allowing for easier value updates. No - Do not log commands Yes - Commands are logged and available via the GetLastIncoming macro | ||
+ | |- | ||
+ | | 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="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
Line 479: | Line 503: | ||
|- | |- | ||
| colspan="2" | Hardware COM port to communicate with any connected USB serial devices or any other virtual COM ports. | | colspan="2" | Hardware COM port to communicate with any connected USB serial devices or any other virtual COM ports. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Modbus Coils - Single bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 489: | Line 517: | ||
|- | |- | ||
| colspan="2" | 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. | | colspan="2" | 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. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Digital Inputs - Single bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 499: | Line 531: | ||
|- | |- | ||
| colspan="2" | 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. | | colspan="2" | 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. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Analog Inputs - 16-bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 509: | Line 545: | ||
|- | |- | ||
| colspan="2" | Specifies how many 16-bit analogue inputs are available on the slave. Each address consumes two RAM Bytes. | | colspan="2" | Specifies how many 16-bit analogue inputs are available on the slave. Each address consumes two RAM Bytes. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Holding Registers - 16-bit values | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
Line 519: | Line 559: | ||
|- | |- | ||
| colspan="2" | Specifies how many 16-bit holding registers are available on the slave. Each address consumes two RAM Bytes. | | colspan="2" | Specifies how many 16-bit holding registers are available on the slave. Each address consumes two RAM Bytes. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} |
Revision as of 17:49, 9 November 2022
Author | Matrix Ltd. |
Version | 2.0 |
Category | Comms: System |
Contents
Modbus Slave USB component
Modbus component for creating Modbus compatible slave hardware via USB Serial.
Component Source Code
Please click here for the component source code: FC_Comp_Source_ModbusSlaveUSB.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.
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.
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. | |
![]() |
Address |
Coil Address | |
![]() |
Return |
![]() |
SetCoil |
Sets the state of a single digital coil. | |
![]() |
Address |
Coil Address | |
![]() |
State |
0=off, 1=on | |
![]() |
Return |
![]() |
SetDigitalInput |
Sets the state of a single digital input. | |
![]() |
Address |
Coil Address | |
![]() |
State |
0=off, 1=on | |
![]() |
Return |
![]() |
ChangeFrameType |
Default frame type is the type set in the component properties. | |
![]() |
Type |
0 = Modbus RTU / 1 = Modbus ASCII | |
![]() |
Return |
![]() |
SetHoldingRegister |
Sets the state of a single holding register. | |
![]() |
Address |
Coil Address | |
![]() |
Value |
Analogue Value range 0 - 65535 | |
![]() |
Return |
![]() |
ReadAnalogInput |
Reads the value of a single analogue input. | |
![]() |
Address |
Coil Address | |
![]() |
Return |
![]() |
SetAnalogInput |
Sets the state of a single analogue input. | |
![]() |
Address |
Coil Address | |
![]() |
Value |
Analogue Value range 0 - 65535 | |
![]() |
Return |
![]() |
Initialise |
Starts up the UART to allow communications and initialises the states of the various Modbus Coils, Inputs and Registers to 0. Returns 1 if USB is started ok. | |
![]() |
Return |