How to read/write one serial port device(like /dev/ttyUSB0) on Linux?

905 views
Skip to first unread message

zhengfish

unread,
Mar 10, 2014, 9:36:58 PM3/10/14
to li...@googlegroups.com
    Hi, Libuver,
        I want to read/write one serial port device(like /dev/ttyUSB0) on Linux.
        What's the handle type I can use?
        Or How can I setup the I/O context?

    Thx!


--
     _                         __ _     _
 ___| |__   ___ _ __   __ _   / _(_)___| |__
|_  / '_ \ / _ \ '_ \ / _` | | |_| / __| '_ \
 / /| | | |  __/ | | | (_| | |  _| \__ \ | | |
/___|_| |_|\___|_| |_|\__, | |_| |_|___/_| |_|
                      |___/

booch

unread,
Mar 11, 2014, 1:21:37 PM3/11/14
to li...@googlegroups.com
You can read/write to a usb device by simply using open/read/write system commands.

Try using a uv_fs_t with uv_fs_open/uv_fs_read/uv_fs_write functions.

These functions will simply communicate bytes of data which is what I think you're looking for.

MY

Saúl Ibarra Corretgé

unread,
Mar 11, 2014, 4:59:15 PM3/11/14
to li...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/11/2014 06:21 PM, booch wrote:
> You can read/write to a usb device by simply using open/read/write
> system commands.
>
> Try using a uv_fs_t with uv_fs_open/uv_fs_read/uv_fs_write
> functions.
>
> These functions will simply communicate bytes of data which is what
> I think you're looking for.
>

The problem with that is that the fs operations run in the thread
pool. So, if you perform 4 uv_fs_read operations and the read()
syscall blocks, the entire thread pool is blocked, that means you
cannot run any other operations that require it, like uv_fd_*,
uv_queue_work, uv_getaddrinfo.

You could try to use a tty or pipe handle. Note that if you use
uv_pipe_open you'll need to set the fd to be non-blocking first.


Cheers,

- --
Saúl Ibarra Corretgé
bettercallsaghul.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/

iQIcBAEBAgAGBQJTH3kjAAoJEEEOVVOum8BZZwkQAJtwSvV/GlX6JuLoqlC9VSvR
KCXAkk9GKPBPO6bCkNH7y9O4UV4wIf9Z7KXjCerKgPtcGalX/q6E9xqNILYdNxu5
cwel6+Nx4GX0rGmQobVs9NhK9Tg6LEKJSM8JWd78AA4ke3rlbqh2sW9m46CJqKTZ
vosRY0fgG4dEdMK1mv9dyxt4k2anFy1SJtiGbFSFLVj2+0+xuQBoypVl5alkxR2y
VHO4JX6hYA4P/PO7jG6z33GIw+iRzj9HTigRjJv+qHZoBXlP/nqhea3pki30uIwX
23M8TggZeClpm5u9yIvro4ObjfIEp57ljdQrAZXlZFTo/wq6u8GWSx/vT/5ylWAz
moiDJJs1DFyp0ml2EWN0+tRq+7fMhEmhb8178U3VTEHm4lyPJ6Tcv3qjec39Hw9F
fl5P/JlZRqfHTfaD5cbig+7+eScQEZz+xkD8Vj5DKih7xLpU0iiczDlhIP4J8o7F
9nLpM08dgaS9Y06RNSNo9dVe1PHlKGvovr/MwJtDdsOOZaeCfloOW8tq9hHrmQ4Z
6meO4HYzAQbuUi4Bbp7zYQIOaja5vYIUCsMZONQc7+mSrG0jQ2Lcu6v1VxCGK8cO
LqPHy4IPRRiYd0FoLPinjio6W/EzdQqmL5g84DrHTzSXf+IFqI1MuuA+1Ah45ktJ
IKo2T0jdZj6GT68PiYtW
=NroZ
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages