require('serial') port = serial.open('/dev/RS485', { baudrate = 9600, databits = 8, stopbits = 1, parity = 'none', duplex = 'half' }) log("Verbinding gemaakt") function readdata(port) local char, buf buf = {} while true do char = port:read(1) -- error (timeout) or newline, stop if char == nil then break -- ignore cr char elseif char ~= '\r' then table.insert(buf, char) end end return table.concat(buf) end data = readdata(port) log (data) port:flush()