(19.11.2020, 07:44)admin Wrote: Try this as a resident script. Edit serial.open with correct port name and settings.
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
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.
THANKS,I will try this.
(19.11.2020, 09:32)Rick Wrote: (19.11.2020, 07:44)admin Wrote: Try this as a resident script. Edit serial.open with correct port name and settings.
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
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.
THANKS,I will try this.
In addition, I found that LM sometimes cannot be accessed through Google browser, and it is normal after waiting for about 30s. When it is not accessible, the logic function inside LM cannot be realized either.