Need help with reading from serial port

80 views
Skip to first unread message

Jörg Krause

unread,
May 25, 2016, 7:15:37 AM5/25/16
to luvit
Hi,

I am trying to read data from a serial port using Luvit. My simple example is running, however, I have an issue with fs_read() as it calls the callback function even if no data are received.


This is the output:

# luvit main.lua 
''
''
''
''
''

My problem with this issue is that it consumes much more CPU cycles on my embedded Linux system than reading from "/dev/input/event0".

Any ideas what's wrong here?

Tim Caswell

unread,
May 25, 2016, 11:46:41 AM5/25/16
to lu...@googlegroups.com
I don't have any idea what's wrong, but several of us have been trying to get serial support (or at least the ability) into upstream libuv, you can see much of the history at https://github.com/libuv/libuv/pull/484

--
You received this message because you are subscribed to the Google Groups "luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jörg Krause

unread,
May 27, 2016, 1:52:48 AM5/27/16
to luvit
Many thanks for the link! I think fs_read() does not work for Linux serial ports as underlying read() system call reads EOF from the serial interface.

If I try to use a Luvits ReadStream interface, the 'end' callback is called before I receive any data.

So, lets hope there will be support for serial ports in libuv soon.

Tim Caswell

unread,
May 27, 2016, 9:37:16 AM5/27/16
to lu...@googlegroups.com
You can maybe try to use the pipe interface as it accepts arbitrary file descriptors.  That's what I use to create pty's in luvit.

Vladimir Dronnikov

unread,
May 27, 2016, 9:40:28 AM5/27/16
to lu...@googlegroups.com
tty is likely set in non-blocking mode -- that may lead to EOF storm.
Message has been deleted

Jörg Krause

unread,
Jun 9, 2016, 2:44:36 AM6/9/16
to luvit
Not sure why my last post was deleted.

I'm back from vacation and I will have a closer look at your example soon. Many thanks!

Martin Croome

unread,
Sep 2, 2016, 2:46:36 AM9/2/16
to luvit
Hi Jorg

We have working serial support, The tack we took is a mixture of Luvit, C and FFI. We use FFI for read and write, C for line monitoring threads and Luvit (uv.poll for events on the port).

Regards

Martin

Tim Caswell

unread,
Sep 2, 2016, 11:30:19 AM9/2/16
to lu...@googlegroups.com
Are there any small simply primitives that I could bake into luvi that made this possible with pure lua+ffi?  I know I would use serial all the time if I had the option (for talking to microcontrollers over USB mostly)

--
You received this message because you are subscribed to the Google Groups "luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+unsubscribe@googlegroups.com.

Jörg Krause

unread,
Sep 5, 2016, 5:32:01 PM9/5/16
to lu...@googlegroups.com
I finally used ffi with libserialport for doing all the serial configuration and reading from the port: https://gist.github.com/joerg-krause/6d0a8a4949670ee103e6c22006f0cc37.

I guess it is not very luvit idiomatic, but at least it works for me.

--
You received this message because you are subscribed to a topic in the Google Groups "luvit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/luvit/m_bJes9J2p0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to luvit+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages