20.11.2020, 04:10
(19.11.2020, 07:44)admin Wrote: Try this as a resident script. Edit serial.open with correct port name and settings.How can I extract the 12th or 13th data separately from the 16 reads?
Return value for read function is a table containing bytes that have been read converted to numbers. It assumes that there's at least 0.5 seconds between consecutive messages. You can edit the timeout value to suit your needs.Code:if not port then
require('serial')
port = serial.open(...)
function read()
local buf = {}
while true do
local timeout = #buf > 0 and 0.5 or 15
local char = port:read(1, timeout)
if char then
buf[ #buf + 1 ] = char:byte()
else
return buf
end
end
end
end
res = read()
log(res)
if #res == 16 then
-- process 16 bytes of data
end