Lua Read Write Serial Port

I have Openwrt router with Arduino connected via USB FTDI adapter. Serial port is /dev/ttyUSB0 Arduino code prints some data: First part of data printed with delay via command print(), for example: Serial.begin(9600); Serial.print(var1); delay(1000); Serial.print(var2); delay(1000); Serial.print(var3); delay(1000); And second part printed with println() command: Serial.println('); Serial.println(var4); Serial.println(var5); Serial.println(var6); So when I open Serial port in terminal I can see something like this: 1 then timeout in 1 sec, then 1 2 next timeout. And then 1 2 3 last timeout and 1 2 3 4 5 6 It works in Terminal program and in console in OpenWRT, for example screen /dev/ttyUSB0 I need make a Lua script that will read Serial port and print the data in the same way. I have a simple script, but it doesn't work as expected. Rserial=io.open('/dev/ttyUSB0','r') while true do chain = nil while chain==nil do chain=rserial:read(); print(chain) end end it shows all data at once. It doesn't show first 3 vars one by one with delays. Seems it is because of rserial:read() - it will read until it receives a newline character.

Read

Sep 15, 2012 - A few ways to send message to serial port of router which flash with OpenWRT. Io.write('on3 r'). Having the same example test.lua, copy it to /www/cgi-bin and rename it to test (without extension), you should have. > I read the serial port but I receive an echo too and the read() waits > until a new line character to return. > There is any other way to read from a serial port?

It stated in similar question: I tried to run this command as was advised there: stty -F /dev/ttyUSB0 -icanon but it doesn't help and I don't understand why. Is it the way to fix this behavior via stty? Or I definitely need to use another Serial libs for Lua script? All of these libs seems pretty outdated for now and I don't want to use outdated stuff. From the: When called without formats, it uses a default format that reads the next line (see below). A new line is anything in the buffer until the next newline character. So as long as you don't send a newline character Lua will wait one as it has been told by calling read() Once a newline character is received you will be prompted any other character in that line.

Terminal programs usually update every byte to show what they receive in 'real-time'. So if you want to have the same behaviour you may not use read() without any arguments.

Hartke ha3500 service manual. Use read(1) to read every single byte without waiting for anything else.

I'm new to lua and I'm trying to receive data from the port, ttyACM0, I can write to the port by: wserial = io.open('/dev/ttyACM0','w') wserial:write('hellloooo') wserial:flush() I thought since I can write to it in the same way as I would write to a file that I could read it in the same way as I would read a file. But when I try to read it (using the code below) I just end up in an infinite loop. Rserial=io.open('/dev/ttyACM0','r') while chaine==nil do chaine=rserial:read() rserial:flush() end print(chaine) So my question is what am I doing wrong, how do I read from the port, ttyACM0?