helvar
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
helvar [2023/05/20 21:12] – emozolyak | helvar [2023/09/22 14:33] (current) – emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Helvar light control | + | ====== Helvar light control |
Please refer to the [[https:// | Please refer to the [[https:// | ||
Line 16: | Line 16: | ||
The usage of this protocol is as follows: | The usage of this protocol is as follows: | ||
- | | + | |
- | | + | |
+ | <WRAP center round important 80%> | ||
+ | Please be informed this protocol relays your HelvarNet string to the TCP address: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round box 80%> | ||
+ | For example, in the command Recall Group 1234, Block 5, Scene 6, Fade Time 32 s, the string is | ||
+ | sent as follows, including the delimiters and the start character '>' | ||
+ | "> | ||
+ | </ | ||
+ | |||
+ | *So the string like "> | ||
+ | *Once the string is written to the CMD0 register, it is sent to the remote device to the TCP port assigned in the connection settings. | ||
+ | *The response (which can be multipart) is stored in the same register | ||
Line 26: | Line 39: | ||
PARTIAL_ETX = ' | PARTIAL_ETX = ' | ||
FULL_ETX | FULL_ETX | ||
+ | |||
function onScanStart () | function onScanStart () | ||
now = os.time() | now = os.time() | ||
Line 34: | Line 47: | ||
| | ||
end | end | ||
+ | |||
function readRegister (reg, device, unitId) | function readRegister (reg, device, unitId) | ||
- | |||
if (not readBuffer) then | if (not readBuffer) then | ||
readBuffer = 'no data' | readBuffer = 'no data' | ||
end | end | ||
- | | + | return readBuffer |
- | | + | |
end | end | ||
+ | |||
function writeRegister (reg, device, unitId, newValue) | function writeRegister (reg, device, unitId, newValue) | ||
- | | + | |
- | sendString_(newValue) -- expects string to be written externally | + | |
- | + | ||
local buf = {} | local buf = {} | ||
+ | local tryCount = 0 | ||
| | ||
+ | | ||
+ | |||
local currentFrame = readUntil(PARTIAL_ETX, | local currentFrame = readUntil(PARTIAL_ETX, | ||
- | local lastChar | ||
if currentFrame then | if currentFrame then | ||
| | ||
| | ||
| | ||
- | + | | |
- | until (not lastChar or (lastChar == FULL_ETX)) | + | |
- | if (#buf > 0) then | + | |
- | readBuffer = table.concat(buf) | + | readBuffer = buf |
- | | + | |
- | + | | |
- | | + | |
+ | | ||
+ | | ||
end | end | ||
+ | |||
-------------------------- Helpers -------------------------- | -------------------------- Helpers -------------------------- | ||
+ | |||
function sendString_(s) -- new sendString version | function sendString_(s) -- new sendString version | ||
+ | |||
local sendBuf = {} | local sendBuf = {} | ||
Line 78: | Line 92: | ||
sendBytes(sendBuf) | sendBytes(sendBuf) | ||
end | end | ||
+ | |||
function readUntil(endByte1, | function readUntil(endByte1, | ||
+ | DEBUG(" | ||
+ | | ||
local ONE_BYTE = 1 | local ONE_BYTE = 1 | ||
- | local buf = {} | + | local buf, rb = {}, nil |
+ | | ||
repeat | repeat | ||
- | | + | rb = readBytes(ONE_BYTE) |
if rb then | if rb then | ||
- | rb = rb[ONE_BYTE] | + | rb = rb[ONE_BYTE] |
table.insert(buf, | table.insert(buf, | ||
end | end | ||
until (not rb or (rb == endByte1 or rb == endByte2)) | until (not rb or (rb == endByte1 or rb == endByte2)) | ||
- | + | | |
- | | + | |
+ | DEBUG(' | ||
+ | |||
+ | if (#buf > 0) and (buf[#buf] == endByte1 | ||
+ | DEBUG(' | ||
+ | else | ||
+ | DEBUG(' | ||
+ | end | ||
end | end | ||
</ | </ | ||
helvar.txt · Last modified: 2023/09/22 14:33 by emozolyak