How to create a virtual serial port?

S

Stuart Davenport

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
 
S

Stuart Davenport

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
(e-mail address removed)

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

Lawrence D'Oliveiro

In message <e454b840-2361-413f-
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.
 
S

Stuart Davenport

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
(e-mail address removed)

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
 
N

Ned Deily

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

Dennis Lee Bieber

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
N

Ned Deily

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

JanC

Scott said:
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. ;)
 
S

Stuart Davenport

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

JanC

Stuart said:
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top