This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Norwegian HAN-interface - Kamstrup meter
#4
Your example already does what I've suggested. The only slight improvement is to use a table to buffer data.
Code:
-- Check if port is open, open serial port if not
if not port then
  require('serial')
  port = serial.open('/dev/ttyUSB0', { baudrate = 2400 })
  port:flush()
  buffer = {}
end

-- Read on byte, or time out after 1 sec
char = port:read(1, 1)

if char then
  buffer[ #buffer + 1 ] = char
elseif #buffer > 0 then
  data = table.concat(buffer)
  -- parse(data)
  loghex(data)
  buffer = {}
end
Reply


Messages In This Thread
RE: Norwegian HAN-interface - Kamstrup meter - by admin - 01.02.2019, 08:24

Forum Jump: