How to create a virtual serial port?

Discussion in 'Python' started by Stuart Davenport, Apr 10, 2009.

  1. Hi,

    I am trying to work out if its possible, to create a virtual serial
    port with Python? Would anyone know how to go about this in code? Any
    help would be greatly appreciated! :)

    I have a had a google and the topics returned only seem to reflect
    "reading" serial port data, particularly pySerial results...

    Stuart Davenport, Apr 10, 2009
    1. Advertisements

  2. Scott, totally fair point - a little candid, but fair...

    I'm on a OS X, python 2.5. Basically I will have a remote application
    pushing data (GPS) over the network to a python application I have
    running on my Mac, I want this python application to again push the
    data on to a "virtual serial port". Then the GPS program I have
    running on my MAC, RouteBuddy, can read the data from that serial port
    as standard.

    The only part I am concerned about here though, is if I can create a
    serial port virtually and push data out of it?

    Hope that defines a little more clarity for yourself.
    Stuart Davenport, Apr 10, 2009
    1. Advertisements

  3. In message <e454b840-2361-413f-
    Macs don't have serial ports.
    Lawrence D'Oliveiro, Apr 11, 2009
  4. Sadly RouteBuddy cannot retrieve data by other means...

    Scott, many thanks for the advice. Will try to find a more specific
    forum of conversation.

    Stuart Davenport, Apr 11, 2009
  5. Stuart Davenport

    Ned Deily Guest

    A number of vendors (Keyspan, Belkin) make USB serial ports. FWIW, I
    use one here on this iMac and OS X with screen(1) and a null modem cable
    to act as a serial console for a headless Linux box.
    Ned Deily, Apr 11, 2009
  6. Extending to the point of absurdity... Does the machine have a
    physical serial port from which the application could read?

    Does the machine have a USB port?

    What would setting a pair of serial ports (possibly one or both
    using USB<>Serial adapters) with a null modem between them give? Could
    the application read from one, while Python is writing to the other?

    Yes, it IS an absurd klutz, but...
    Wulfraed Dennis Lee Bieber KD6MOG

    (Bestiaria Support Staff: )
    Dennis Lee Bieber, Apr 11, 2009
  7. Stuart Davenport

    Ned Deily Guest

    Also true but I just wanted to use "headless" in a python post.
    Ned Deily, Apr 11, 2009
  8. Stuart Davenport

    JanC Guest

    USB *is* a serial port... that's what the "S" stands for. ;)
    JanC, Apr 12, 2009
  9. Stuart Davenport

    JanC Guest

    I wonder if there is no way to emulate ptys from userspace?
    (Like you can use FUSE to implement filesystems in python.)
    JanC, Apr 12, 2009
  10. And the "B" stands for "bus". It's a serial bus, not a serial port.
    Lawrence D'Oliveiro, Apr 12, 2009

    I didn't realise people were still posting on this thread and have
    spent the last 3 hours trying to get some example code to create a
    pseudo TTY (pty) in Python, I get that I have to use the pty module,
    but finding an example is like searching for... lets go festing
    easter egg in a forest ;)

    You wouldn't have any pointers to initiating a PTY and how to write to
    it? This is all I want to achieve.

    My point in all this is actually that I ordered a USB GPS Receiver and
    it wont arrive for another two weeks, being my impatient self, I am
    writing an app for my iPhone to broadcast its GPS location over the
    network to my laptop. I then want to get this data into the NMEA
    format and push this data onto a PTY - this will in-effect replace the
    USB GPS Receiver and the GPS software can read it :)

    Stuart Davenport, Apr 12, 2009
  12. Lawrence D'Oliveiro, Apr 13, 2009
  13. It is a serial protocol, but it is a shared bus-based protocol, in
    contrast to the 1<>1 protocol used by serial ports.
    Wulfraed Dennis Lee Bieber KD6MOG

    (Bestiaria Support Staff: )
    Dennis Lee Bieber, Apr 15, 2009
  14. Stuart Davenport

    JanC Guest

    I just bought one myself a couple of weeks ago. They sell them at 10-13
    euro on computer fairs these days, that's too cheap to not buy one... ;)
    Well, on normal linux/unix systems it would be easy, as in general
    applications there use 'gpsd'[1] to access GPS data, which you can then
    access from every application (instead of one application monopolizing the
    serial port) and it even supports access over TCP/IP.

    I don't know if gpsd works on Mac OS X[2] and the iPhone *and* with your
    application though (it doesn't emulate a serial port, so I think not...).

    Applications shouldn't monopolize a resource like a GPS without giving
    access to the data for others (like gpsd does)...

    [1] <>
    [2] well, [1] says that it does, but is not officially supported
    JanC, Apr 16, 2009
  15. Stuart Davenport

    Roberto Walles

    Jul 18, 2016
    Likes Received:
    Hi Stuart! It's easy to create a virtual serial port with a special software like Virtual Null Modem. I'm using it for emulating real serial port, creating virtual COM port pairs and controlling own application. It's not free, but you have 14 days for trial this soft.
    Good luck in your work!
    Roberto Walles, Jul 18, 2016
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.