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.

Process received data
#19
(19.11.2020, 07:44)admin Wrote: Try this as a resident script. Edit serial.open with correct port name and settings.
Code:
1234567891011121314151617181920212223242526
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.
How can I extract the 12th or 13th data separately from the 16 reads?
Reply


Messages In This Thread
Process received data - by Rick - 18.11.2020, 09:11
RE: Process received data - by Daniel - 18.11.2020, 09:27
RE: Process received data - by Rick - 18.11.2020, 09:35
RE: Process received data - by Daniel - 18.11.2020, 09:41
RE: Process received data - by Rick - 18.11.2020, 09:49
RE: Process received data - by admin - 18.11.2020, 09:46
RE: Process received data - by admin - 18.11.2020, 10:58
RE: Process received data - by Rick - 18.11.2020, 11:07
RE: Process received data - by admin - 18.11.2020, 11:20
RE: Process received data - by Rick - 19.11.2020, 01:59
RE: Process received data - by admin - 19.11.2020, 07:44
RE: Process received data - by Rick - 19.11.2020, 09:32
RE: Process received data - by Rick - 20.11.2020, 04:10
RE: Process received data - by Daniel - 19.11.2020, 09:36
RE: Process received data - by Rick - 19.11.2020, 09:43
RE: Process received data - by Daniel - 19.11.2020, 09:56
RE: Process received data - by Rick - 19.11.2020, 10:01
RE: Process received data - by Daniel - 19.11.2020, 10:03
RE: Process received data - by Rick - 19.11.2020, 10:03
RE: Process received data - by admin - 20.11.2020, 06:48
RE: Process received data - by Rick - 20.11.2020, 07:00

Forum Jump: