[luci] help with nixio nonblocking serial usb connection

Pedro Infantilo infantilo at hotmail.com
Fri Jun 28 10:23:04 CEST 2013


Hi there,i'm stuck with reading data from my arduino nonblocking.Sadly there's no support in openwrt or lua forum regarding this problem, so maybe someone here could give advice.
i'm building an homeautomation/burglar alarm based on an arduino connected to my wrt703n that sends strings when it receives an command from any 433mhz remote. my lua script is basically an simple webserver. So i needed both, socket and serial connection to be nonblocking.Sadly the following code forks fine for hours but then stucks and the serial connection does not read any value anymore. i can still echo to ttyUSB0 from the shell.Anyone on what i'm doing wrong?
all i need is to check if data is available and read all available data. For me it looks like as im stressing the serial port this way.
i'm initialising my connection by:os.execute("stty -F "..port.." hupcl")
os.execute("stty -F "..port.." cs8 "..speed.." raw ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts")
local flags = nixio.open_flags('rdwr','sync','ndelay')
arduinoR = nixio.open(port,flags)  and i'm trying to look if data is available this way:function DoSerialCommunication()
    local achar = arduinoR:read(1)
    local line = ""
    local eexit = 0
    while not achar== false and eexit<200 do
        eexit = eexit + 1

        line=line..achar
        if string.byte(achar)==10 then
            if line~="" then
                local parsedcode = ""
                string.gsub(line,"OC,C:(.-),", function(a) parsedcode=a end )
                if parsedcode then
                ----- store the received code so we can grab it eg. from the webpage in learn function
                    GetLastReceivedCode = parsedcode
                    ProcessCode(parsedcode)
                end
            end
            line=""
        end
        achar = arduinoR:read(1)
    end
end 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsignal.org/pipermail/luci/attachments/20130628/47e80bcd/attachment.html>


More information about the luci mailing list