User Tools

Site Tools


custom_protocols

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
custom_protocols [2019/01/09 12:35] – [The examples of custom protocols] emozolyakcustom_protocols [2020/02/07 12:50] – [readRegister] emozolyak
Line 93: Line 93:
 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:+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. +  *internalAddr - Recalculated register address. This number is recalculated from the specified number system with shift added to it. 
-addr - The original address of the register that the user entered. +  *addr - The original address of the register that the user entered. 
-dataType – The type of data that the user specified for the register. 0 = Bit, 1 = Byte, 2 = Word, 3 = Double Word, 4 = UnixTime +  *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:+There are such attributes in the __device__ structure:
  
-shift - The shift value from the corresponding row in createDevices +  *shift - The shift value from the corresponding row in createDevices 
-base - base 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+  *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.
  
-Для передачи запроса устройству используются функции sendBytes и sendString. Для чтения ответа - readBytesreadString.+To send a request to the device //sendBytes// and //sendString// are usedTo read the reply //readBytes// and //readString// respectivelyTheir overview is given in the following table:
  
-На вход sendBytes принимает таблицу (массивбайт. Результатом будет true в случае успеха и false в случае ошибки.  +^ Function ^ Arguments ^ Returns ^ 
-На вход sendString принимает строку. Результатом будет true в случае успеха и false в случае ошибки.  +|sendBytes  |table | true/false (success execution or no| 
-На вход readBytes принимает количество байт, которое необходимо прочитать. Результатом будет таблица (массивбайт в случае успеха и false в случае ошибки. +|sendString |string| same | 
-На вход readString принимает количество байт, которое необходимо прочитать. Результатом будет строка в случае успеха и false в случае ошибки. +|readBytes  |number (of bytes to read)| table of bytes or false for error | 
-Если необходимо закрыть соединение (например, в случае множественных ошибок), то можно вызвать процедуру closeConnection.+|readString |number (of chars to read)| string  or false for error |
  
-Если необходимо сделать паузу, то можно вызвать функцию sleep. Ее единственным аргументом должно быть время в микросекундах. Пример: sleep(20000); - произойдет пауза 20 миллисекунд.+To close connection (in case of many errors), //closeConnection// function can be used.
  
-Для работы с битами можно использовать библиотеку bitop [4].+To make a delay, //sleep// function can be used. Its only argument is time in microseconds, e.g. sleep(20000) will make a pause for 20 ms.
  
-Для отладки и вывода диагностических сообщений можно использовать процедуры ERROR, INFO, DEBUG и TRACE которые доступны и в обычных сценариях Lua [5].+For bit processing refer to bitop library and this [[useful_programs#bit_functions | link]]. 
  
-Что бы лучше понять как это все работает давайте рассмотрим пример функции readRegister для протокола ModBus TCP:+For debugging and diagnostic messages you can use ERROR, INFO, DEBUG or TRACE from the users Lua scripts - see [[write_to_logs | this]].  
 + 
 +To better understand the custom protocol application, let's examine the readRegister function for the ModBus TCP protocol:
  
 <code lua> <code lua>
custom_protocols.txt · Last modified: 2023/02/21 17:52 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki