How to create a virtual serial/COM port in Linux
I'm currently working on a project for university that requires communication, via an RS232 link between a piece of hardware (I have designed and am currently testing) and some software(which need testing).
I was hoping to have my hardware finished by now so I could get on with testing the software over Easter.
The hardware does not work yet but I would still like to test the software.
Does any one know if there a way to make a virtual serial port that I could put data on and read data off while my program accesses it as a regular serial port so I can check my code?
I am using Ubuntu 9.10 and am happy to give any more information on request.
PS: I'm sorry if this is in the wrong place I did not know what this type of question came under so I put it in genral
I had thought about using a loop back but the data I wish to simulate coming in is not the same as that going out. I suppose I could get two serial ports and connect RX of one to TX of the other and vice versa.
Would still be nice if I could do it with a virtual port.
I think part of the answer lies in how you intend to create a simulation of the device, and whether the objective is to test the communication channel itself, or to test the 'conversation', the data exchange irrespective of the serial interface. If the latter, you can probably create a useful and simple to deploy simulation by exchanging data through pipes or message queues. A process simulating the device reads and writes data in real time, responding to queries from the project software. If the communications itself is the object of the test, then a second serial port driven by the simulation code seems like a good approach. Simply using a loopback on a single port doesn't sound like it will work, since it is still a single port, which only a single process can open and use.
How you craft your simulator might make as much of a project as the original project. Usually devices do something that relates to real-world events and circumstances, and modeling these is the subject of a lot of science.
First off thanks for the and help.
Seaching the Internet I found this program http://sourceforge.net/projects/ttypatch/ but I keep getting this error.
I think this should show the logic of my project which is what needs to be done (I only have to demonstrate the validity of my idea)
I plan to try this over the weekend wish me luck :)
ttypatch use legacy ptys (bsd style), disabled for security questions in new kernels. You can recompile the kernel with this option enabled and the ttypatch will work.
Other option is use the ptys UNIX_98 style, supported in new kernels.
The code below simulate an serial data connection without control handshake using pty UNIX_98 style, this code work to connect two gtkterm, replacing ttypatch for my tests.
/*compile with : gcc -Wall -O2 -D_GNU_SOURCE tty0tty.c -o tty0tty */
ptym_open(char *pts_name, char *pts_name_s , int pts_namesz)
strncpy(pts_name, "/dev/ptmx", pts_namesz);
pts_name[pts_namesz - 1] = '\0';
fdm = posix_openpt(O_RDWR | O_NONBLOCK);
if (fdm < 0)
if (grantpt(fdm) < 0)
if (unlockpt(fdm) < 0)
if ((ptr = ptsname(fdm)) == NULL)
strncpy(pts_name_s, ptr, pts_namesz);
pts_name[pts_namesz - 1] = '\0';
printf("(%s) <=> (%s)\n",slave1,slave2);
if(read (fd1,&c1,1) == 1) write(fd2,&c1,1);
if(read (fd2,&c2,1) == 1) write(fd1,&c2,1);
same kind of problem
This s regarding my project
I am trying to send data over wifi using socket.
I am working Ubuntu.
The data to be sent is received from a device over serial port.
I want to create a virtual serial
port which will read data from a file and present it in way serial port will present for a given baud rate.
I got same error and also we while running auto testtty.c
the error is couldnt open ttyp0
Also i checked /de there is no file called ptyp0 then how can it open(there is file named ptmx,i think its pseudo terminal)
So can u please tell how to recomplile with kernel permission changed or what should be make file.
This is what make file i have.
[/quote]# Makefile for ttypatch-1.0
# Copyright (c) Daniel G. Clemmensen. Licensed under the GPL.
# trivial makefile, generated manually. Needs to be replaced by full-up
# autoocnf/automake system. We simply make ttypatch and testty.
# This will probably work on most Linux distros, but that's all
all: ttypatch testty autotesttty
gcc -DSTDC_HEADERS=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_UNISTD_H=1 -DRETSIGTYPE=void -DHAVE_SELECT=1 -DHAVE_STRERROR=1 -I. -I. -g -O2 ttypatch.c -o ttypatch
gcc -DSTDC_HEADERS=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_UNISTD_H=1 -DRETSIGTYPE=void -DHAVE_SELECT=1 -DHAVE_STRERROR=1 -I. -I. -g -O2 testty.c -o testty
gcc -DSTDC_HEADERS=1 -DHAVE_SYS_WAIT_H=1 -DHAVE_FCNTL_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_UNISTD_H=1 -DRETSIGTYPE=void -DHAVE_SELECT=1 -DHAVE_STRERROR=1 -I. -I. -g -O2 autotesttty.c -o autotesttty
Also can u please tell me how i can open a ttyp0 slave in other user program and read data from it.
|All times are GMT -5. The time now is 03:40 AM.|