Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am looking to create virtual serial ports on Debian 6 squeeze. Basic requirements are:

  1. be able to connect as if port was a real serial port( IE be able to set baud, stop bits etc)

  2. com port pairs need to be persistent

  3. com port pairs names must be static on reboot. I don't want to change code settings each time computer is rebooted

I briefly tried socat today using socat -d -d pty, raw, echo=1 pty, raw, echo=1 that successfully created /dev/pts/5 and /dev/pts/6 as a pair. However soon as I close the terminal running socat the pair is terminated. I am also wondering if tty0tty is an option? I have used com0com in the past with windows with great success.

My question is what is the best way to create a null modem pair so that I can simulate several com ports in Linux?

share|improve this question
    
What is it that you are really trying to do? Most programs don't care if they are connected to a serial port, a tty, a pipe, or a network socket. –  psusi Feb 4 '13 at 17:12
    
I have several sensors that I will be connecting to. Right now I do not have the physical sensors so I must simulate with sample data. sensors will connect to a serial port so I am trying to keep everything as much like the real sensor as possible. IE be able to set baud, stop bits, etc –  Richard Feb 4 '13 at 17:45
add comment

3 Answers

I am thinking this solution will not be "persistent" however names will be static even though they are symbolic. socat will continue to run after terminal is closed thanks to Kotte's answer

socat -d -d PTY,link=/home/someuser/COM0 PTY,link=/home/someuser/COM1 & disown
share|improve this answer
add comment

Stop bits only exist if you have an actual UART so there's nothing there to simulate. Baud rate is simply the upper limit on how fast you can transfer data, so when you are writing your simulation program, you simply have it limit its data rate to the appropriate speed. Then you can connect the simulator to the consuming program with a plain old pipe or fifo.

There is no reason to bother with a pseudo tty since they don't actually do anything with the baud rate and other parameters, they just pass it on for backward compatibility.

share|improve this answer
add comment

If you close the terminal you will also kill socat.

Try running it with

socat -d -d pty, raw, echo=1 pty, raw, echo=1 &
disown

Then you should be able to close the terminal

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.