custom_protocols
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
custom_protocols [2020/01/02 10:56] – [readRegister] emozolyak | custom_protocols [2022/10/18 13:58] – atolstov | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{ network: | ||
====== Custom protocols ====== | ====== Custom protocols ====== | ||
- | There are a lot of different automation devices with non-standard communication protocols. To solve the problem of data collection from such devices in WebHMI, it is possible | + | There are a lot of different automation devices with non-standard communication protocols. To solve the problem of data collection from such devices in WebHMI, it is possireble |
===== About Lua ===== | ===== About Lua ===== | ||
Line 21: | Line 22: | ||
To go to the list of user protocols, click on the button " | To go to the list of user protocols, click on the button " | ||
- | {{ :: | + | {{ network: |
You will be taken to the protocol management page. In this example, we see two demonstration protocols - ModBus TCP Demo and ModBus ASCII Demo: | You will be taken to the protocol management page. In this example, we see two demonstration protocols - ModBus TCP Demo and ModBus ASCII Demo: | ||
- | {{ :: | + | {{ network: |
Let's look at the page for editing the ModBus TCP Demo protocol: | Let's look at the page for editing the ModBus TCP Demo protocol: | ||
Line 40: | Line 41: | ||
The regular expression must ensure that the register address is validated on the register editing page (when this protocol is selected). Example: | The regular expression must ensure that the register address is validated on the register editing page (when this protocol is selected). Example: | ||
- | {{ :: | + | {{ network: |
We also see a convenient code editor. It supports formatting, highlighting and validation of syntax. So it's convenient to write the code | We also see a convenient code editor. It supports formatting, highlighting and validation of syntax. So it's convenient to write the code | ||
If there is a syntax error in the code, a red X appears in the corresponding line. To see a detailed error message, just point your mouse at it: | If there is a syntax error in the code, a red X appears in the corresponding line. To see a detailed error message, just point your mouse at it: | ||
- | {{:: | + | {{ |
After creating the protocol, it will appear in the drop-down list of available PLC models on the page of creating newConnections and with it you can work as well as with the usual built-in protocol: | After creating the protocol, it will appear in the drop-down list of available PLC models on the page of creating newConnections and with it you can work as well as with the usual built-in protocol: | ||
- | {{ : | + | {{ network: |
===== Necessary functions ===== | ===== Necessary functions ===== | ||
Line 89: | Line 90: | ||
The function readRegister should read the specified register. | The function readRegister should read the specified register. | ||
- | In case of successful reading, the function readRegister should return an array of bytes, with length corresponding to the specified data type (1, 2 or 4) or the number. In case of failure, you must return false. | + | In case of successful reading, the function readRegister should return an //(lua table)// **array of bytes, with length corresponding to the specified data type** (1, 2 or 4) or the number. In case of failure, you must return |
Three parameters are passed to it as arguments: | Three parameters are passed to it as arguments: | ||
- | reg - Table (structure) with register parameters | + | ***reg** - Table (structure) with register parameters |
- | device - Table (structure) with register type parameters (that were defined in createDevices) | + | ***device** - Table (structure) with register type parameters (that were defined in createDevices) |
- | unitId – device ID for the bus or other ID. For instance, Slave ID in ModBus RTU or Unit ID in ModBus TCP. | + | ***unitId** – device ID for the bus or other ID. For instance, Slave ID in ModBus RTU or Unit ID in ModBus TCP. |
- | There are such attributes in the reg structure: | + | |
- | internalAddr - Recalculated register address. This number is recalculated from the specified number system with shift added to it. | + | === Attributes |
- | addr - The original address | + | |
- | dataType – The type of data that the user specified for the register. 0 = Bit, 1 = Byte, 2 = Word, 3 = Double Word, 4 = UnixTime | + | |
- | There are such attributes in the device structure: | + | |
- | shift - The shift value from the corresponding row in createDevices | + | *internalAddr - Recalculated register address. This number is recalculated from the specified number system with shift added to it. |
- | base - base value from the corresponding row in createDevices | + | *addr - The original address of the register that the user entered. |
- | xtraFields – xtraFields value from the corresponing row in createDevices | + | *dataType – The type of data that the user specified for the register. 0 = Bit, 1 = Byte, 2 = Word, 3 = Double Word, 4 = UnixTime |
+ | |||
+ | === Attributes of the DEVICE structure === | ||
+ | |||
+ | *shift - The shift value from the corresponding row in createDevices | ||
+ | *base - base value from the corresponding row in createDevices | ||
+ | *xtraFields – xtraFields value from the corresponing row in createDevices | ||
These parameters are passed in order to be able to correctly and fully compose a request according to the protocol. | These parameters are passed in order to be able to correctly and fully compose a request according to the protocol. | ||
Line 446: | Line 449: | ||
As an example we've made (partually) several protocols: | As an example we've made (partually) several protocols: | ||
- | *[[http:// | + | *[[modbus_tcp_custom|ModBus TCP]] |
- | *[[http:// | + | *[[modbus_ascii_custom|ModBus ASCII]] |
- | *[[http:// | + | *[[modbus_rtu_custom|Modbus RTU]]. |
+ | *[[http_get_custom | HTTP request example]] | ||
*Other devices that were connected using [[http:// | *Other devices that were connected using [[http:// | ||
custom_protocols.txt · Last modified: 2023/02/21 17:52 by emozolyak