Linux question -- how to tell if serial port in /dev is for real?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
OK, wrong group.  But you guys are smart, and mostly aren't snobs.

So -- is there a way to tell if a device in /dev is for real?  There's  
about a bazzilion /dev/tty<this and that> in my computer at the moment,  
but there's only one (/dev/ttyUSB0) that's actually connected to a  
working serial port.

I would like to know how to know.

Thanks.

--  

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
On Mon, 04 Aug 2014 19:39:12 -0500

Quoted text here. Click to load it

I'm assuming you're looking to do this from code, not the command
line.  Sooner or later, the lack of reality of a
given /dev/dealiewhopper will become a problem. In your case, that
should be when you actually try to treat it as a serial port.  So the
following test code keels over and dies with the error
"tcgetattr /dev/ttyS18: Input/output error"

---

#include <stdio.h>
#include <fcntl.h>
#include <termios.h>

#define TTY "/dev/ttyS18"

int main(void) {
    int fd = open(TTY, O_RDWR | O_NOCTTY);
    if (fd < 0) {
        perror("open " TTY);
        return 1;
    }
    
    struct termios tio;
    if (tcgetattr(fd, &tio)) {
        perror("tcgetattr " TTY);
        return 1;
    }
    
    return 0;
}



--  
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.

Re: Linux question -- how to tell if serial port in /dev is for real?
On Mon, 04 Aug 2014 18:06:47 -0700, Rob Gaddi wrote:

Quoted text here. Click to load it

Thanks Rob.  Eventually I may get my head wrapped around all the termios  
stuff, probably ten minutes before I get run over by a beer truck.

--  
Tim Wescott
Control system and signal processing consulting
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
On 05/08/14 04:48, Tim Wescott wrote:
Quoted text here. Click to load it

You might prefer to use pyserial to access the port from Python - and
let pyserial handle the messy termios stuff:

import serial

try :
    port = serial.Serial("/dev/ttyUSB0", 9600)
    print "It's a serial port :-)"
except :
    print "It's not a serial port :-("




Re: Linux question -- how to tell if serial port in /dev is for real?
On Tue, 05 Aug 2014 08:30:08 +0200, David Brown wrote:

Quoted text here. Click to load it

All of the desktop serial-port stuff I've done in the last decade has  
been in support of embedded work, and it's all been heavily dependent on,  
and used as part of the testing framework for, serial communication code  
that is to be embedded.

So I'm constrained to C or C++.

Basically what I do when I write embedded stuff (unless it's really  
teeny) is to write it so that the actual hardware layer is abstracted --  
usually into a class, because I'm usually working in C++.  Then all of  
the "middleware" that I'm seeking validation for finds its way into both  
the embedded software and a test-bench running on a PC that's talking to  
the embedded system.  Finally, the PC has some GUI (I'm currently using  
Qt, again because I'm constrained to C++), and the embedded system has  
whatever it needs to have piled atop the serial port.

Knowing whether a port is real or not is really just a convenience for me  
-- when you do an "open file" dialog on /dev/tty* in Ubuntu you get a  
buttload of stuff, most of which is not valid; I'd like to fix that.

--  

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
Quoted text here. Click to load it

If this is about embedded Linux, Python works great for that.

Re: Linux question -- how to tell if serial port in /dev is for real?
On Tue, 05 Aug 2014 16:15:44 -0700, Paul Rubin wrote:

Quoted text here. Click to load it

Will Python run on an ARM Cortex M0 with 64k of ROM and 8K of RAM?

With room left over for actual application code?

--  

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
Quoted text here. Click to load it

No, but you said it was _desktop_ serial-port stuff.  Your desktop is
an M0 with 64K of ROM and 8K of RAM?  And it suppors network access
and an NNTP client!  That is impressive.

--  
Grant




Re: Linux question -- how to tell if serial port in /dev is for real?
On Wed, 06 Aug 2014 05:17:51 +0000, Grant Edwards wrote:

Quoted text here. Click to load it

Actually I explained it in my original post: I'm running the software on  
a desktop, but it's written with a Linux serial driver and a cool GUI  
that are easy to lop off.  At some point all of the (by then hopefully  
well-tested) stuff in the middle will get shoved into an itty bitty  
processor on a board with two buttons and a 2 line by 16 character  
display.

--  

Tim Wescott
Wescott Design Services
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
Il 06/08/2014 04:38, Tim Wescott ha scritto:> On Tue, 05 Aug 2014  
16:15:44 -0700, Paul Rubin wrote:
 >
 >>> All of the desktop serial-port stuff I've done in the last decade has
 >>> been in support of embedded work, ...
 >>> So I'm constrained to C or C++.
 >>
 >> If this is about embedded Linux, Python works great for that.
 >
 > Will Python run on an ARM Cortex M0 with 64k of ROM and 8K of RAM?
 >
 > With room left over for actual application code?

Linux on ARM Cortex M0? Fantastic... could you give us more details  
about the board? Is it a custom board? Are you able to run a full Linux  
(no uclinux) on a M0-based board?



Re: Linux question -- how to tell if serial port in /dev is for real?
On 07/08/14 08:42, pozzugno wrote:
Quoted text here. Click to load it

I think you've got things a bit mixed up here.  No one is running Linux
on an M0 (though people /have/ run Linux on M3 and M4 cores, albeit the
nommu version - what used to be called ucLinux before the nommu support
was integrated into the mainline kernel).

The thread here has got somewhat confusing, because people tried to help
Tim before he had given us his full requirements.  When he wanted to do
serial stuff on a Linux system, several responses suggested Python
because it is much easier than doing it in C.  When he said it had to be
portable to embedded systems, Python was still a suggestion since it
works fine in embedded Linux systems.  But it turns out that he wants to
code in C so that it can be easily used on small non-Linux embedded
systems (so that he can test and debug the code on the PC, then run it
on a Cortex M0 - not a bad plan).

And while it is /possible/ to run a cut-down and limited Python on an
M0, I think it is unlikely to be a good choice in practice!


There is a lesson to be learned here in making your requirements and
constraints explicit from the start - it's a lesson we have all
"learned" many times, and all forgotten just as often :-)


If you are really keen, then I'd imagine this setup could be ported to
an M0:

<http://dangerousprototypes.com/2012/03/29/running-linux-on-a-8bit-avr/


Re: Linux question -- how to tell if serial port in /dev is for real?
Quoted text here. Click to load it

Yea, I didn't understand why the desktop stuff was constrained to be C
or C++ just because it was talking to an embedded system.

I do a _lot_ of desktop serial port stuff in support of embedded work,
and all the desktop stuff is in Python -- and some of it needs
response time measured in tens of microseconds.  I know a lot of other
embedded developers do that as well.

--  
Grant


Re: Linux question -- how to tell if serial port in /dev is for real?
On Wed, 6 Aug 2014 05:16:13 +0000 (UTC)

Quoted text here. Click to load it

I'll bite.  I do most of my desktop support in Python as well, but
always assume that at any time the combination of Python and the OS
may wallop me for any number of milliseconds, and that I just need to
suck up and deal, and find some other way to handle it when I need to
ensure realtimeyness.

How do you guarantee microsecond level response from Python (and I
assume Linux)?

--  
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.

Re: Linux question -- how to tell if serial port in /dev is for real?
Quoted text here. Click to load it

Linux has a realtime scheduler but guaranteeing microsecond response is
not realistic because of nondeterministic cache misses and that sort of
thing.  For soft realtime maybe it's feasible.  Milliseconds are easier
than microseconds of course.

Python is interpreted and slower than C, but if the realtime loop is
simple, then you can generally have at least a "soft" bound on the
latency.  Memory management is by reference counting so there should be
no GC pauses unless you're building up large connected structures and
freeing them in one piece.

Re: Linux question -- how to tell if serial port in /dev is for real?

Quoted text here. Click to load it

or you use something like Linux RTAI that gives you hard real time.

Bye Jack
--  
Yoda of Borg am I! Assimilated shall you be! Futile resistance is, hmm?

Re: Linux question -- how to tell if serial port in /dev is for real?
snipped-for-privacy@disney.com (Jack) writes:

Quoted text here. Click to load it

Is CONFIG_PREEMPT_RT dead?
--  
Randy Yates
Digital Signal Labs
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
On 06/08/14 20:56, Jack wrote:
Quoted text here. Click to load it

.. providing, of course, the processor neither instruction nor
data caches. If either are present then the ratio of mean:max
latency rapidly becomes very significant.

Even a 486 with its tiny caches showed a 10:1 interrupt latency
depending on what was/wasn't in the caches. (IIRC that was measured
with a tiny kernel, certainly nothing like the size/complexity
of a linux kernel)


Re: Linux question -- how to tell if serial port in /dev is for real?

Quoted text here. Click to load it

Aren't interrupt routines in some permanently-cached portion of the MMU?
--  
Randy Yates
Digital Signal Labs
We've slightly trimmed the long signature. Click to see the full one.
Re: Linux question -- how to tell if serial port in /dev is for real?
On Wed, 06 Aug 2014 17:31:23 -0400, Randy Yates

Quoted text here. Click to load it


There's no such thing on typical x86s.

Re: Linux question -- how to tell if serial port in /dev is for real?
On 06/08/14 22:31, Randy Yates wrote:
Quoted text here. Click to load it

No, and once an MMU is involved all the paging information
might or might not be cached. Double whammy.


Site Timeline