User Tools

Site Tools


hydrus-flowmeter

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
hydrus-flowmeter [2023/08/17 11:03] emozolyakhydrus-flowmeter [2024/02/20 14:42] (current) – [Connecting to DIEHL HYDRUS flowmeter] emozolyak
Line 1: Line 1:
 {{ :custom_protocols:mbus:hydrus-meter-for-mbus.jpg?direct&150|}} {{ :custom_protocols:mbus:hydrus-meter-for-mbus.jpg?direct&150|}}
-====== Connecting to HYDRUS by DIEHL flowmeter  ======+====== Connecting to DIEHL HYDRUS flowmeter ======
  
 <WRAP center round info 80%> <WRAP center round info 80%>
Line 16: Line 16:
 end  end 
  
-POLL_DELAY    = 60 -- poll rate constant in sec. +POLL_DELAY    = 60 * 15  -- poll rate constant in sec. 
 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, pttrn) -- finds pattern in a table  tableFindPattern+function table.findPattern(t, pttrn) 
    
     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 + #pttrn) -- start of data +            return (tabIndex + #pttrn) 
         end          end 
     end      end 
Line 68: Line 67:
 end  end 
    
-function table.sub(t, startIndex, endIndex) -- picks sub-table from a table +function table.sub(t, startIndex, endIndex) 
     local tmpTable = {}     local tmpTable = {}
     for k = startIndex, endIndex do      for k = startIndex, endIndex do 
Line 76: Line 75:
 end  end 
    
-table.hexView = function(hextab, spacer) -- get string of a hex view for a table  tabHexView+table.hexView = function(hextab, spacer) 
     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)
 +   return tonumber(table.hexView(t), HEX_NUMBERING) 
 +end  
 +
    
-function getHexByteAsStr(inputByte) -- gets 2 - char hex string of a byte + -- gets 2 - char hex string of a byte  
 +function getHexByteAsStr(inputByte) 
     local strByte = string.format("%X", inputByte)         local strByte = string.format("%X", inputByte)    
     return (#strByte == 1 and '0' .. strByte) or strByte     return (#strByte == 1 and '0' .. strByte) or strByte
 end  end 
  
-table.reverse = function (tab) -- reverses a table   reverseTable+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             = 0x7B -- Request for Class 2 Data  +REQ_UD2             = 0x7B -- Request for Class 2 Data  FCB  
-REQ_UD2_            = 0x5B -- Request for Class 2 Data +REQ_UD2_            = 0x5B -- Request for Class 2 Data  Frame count bit 
  
 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},       length = 4, func = table.bcd},  
-    flow   = {pattern = {0xB, 0x3C}, length = 3, func = table.bcd}, +    flow   = {pattern = {0xB, 0x3C},       length = 3, func = table.bcd}, 
-    tint   = {pattern = {0xA, 0x5A}, length = 2, func = table.bcd}, +    tint   = {pattern = {0xA, 0x5A},       length = 2, func = table.bcd}, 
-    text   = {pattern = {0xA, 0x66}, length = 2, func = table.bcd}, +    text   = {pattern = {0xA, 0x66},       length = 2, func = table.bcd}, 
-    err    {pattern = {0x4, 0xFD, 0x17} +    err    {pattern = {0x4, 0xFD, 0x17}, length = 4, func = table.int}
-              , length = 4 +
-              , func = function(d) +
-                          return tonumber(table.hexView(d), HEX_NUMBERING)  +
-                        end},  -- int32 convertion+
 } }
  
Line 178: Line 179:
                 else                  else 
                     ERROR("failed to find data !")                     ERROR("failed to find data !")
-                    data = false     +                    data[param] = false     
                 end                 end
             end              end 
         else          else 
             ERROR("failed to read reply!")             ERROR("failed to read reply!")
-            data = false +            data = {} 
         end          end 
     end      end 
Line 200: Line 201:
 -------------------------- Other helpers -------------------------- -------------------------- Other helpers --------------------------
    
-function readUntil(endByte) -- read input buffer untils endByte or timeout  +function readUntil(endByte)  
-    local ONE_BYTE = 1  +    local ONE_BYTE, buf = 1, {}  
-    local buf = {}+    
     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, rx)
-            table.insert(buf, rx)+
         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 </code>
- +
- +
-</code>+
  
hydrus-flowmeter.1692270199.txt.gz · Last modified: 2023/08/17 11:03 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki