views:

73

answers:

2

I am writing a C program in Linux which will read/write to/from a serial port. I know the data that needs to be read and written on the port but I don't have a serial port to currently test this with.

Is there any way to simulate a serial port? Would reading/writing to a file be sufficient? I can have one process write to the file while another process reads that data and writes back other data to the file. Or are there others tools that can be used to simulate a port?

Thanks

A: 

A character device, even something as simple as normal stdin and stdout should work if you don't care about attributes specific to port devices.

Delan Azabani
+3  A: 

Serial ports on Linux are terminal devices. A close simulation is to create a pseudo-terminal pair; the program that normally talks to the serial port is instead told to open the slave side of the pseudo-terminal, and the simulator writes and reads from the master side.

The pty(7) man page has more information.

caf
Doing this you also get to have another program act as the device at the other end of the serial port.
nategoose