hydrus-flowmeter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
hydrus-flowmeter [2023/08/17 11:03] – emozolyak | hydrus-flowmeter [2024/02/20 14:40] – [Connecting to DIEHL HYDRUS flowmeter] emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
{{ : | {{ : | ||
- | ====== Connecting to HYDRUS by DIEHL flowmeter | + | ====== Connecting to DIEHL HYDRUS |
<WRAP center round info 80%> | <WRAP center round info 80%> | ||
Line 16: | Line 16: | ||
end | end | ||
- | POLL_DELAY | + | POLL_DELAY |
HEX_NUMBERING = 16 -- numbering system conversion | HEX_NUMBERING = 16 -- numbering system conversion | ||
Line 35: | Line 35: | ||
end | end | ||
end | end | ||
+ | -- prints any parameters | ||
function DBG(...) | function DBG(...) | ||
for i = 1, #arg do | for i = 1, #arg do | ||
Line 48: | Line 48: | ||
------ Table helpers ----------------------------- | ------ Table helpers ----------------------------- | ||
- | function table.findPattern(t, | + | function table.findPattern(t, |
for tabIndex, _ in ipairs(t) do | for tabIndex, _ in ipairs(t) do | ||
Line 60: | Line 60: | ||
end | end | ||
end | end | ||
- | |||
if matchFlag then | if matchFlag then | ||
- | return (tabIndex + # | + | return (tabIndex + # |
end | end | ||
end | end | ||
Line 68: | Line 67: | ||
end | end | ||
- | function table.sub(t, | + | function table.sub(t, |
local tmpTable = {} | local tmpTable = {} | ||
for k = startIndex, endIndex do | for k = startIndex, endIndex do | ||
Line 76: | Line 75: | ||
end | end | ||
- | table.hexView = function(hextab, | + | table.hexView = function(hextab, |
local hex = {} | local hex = {} | ||
for _, hexbyte in ipairs(hextab) do | for _, hexbyte in ipairs(hextab) do | ||
Line 89: | Line 88: | ||
return tonumber(hex) | return tonumber(hex) | ||
end | end | ||
+ | -- integer convertions | ||
+ | table.int = function(t) | ||
+ | | ||
+ | end | ||
+ | |||
- | function getHexByteAsStr(inputByte) | + | -- gets 2 - char hex string of a byte |
+ | function getHexByteAsStr(inputByte) | ||
local strByte = string.format(" | local strByte = string.format(" | ||
return (#strByte == 1 and ' | return (#strByte == 1 and ' | ||
end | end | ||
- | table.reverse = function (tab) -- reverses a table | + | table.reverse = function (tab) |
local outTable = {} | local outTable = {} | ||
for i = #tab, 1, -1 do | for i = #tab, 1, -1 do | ||
Line 110: | Line 115: | ||
CTRL_LONG_FRAME_STX = 0x68 | CTRL_LONG_FRAME_STX = 0x68 | ||
- | REQ_UD2 | + | REQ_UD2 |
- | REQ_UD2_ | + | REQ_UD2_ |
BRDCAST_NET_LAYER_ADDR = 0xFD -- 253 | BRDCAST_NET_LAYER_ADDR = 0xFD -- 253 | ||
Line 127: | Line 132: | ||
dataHandlers = { | dataHandlers = { | ||
- | volume = {pattern = {0xC, 0x14}, length = 4, func = table.bcd}, | + | volume = {pattern = {0xC, 0x14}, |
- | flow = {pattern = {0xB, 0x3C}, length = 3, func = table.bcd}, | + | flow = {pattern = {0xB, 0x3C}, |
- | tint = {pattern = {0xA, 0x5A}, length = 2, func = table.bcd}, | + | tint = {pattern = {0xA, 0x5A}, |
- | text = {pattern = {0xA, 0x66}, length = 2, func = table.bcd}, | + | text = {pattern = {0xA, 0x66}, |
- | err | + | err |
- | | + | |
- | | + | |
- | return tonumber(table.hexView(d), HEX_NUMBERING) | + | |
- | end}, -- int32 convertion | + | |
} | } | ||
Line 178: | Line 179: | ||
else | else | ||
ERROR(" | ERROR(" | ||
- | data = false | + | data[param] |
end | end | ||
end | end | ||
Line 200: | Line 201: | ||
-------------------------- Other helpers -------------------------- | -------------------------- Other helpers -------------------------- | ||
- | function readUntil(endByte) | + | function readUntil(endByte) |
- | local ONE_BYTE = 1 | + | local ONE_BYTE, buf = 1, {} |
- | | + | |
repeat | repeat | ||
local rx = readBytes(ONE_BYTE) | local rx = readBytes(ONE_BYTE) | ||
if rx then | if rx then | ||
- | rx = rx[1] | + | rx = rx[1] ; table.insert(buf, |
- | | + | |
end | end | ||
until (not rx or (rx == endByte)) | until (not rx or (rx == endByte)) | ||
Line 214: | Line 214: | ||
end | end | ||
- | function getCRC(a, pos, len) -- calc. CRC sum for the mbus packet | + | function getCRC(a, pos, len) |
local sum, mask = 0, 0xFF | local sum, mask = 0, 0xFF | ||
Line 222: | Line 222: | ||
end | end | ||
return sum | return sum | ||
- | end | + | end </ |
- | + | ||
- | + | ||
- | </ | + | |
hydrus-flowmeter.txt · Last modified: 2024/02/20 14:42 by emozolyak