# Emulate serial port

## elestedt

Hi,

I've got a special need, which I have been unable to solve with the help of Google and 'Quick Search'  :Very Happy: 

What I've got is some special software which communicates with another piece of special software over a serial cable.

And what I need is for these two pieces of software not to use up serial ports, hence I need some construct which emulates

a full UART inside Linux.

I've tried using BSD PTYs but with no success. The software uses the parity in a special way, and since the PTY does not

seem to emulate the parity handling of a UART it will not work.

I might be able to solve the problem with software such as QEMU, but would rather just use a chroot jail.

Anyone have any ideas on how to do this?

Thanks in advance

----------

## cchildress

I'm not sure exactly what you're trying to work with, but have you tried a serial port emulator for USB?  I'm not sure if they have one that is supported by the Linux kernel, but it might be something to look into.

----------

## NeddySeagoon

elestedt,

Have you tried using pipes for the serial I/O

What does 'uses the partity a special way mean'?

The sender can control a real UART to set even|odd|mark|space parity but its a really bad Idea to change it when communications are underway as it must be changed at the receiving end at the same time. As UARTs have buffers now, you must be sure the buffers are empty when you make changes.

----------

## elestedt

cchildress: USB emulators are not really a solution which works for me, since I'd need 32 of them.

NeddySeagoon: I agree that it is a bad idea to do that, but the protocol which is used is designed for old hardware where UARTs weren't available - hence control of all 9 databits (between the start and stop bits) were available.

This protocol uses the paritybit as data carrier. And since the pipes and BSD PTYs do not have any parity that would be fatal for data transmission.

----------

## cwr

If you have the sources, then it's fairly easy to re-link them with a library

that will pretend to be a UART, and in fact write to and from a file.

If you don't have the sources, then surely you could just write to and

from a tty, with some sort of listener on the tty.  ISTR Linux has 64 ttys

by default, and I think you can rebuild the kernel to have more.

Will

----------

## NeddySeagoon

cwr,

Thats a truly horrible interface. It can never work with a real UART. The software that sends and receives the data must read bytes from somewhere, repack 9 bytes into 8 symbols for transmission over the data link then do the reverse at the receiving end.

As it does not use a UART, I suspect it has a special interface of some sort.

This software must predate the IBM PC

It sounds like if you don't have the sources you are out of luck unless you are willing to reverse engineer the packages.

----------

## wjb

 :Evil or Very Mad: 

This is fairly hideous example: Use The PC's UART With 9-Bit Protocols (slow to load)

You could maybe have all 8 databits and also use the parity bit if you can change the parity setting on the fly. You would probably have to disable the FIFOs on modern(?) UARTS to stand a chance at this. You also need to be able to read the databits that did arrive, even if there was a parity error. And you need there to be no real parity errors (not hard, I've never seen any real ones ever).

e.g. you'd set the clients to, say, even parity. Then for the server

- If you want the 9th bit clear

look at the 8 data bits

you want even parity to arrive the other end, so if the 8 bits are even parity set the UART to even, otherwise set the UART to odd.

send the byte

the client gets that without a parity error. Interprets it as a 0.

- If you want the 9th bit set,

look at the 8 data bits

you want odd parity to arrive the other end, so if the 8 bits are even parity set the UART to odd, otherwise set the UART to even.

send the byte

the client gets that with a parity error. Interprets it as a 1.

Oh yeah, its strictly one-way. Server to client. Or is it?? Mad scientists only.

Good luck.

----------

## cwr

Checking the termios man page, it looks as if you could, with some cursing

and hammering, put together something that read and wrote byte parities.

Linux currently has Unix98 ptys, so you can have as many pairs as you want.

Will

----------

## McTango

Maybe this could help...

http://www.tibbo.com/vspdl.php

Greetings.

----------

