TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: GREGORIE
from: JAN PANTELTJE
date: 2018-05-18 07:11:00
subject: Re: poll() and USB-serial

On a sunny day (Fri, 18 May 2018 00:13:32 +0000 (UTC)) it happened Martin
Gregorie  wrote in :

>Has anybody tried using a asynchronous, i.e. poll() based i/o, to handle
>bidirectional data transfers over a USB-serial adapter?
>
>I have a setup that works as expected when talking to a program that
>emulates the target via a socket session, but appears to send but not
>receive messages when connected to the target device via a USB-serial
>adapter.

If I am understanding you right? You just want to talk to a /dev/ttyUSBX ?

Here is a simple example, my serial commie-nuke-aid-ion program:
 http://panteltje.com/panteltje/newsflex/download.html#ptlrc
C code, uses 'select()'.

If you look at the functon set_port_parameters() in that code, it sets the
required baudrate using stty,
 man stty
so you could even script that,

I never use poll(), select() does everything and more.

You find those select() based commie-nuke-aid-ion solutions in many programs I
wrote on that link.
 man select()

For the rest USB sucks.

As an alternative after setting the baudrate with for example
 stty -F /dev/ttyUSBX -N 115200
you could write to a serial USB device with
 cat /dev/ttyUSBX > filename
and write to it with
 cat filename > /dev/ttyUSBX
I suppose.

ptlrc has a script mode, never used it for years, so YMMV.
but it is the best commie-nuke-aid-ion program around,
wrote it to commie-nuke-aid with Microchip PIC devides, works on anything else.
Not the catch that Unix use LF as line termination,
while many other systems need the extra CR, so need CRLF:

 /* PIC wants CR */
 if(tx_buffer[i] == 10) tx_buffer[i] = 13;
 if(tx_buffer[i] == 13)
   {
   tx_buffer[i + 1] = 10; // CR
 ....


Also note the lines:
 system("stty raw");
 system("stty -echo"); /* no echo */
 system("stty sane")
in the ptlrc code, also system calls to stty
maybe not important for your app if you do not emulate a teminal


Code is GPL.

Does this help, tick as required:
[ ] Yes
[ ] No
[ ] Dunno
[ ] Help
click  to reset your computer.

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.