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...

    Cheers
    Stu
    Stuart Davenport, Apr 10, 2009
    #1
    1. Advertising

  2. On 10 Apr, 20:45, Scott David Daniels <> wrote:
    > Stuart Davenport wrote:
    > > 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...

    >
    > > Cheers
    > > Stu

    >
    > Well, search for Smart Questions.  I have no idea what your OS is, nor
    > what level of "virtual serial port" you want/need.  All anyone could
    > do with your current request is guess what you need and try to steer you
    > towards it.
    >
    > --Scott David Daniels
    >


    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
    #2
    1. Advertising

  3. In message <e454b840-2361-413f-
    >, Stuart Davenport wrote:

    > Then the GPS program I have running on my MAC, RouteBuddy, can read the
    > data from that serial port as standard.


    Macs don't have serial ports.
    Lawrence D'Oliveiro, Apr 11, 2009
    #3
  4. On 11 Apr, 08:52, Scott David Daniels <> wrote:
    > Stuart Davenport wrote:
    > > ... 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?

    >
    > OK, this is a Max OS/X question.  Does "RouteBuddy" have any other way
    > to get data except from the serial port?  Does the mac have a serial
    > port?or are you talking "serial port over USB" (which would be an
    > entirely different kettle of fish).  With that out of the wa, I'd try
    > to ask some Mac guys if the ponying up is possible, and if so how to
    > do it in _any_ language (likely they'll have an Objective C way).
    > Then pop back over here (or even better a python-mac list, where
    > they'll be familiar with how to do lots of stuff) and you can get
    > help getting python to either do the same thing or talk to a bit
    > of code that does the byte-transfers.
    >
    > --Scott David Daniels
    >


    Sadly RouteBuddy cannot retrieve data by other means...

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

    Stu
    Stuart Davenport, Apr 11, 2009
    #4
  5. Stuart Davenport

    Ned Deily Guest

    In article <>,
    Scott David Daniels <> wrote:
    > This part I actually understand. The OP has a program named
    > "RouteBuddy" that talks to a device over a serial port, and he
    > want to repalce the data stream coming from that device. My
    > question is, "where does the device that he wants to replace
    > plug in?" I don't see anywhere on my laptop I could plug in
    > anything but a USB connector, an ethernet connector, a firewire
    > connector, headphones, speakers, a display connector, or a
    > power cord.


    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,
    Ned Deily, Apr 11, 2009
    #5
  6. On Sat, 11 Apr 2009 12:05:21 -0500, Grant Edwards <>
    declaimed the following in gmane.comp.python.general:

    > The data comes in on the TCP/IP network.
    >
    > The OP wants to send that data to a program called RouteBuddy.
    >
    > RouteBuddy will only read data from a serial port.
    >
    > The phrase "that serial port" in the text which you quote
    > refers to the virtual serial port that the elided text says the
    > OP wants to create.
    >
    > The OP wants what is called a "serial port redirector" in
    > Windows-speak. It's a program that routes data between a
    > network connection (often a TCP/IP connection that implements
    > RFC2217) and what appears to other programs to be a normal
    > serial port device API.
    >
    > You can write a port redirector in user-space in MS-Windows,
    > but you can't in Linux/Unix. On Unix systems you have to write
    > a kernel module that sits below the tty layer. The tty layer
    > is what user applications talk to with open/close/read/write/ioctl
    > calls.


    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

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Apr 11, 2009
    #6
  7. Stuart Davenport

    Ned Deily Guest

    In article <>,
    Grant Edwards <> wrote:
    > On 2009-04-11, Ned Deily <> wrote:
    > > In article <>,
    > > Scott David Daniels <> wrote:
    > >> This part I actually understand. The OP has a program named
    > >> "RouteBuddy" that talks to a device over a serial port, and he
    > >> want to repalce the data stream coming from that device. My
    > >> question is, "where does the device that he wants to replace
    > >> plug in?" I don't see anywhere on my laptop I could plug in
    > >> anything but a USB connector, an ethernet connector, a firewire
    > >> connector, headphones, speakers, a display connector, or a
    > >> power cord.

    > > 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.

    > True, but that doesn't help the OP, where the data is coming
    > into the OS-X machine via a network connection.


    Also true but I just wanted to use "headless" in a python post.

    --
    Ned Deily,
    Ned Deily, Apr 11, 2009
    #7
  8. Stuart Davenport

    JanC Guest

    Scott David Daniels wrote:

    > I'ms confused by this statement. What physical connector does your
    > "serial port" use to get the serial data to the Mac? I only have one
    > 3-year old Mac laptop to look at, and I just don't see anything that I
    > would call a serial port.


    USB *is* a serial port... that's what the "S" stands for. ;)


    --
    JanC
    JanC, Apr 12, 2009
    #8
  9. Stuart Davenport

    JanC Guest

    Grant Edwards wrote:

    > On 2009-04-10, Stuart Davenport <> wrote:
    >
    >> I am trying to work out if its possible, to create a virtual serial
    >> port with Python?

    >
    > On Linux: no.


    I wonder if there is no way to emulate ptys from userspace?
    (Like you can use FUSE to implement filesystems in python.)


    --
    JanC
    JanC, Apr 12, 2009
    #9
  10. In message <grrmlu$nqt$>, JanC wrote:

    > USB *is* a serial port... that's what the "S" stands for. ;)


    And the "B" stands for "bus". It's a serial bus, not a serial port.
    Lawrence D'Oliveiro, Apr 12, 2009
    #10
  11. On Apr 11, 6:56 pm, Grant Edwards <> wrote:
    > On 2009-04-11, Grant Edwards <> wrote:
    >
    > > You can write a port redirector in user-space in MS-Windows,
    > > but you can't in Linux/Unix.  On Unix systems you have to
    > > write a kernel module that sits below the tty layer.

    >
    > Perhaps I should elucidate further.
    >
    > That's what the "pty" driver on Unix is: a kernel module that
    > sits underneath the tty layer where the "normal" serial-port
    > UART drivers sit.
    >
    > However, Unix pty drivers only handles a subset of the normal
    > serial-port API.  [I'm not sure why pty drivers have never been
    > "finished" so that they fully emulate a serial port, but it's
    > been that way for 20+ years].
    >
    > If RouteBuddy doesn't try to do things like get/set modem
    > control/status lines, then the OP might be able to use a pty.
    >
    > Each pty consists of two devices: a master end and a slave end.
    > RouteBuddy would be told to use the slave end, and the OP would
    > write a program that would transfer data between a network
    > connection and the master end.
    >
    > A pty devices is what is used by programs like xterm to run
    > programs like bash.  Xterm transfers data between a network
    > connection and the master end of a pty.  Bash is connected to
    > the slave end of that pty and "thinks" it's connected to a
    > serial port.  Bash uses little of the serial port API, so it's
    > happy with the limited API provided by a pty slave-end.
    >
    > --
    > Grant


    Grant - HERO! THIS EXACTLY WHAT I WANT TO DO...

    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 ...an
    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 :)

    Cheers
    Stu
    Stuart Davenport, Apr 12, 2009
    #11
  12. In message <>, Grant
    Edwards wrote:

    > On Linux: no.


    What about this <http://www.tibbo.com/vspdl.php>.
    Lawrence D'Oliveiro, Apr 13, 2009
    #12
  13. On Sun, 12 Apr 2009 03:20:30 +0000 (UTC), JanC <>
    declaimed the following in gmane.comp.python.general:

    >
    > USB *is* a serial port... that's what the "S" stands for. ;)
    >

    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

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Apr 15, 2009
    #13
  14. Stuart Davenport

    JanC Guest

    Stuart Davenport wrote:

    > My point in all this is actually that I ordered a USB GPS Receiver and


    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... ;)

    > 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 :)


    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] <http://gpsd.berlios.de/>
    [2] well, [1] says that it does, but is not officially supported

    --
    JanC
    JanC, Apr 16, 2009
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paolino
    Replies:
    8
    Views:
    960
    Andrew Thompson
    Aug 5, 2005
  2. Pom
    Replies:
    2
    Views:
    1,651
    Bas-i
    Jan 31, 2007
  3. Replies:
    4
    Views:
    2,063
    marina_dan
    Oct 31, 2011
  4. Max Kotasek
    Replies:
    4
    Views:
    979
    Max Kotasek
    Apr 9, 2010
  5. msalerno
    Replies:
    3
    Views:
    409
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page