Networking Forums

Networking Forums > Computer Networking > Linux Networking > Simulating a serial port

Reply
Thread Tools Display Modes

Simulating a serial port

 
 
Gonzales Valero Daniel
Guest
Posts: n/a

 
      11-06-2003, 10:51 AM
Hi *,

I have an application which tries to connect to a serial terminal. I
want to create a "virtual serial terminal" which I can redirect to a
socket interface.

Specifically, what I want to do is to convert the following system:


System 1

Application <-------> serial terminal <-----> target


As you can see, the application is running on the same computer where
the target is connected to. This must be converted to the following system:



Sytem 2

Application <---------> virtual serial terminal* <--------\
|
|
|
network
|
|
|
Target <----> serial terminal <------> serproxy <----------/




The advantage of Sytem 2 is that the application can run in any computer
which has network access to the computer which is connected to the target.

The serproxy component is an open source application which offers a
socket connection for each serial interface present in the system.

The component marked with a * (the virtual serial terminal) is the one
which I need to implement. It must offer bidirectinal communication, and
it must fully emulate a serial port: the application must not be aware
that it is not a real serial port, but an emulation.

I was thinking about implementing this functionality using telnet or
ssh, but I am not sure about the details.

Could somebody give me details or references about a similar implemention?


Thanks all,

Daniel

 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a

 
      11-06-2003, 02:37 PM
In article <(E-Mail Removed)>, Gonzales Valero Daniel wrote:

> I have an application which tries to connect to a serial terminal. I
> want to create a "virtual serial terminal" which I can redirect to a
> socket interface.


That's sort of what the pty (pseudo-terminal) device driver does. There's
one device that looks to the application like a serial prot (tty device) and
a second device that's connected to the first device.

--
Grant Edwards grante Yow! Where's th' DAFFY
at DUCK EXHIBIT??
visi.com
 
Reply With Quote
 
Neil Horman
Guest
Posts: n/a

 
      11-06-2003, 06:15 PM
Grant Edwards wrote:
> In article <(E-Mail Removed)>, Gonzales Valero Daniel wrote:
>
>
>>I have an application which tries to connect to a serial terminal. I
>>want to create a "virtual serial terminal" which I can redirect to a
>>socket interface.

>
>
> That's sort of what the pty (pseudo-terminal) device driver does. There's
> one device that looks to the application like a serial prot (tty device) and
> a second device that's connected to the first device.
>

More than sort of, thats exactly what ptys do. In fact this is how
telnet is implemented.
Neil

--
/************************************************** *
*Neil Horman
*Software Engineer
*Red Hat, Inc., www.redhat.com
*gpg keyid: 1024D / 0x92A74FA1
*http://www.keyserver.net
************************************************** */

 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a

 
      11-06-2003, 06:56 PM
In article <boe7le$a1m$(E-Mail Removed)>, Neil Horman wrote:

>>>I have an application which tries to connect to a serial terminal. I
>>>want to create a "virtual serial terminal" which I can redirect to a
>>>socket interface.

>>
>> That's sort of what the pty (pseudo-terminal) device driver does.
>> There's one device that looks to the application like a serial prot (tty
>> device) and a second device that's connected to the first device.
>>

> More than sort of, thats exactly what ptys do.


Except for the "socket" part. The "other end" of a pty is a char device
rather than a socket -- so he'll have to write some code to shovel data back
and forth between the pty master device and the socket. He might be able to
use netcat for that, and the whole thing could be done in a small shell
script. At least I think it could have been done with a shell-script with
"old" pty's I don't remember the new pty API well enough to say for sure if
you could avoid writing any C code or not. The OP should definitely read up
on ptys and netcat.

> In fact this is how telnet is implemented.


And ssh, and rlogin, and abut a hundred different flavors of X terminals.

--
Grant Edwards grante Yow! Where's th' DAFFY
at DUCK EXHIBIT??
visi.com
 
Reply With Quote
 
Gonzales Valero Daniel
Guest
Posts: n/a

 
      11-07-2003, 09:11 AM
Hi *,


Thanks for your insightfull answers. I was already suspicious about the
ptys when I read your answers, and they were a great confirmation to
those suspicions.

I am planning to use netcat in the following way:

I will do something like:

netcat host_running_serproxy port_for_COM1 <> /dev/ptyp0


I do a double redirection (<>) to the master pty to support
bidirectional communication. Since I am not very familiar with ptys, I
have the following questions:

1 - Is the double redirection a good idea at all?

2 - Can I connect with the master pty and later use the slave pty *and*
expect that things are reliably working? What I have seen up to now is
that usually master and slave pty are opened at the same time and that a
parent and child process use the both ends to communicate; in my case I
want two completely independent processes to communicate via the pty,
which I do not know if is at all supported by the pty architecture.




I am facing a further problem, which probably does not belong to this
newsgroup. But since you are already aware of my application, I will
post here the message which I have already posted to the relevant
newsgroup (c.e.m-w.wine)

I summarize it for you: the application which must use the slave pty is
a windows application which must be fooled into believing that a given
pty is COM1. The problem that I face is that although I correctly
configure Wine for that, it seems that my application is not using the
pty at all. You can find the exact details in the text below.


Thanks again,

Daniel




Hi *,

I have a windows application which tries to connect to a serial terminal
(System A). I want to run this application differently: I want to run it
on a computer which is not directly connected to the terminal. Instead
of doing this using windows systems, I have decided to do it with linux
using network facilities already present. (System B). The Host X, which
has the real terminal, will remain a windows host, though.

---------------------------------------------------------------------------

System A

Application (Host X, windows) <----> serial itf (COM1) <---> target


As you can see, the application is running on the same computer where
the target is connected to. This must be converted to the following system:

---------------------------------------------------------------------------


Sytem 2

Appl. (with Wine, in Host Y, linux) <--> pty <--> netcat <-\
|
|
|
network
|
|
|
Target <--> serial itf <--> serproxy (Host X, windows) <--/


---------------------------------------------------------------------------


The advantage of Sytem 2 is that the application can run in any computer
which has network access to the computer which is connected to the target.




What I have done is:

1) Publish the serial interface present in the windows host (Host X)
with an open source application called serproxy. This will create
sockets for all serial interfaces present in the Host X, and will listen
for incoming connection, establishing then a bidirectional connection to
the serial port.

2) Prepare the linux host (Host Y) so that the windows application can
be run with Wine.

3) Route one of the pseudo terminals (pty) in the linux host to the
socket published by the windows host, using netcat.


The problem that I face is the following:

The application running under wine in the linux Host is trying to
establish a connection with a serial port. I want to fool Wine so that
it uses a pseudo terminal instead of a real serial terminal. I do this
by having the following line in config:

[serialports]
"Com1" = "/dev/ttyp0"

That is, I tell Wine that it must use the slave tty 0 as COM1.


I have the following worries about the current configuration:

1 - the application scans the serial interface using different
baud-rates to try to find the target. This would normally happen in
System A configuration; the problem is that in System B, i do not see
any kind of traffic coming via the pseudo terminal, which makes me
suspicious about whether Wine is really trying to use the ptys as serial
ports. To check the data going via the pseudo terminal, I have done the
following:

netcat -l -p 2000 ; netcat localhost 2000 <> /dev/ptyp0


2 - For the ptys there is no concept of "baud rate" (afaik). What is the
application trying to configure when there is nothing to configure?

3 - It could be that I am completely wrong here. Is there any support in
Wine for pseudo-terminals?


Thanks,


Daniel






Grant Edwards wrote:
> In article <boe7le$a1m$(E-Mail Removed)>, Neil Horman wrote:
>
>
>>>>I have an application which tries to connect to a serial terminal. I
>>>>want to create a "virtual serial terminal" which I can redirect to a
>>>>socket interface.
>>>
>>>That's sort of what the pty (pseudo-terminal) device driver does.
>>>There's one device that looks to the application like a serial prot (tty
>>>device) and a second device that's connected to the first device.
>>>

>>
>>More than sort of, thats exactly what ptys do.

>
>
> Except for the "socket" part. The "other end" of a pty is a char device
> rather than a socket -- so he'll have to write some code to shovel data back
> and forth between the pty master device and the socket. He might be able to
> use netcat for that, and the whole thing could be done in a small shell
> script. At least I think it could have been done with a shell-script with
> "old" pty's I don't remember the new pty API well enough to say for sure if
> you could avoid writing any C code or not. The OP should definitely read up
> on ptys and netcat.
>
>
>>In fact this is how telnet is implemented.

>
>
> And ssh, and rlogin, and abut a hundred different flavors of X terminals.
>

 
Reply With Quote
 
Martin Blume
Guest
Posts: n/a

 
      11-07-2003, 11:09 AM

"Gonzales Valero Daniel" <ext-daniel.gonzales-(E-Mail Removed)>
> Hi *,
>
> I have an application which tries to connect to a serial
> terminal. I want to create a "virtual serial terminal" which I
> can redirect to a socket interface.
>


Is it that what you're looking for:

***
*** Filename : net2tty.c
*** Purpose : TCP socket <-> RS232 bridge
*** Author : Matt J. Gumbley
*** Last updated : 22/05/99
*** Notes : Connects to a port at a host, opens a tty,
*** sets the baud rate, and sends any data
*** coming in over the socket to
*** the tty, and sends any data received from
*** the tty to the socket.
***

Don't know where I got it from, just google for it.

HTH. YMMV.
Martin



 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a

 
      11-07-2003, 02:55 PM
In article <3fab8c1f$0$3678$(E-Mail Removed)>, Martin Blume wrote:
>
> "Gonzales Valero Daniel" <ext-daniel.gonzales-(E-Mail Removed)>
>> Hi *,
>>
>> I have an application which tries to connect to a serial
>> terminal. I want to create a "virtual serial terminal" which I
>> can redirect to a socket interface.
>>

>
> Is it that what you're looking for:
>
> ***
> *** Filename : net2tty.c
> *** Purpose : TCP socket <-> RS232 bridge
> *** Author : Matt J. Gumbley
> *** Last updated : 22/05/99
> *** Notes : Connects to a port at a host, opens a tty,
> *** sets the baud rate, and sends any data
> *** coming in over the socket to
> *** the tty, and sends any data received from
> *** the tty to the socket.
> ***


That doesn't sound like what the OP wanted to me. He doesn't want to
connect a socket to a tty. He wants to connect a socket to the master end
of a pty. Perhaps it will work anyway, but I think trying to set the baud
rate on the master end of a pty will generate an error, since that end isn't
emulating a tty device like the slave end.

Disclaimer: There's about a 40% chance I've got the "slave" and "master"
names backwards when I talk about pty's.

--
Grant Edwards grante Yow! Where's th' DAFFY
at DUCK EXHIBIT??
visi.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
no serial port and no parrallel port how do i console to a router sloan949@gmail.com Linux Networking 4 02-13-2007 07:02 PM
Map serial port through TS Tippy Windows Networking 0 11-23-2005 12:06 AM
Serial Port Multiplexing (2 apps to 1 port) Onslo Linux Networking 0 10-06-2004 08:53 AM
serial port characteristics WWW Linux Networking 10 01-26-2004 09:00 PM
programming serial port Carmin Linux Networking 11 11-20-2003 01:32 AM



1 2 3 4 5 6 7 8 9 10 11