Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

USB to serial "coupler"?

by Anonymous Monk
on Dec 31, 2008 at 22:58 UTC ( [id://733572]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, Perl gurus!

I've been trying to figure this out for the past week or so, and not having much luck. I'm hoping that someone here will have some ideas, or even better, experience with my problem.

I've got an old (compiled, no source code) application that requires a GPS connection on a serial port. Of course, none of our field laptops have anything like that - it's all USB these days. What I need is some kind of a "bridge" daemon that will read the NMEA-0183 sentences from the USB port and write them to the serial port.

I've read 'perldoc -q serial', including Jamie Zawinski's solution... and I see that even he had to struggle with all the craziness in dealing with these things. I've messed around, half-heartedly - since I don't really understand what I'm doing - with IPC::Open2, and got nowhere. Not even close to anywhere, in fact - couldn't read anything at all. I've searched the web until the engine in my browser ran out of oil and started making a rattling noise, and had no luck at all.

We're running Ubuntu, and I know that these external USB dongles work just fine - 'gpsdrive' has no problem seeing them. The only problem is this legacy app - and I'm the guy who's been "delegated" to deal with the issue.

I'd really appreciate whatever wisdom and advice you can spare.

Replies are listed 'Best First'.
Re: USB to serial "coupler"?
by jasonk (Parson) on Jan 01, 2009 at 03:46 UTC

    Not a perl solution, but serpipe lets you use a pty/tty pair as a pseudo serial port. Run 'serpipe /tmp/foo /dev/ptyp1' and it will relay data between the pipe at /tmp/foo and /dev/ttyp1.


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!
      It sounds like exactly the right thing. I'll check it out, thanks!
Re: USB to serial "coupler"?
by shmem (Chancellor) on Jan 01, 2009 at 14:42 UTC
    I've got an old (compiled, no source code) application that requires a GPS connection on a serial port. Of course, none of our field laptops have anything like that - it's all USB these days. What I need is some kind of a "bridge" daemon that will read the NMEA-0183 sentences from the USB port and write them to the serial port.

    Write them to the serial port? There isn't any, if your laptop doesn't have a serial port. Your GPS mouse is USB, isn't it? So it should show up as /dev/ttyUSB0 or such and be handled by the usbserial kernel module. All you need to do is to soft-link the USB device file to the one your legacy application expects, e.g. ln -s /dev/ttyUSB0 /dev/ttyS0

      When I said "write them to the serial port", I didn't mean "shove them out through some non-existent pins in a non-existent D-type connector". I meant, "write the data to wherever the kernel will pick it up as data coming in via the serial port if it's possible." I'm probably making a bunch of stupid assumptions in saying that, but if I knew all those answers, I wouldn't be asking the questions, right?

      Your idea of linking the two implies that USB and serial ports share exactly the same protocol. I don't know if that's what you meant to imply, but - hell, I can't see any harm in trying it, so I'll give it a shot. At least it's a directions I hadn't thought about before. Thanks - I really appreciate that!

Re: USB to serial "coupler"?
by zentara (Archbishop) on Jan 01, 2009 at 14:28 UTC
    Why try to code it? For $20 you can get a usb-serial adaptor. Google for "serial to usb adapter". (Maybe I misunderstand your question?)

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      This is the wrong way around. I'm not going from a serial dongle to a USB port - I'm going from a USB dongle to an application that can ONLY read from serial ports.

        You didn't mention your OS, but if you are on Win32, com0com provides an easy way to pipe stuff through serial ports. It provides a pair of connected virtual serial ports.

        You'd still need to write a translator that can talk to the USB dongle.

        Your serial requiring legacy code would connect to one port. Your translator would connect to the other port. The translator would then talk to the USB dongle and perform any needed protocol conversions.


        TGI says moo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://733572]
Approved by oko1
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found