reading the usb

Hi,

I am feeding data from an external modem using a serial-usb convertor dongle (I am a newbie when it comes to reading USB devices by the way). I have written a c program to read the bytes on /dev/ttyUSB0 and this works fine. However, if another usb device was plugged into the computer before my device then presumably I would need to read ttyUSB1 instead. So how do interrogate the operating system to find out which /dev/ttyUSB.. is currently in use and thus communicate to my program which usb device my program should read from?

I'm sure this is a pretty basic question so I have done searches and looked at the faqs etc but have not been able to find what I am looking for. So any help appreciated.

Regards,

Mary

Reply to
Mary Walker
Loading thread data ...

Depends on the OS -- what OS is it?

You probably won't be able to find out whether the device is connected just by looking at /dev/ttyUSB*. You might be able to get stats on what USB devices are connected and figure out what ttys they're bound to, but this is bound to be complicated.

You could maybe just send out an are-you-there and see if you get anything back ..

--mpa

Reply to
Data

Hi,

The operating sytem is Linux.

Reply to
Mary Walker

I would poke around /proc. That is where linux puts status type information. I don't have my Linux box close, or I could tell you where in /proc to look.

eepoke

Reply to
eepoke

What I do is set up udev rules to name the USB devices consistently regardless of the order they're plugged in.

formatting link
formatting link
formatting link
formatting link

--
Grant Edwards                   grante             Yow!  Dizzy, are we
                                  at               "REAL PEOPLE" or "AMAZING
                               visi.com            ANIMALS"?
Reply to
Grant Edwards

/proc/bus/usb/devices

--
Grant Edwards                   grante             Yow!  I just put lots of
                                  at               the EGG SALAD in the SILK
                               visi.com            SOCKS --
Reply to
Grant Edwards

Yep, that would seem to be the "right" answer to the OP's problem.

Reply to
toby

mary, you seem to be further than i in this kind of job could you (or anyone else, for that matter) give me some pointers as to the the beginning? does one do an fopen on the right /dev entry, then freadc or the like?

I did search google but only got a bewildering multitude of non-useful results. sincere apologies if I'm considered too lazy or off topic... karel

Reply to
karel

Some pointers:

1) Do not read, look at, use code from, or even think about the "Serial Programming HOWTO" at tldp.org. It's incomplete, incorrect, and unmaintained. 2) Read the Posix Serial Programming Guide at
formatting link
3) man termios
--
Grant Edwards                   grante             Yow!  I think I'll make
                                  at               SCRAMBLED EGGS!! They're
                               visi.com            each in LITTLE SHELLS...
Reply to
Grant Edwards

thank you sir, that's a most useable reply! (though i had hoped for an example, or a link to one...) KA

Reply to
karel

The Posix Serial Programming Guide has tons of examples.

--
Grant Edwards                   grante             Yow!  The SAME WAVE keeps
                                  at               coming in and COLLAPSING
                               visi.com            like a rayon MUU-MUU...
Reply to
Grant Edwards

it has indeed, and a nice website it makes! but the word USB does not once figure in it, or i should have overlooked it it's all about rs-232 as far as i can see.

maybe my question should have been: "i might be able to figure this out for rs-232 but are there any differences for USB serial apart from the device to open?"

Reply to
karel

I thought you were using a USBRS-232 serial widget.

RS-232 is the standard which defines the 25-pin D connectors and electrical signalling levels at those connectors. It's got nothing to do with the UART or how that UART is attached to the CPU.

No, there are no differences in the serial port API between ISA-attached serial ports and USB-attached (or Ethernet-attached, for that matter) serial ports. That's what device drivers are for, you know. ;)

There are going to be differences in timing. For example: when you make the call to set RTS, that happens immediately for ISA-bus and PCI-bus attached devices (by "immediately" I mean that you know that when the ioctl() system call returns, you know the operation has been completed and the RTS line is in the requested state). It doesn't happen immediately for USB. The ioctl() call may just queue up a request to set RTS. The ioctl() call can return before the USB host controller has sent the request.

--
Grant Edwards                   grante             Yow!  The Osmonds! You are
                                  at               all Osmonds!! Throwing up
                               visi.com            on a freeway at dawn!!!
Reply to
Grant Edwards

Oh, unless you're a glutton for punishment, I wouldn't actually recommend using C at all for host-side serial apps. I use Python and the pyserial module for 99% of my serial stuff. Apart from taking a fraction of the time to develop when compared to C, the resulting program will work under Linux/Unix, Windows, MacOS, and Java VM.

--
Grant Edwards                   grante             Yow!  One FISHWICH coming
                                  at               up!!
                               visi.com
Reply to
Grant Edwards

yes. also, my linux (suse 8.2) has a utility called lsusb which consults the same information.

Reply to
karel

I am in a similar config and have found that, during the boottime hardware scan, a line is added to /var/log/messages stating the ttyUSB# used. KA

Reply to
karel

Well yes, in a way I am, but it seems to me my config is the reverse of what you figured.

Actually, I want to read GPS-data from a Hicom receiver that has a 6-pin DIN-connector, like on pre-USB PC keyboards. It sends out a continuous stream of GPS-data at 4800,n,8,1 which I can perfectly receive and decode. But it also has a convertor from the DIN-connector to USB, and is recognized by the Linux box; only I seem unable to read any data from it.

NB the reason I should like to read from USB is that serial ports are less and less common on PC's and especially on portables.

Thanks for your interest! KA

Reply to
karel

I assumed you have a USB-serial adapter where the USB end plugs into the Linux host and the serial end plugs into some device or other. If that's not what you're talking about, then for pete's sake tell me what you _are_ talking about rather than making us guess.

That's exactly what I was talking about.

What's it recognized as? I'd be surprised if it's not either a PL2303 or an FTDI USB-serial adapter. From what I've seen 95% of the USB serial converters are one or the other. There are about a 20 other USB-serial adapters supported by Linux, but I've never seen any of them in use.

And I've given you pointers for documentation on exactly how to do it.

--
Grant Edwards                   grante             Yow!  I know how to get the
                                  at               hostesses released! Give
                               visi.com            them their own television
                                                   series!
Reply to
Grant Edwards

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.