LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-05-2012, 04:28 AM   #1
reszj
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
Lightbulb Virtual serial port?


Hi,
I have a little .c program which read data from a serial a port.
If I use a PC where is a serial port with the machine connected to the port than I can read the data.
The problem is that on my laptop, I don't have serial port. Can I simulate a serial port where I send some data and my .c program will read from there like he read from a real serial port.
I need this option because I want to test my .c program on my laptop because I can't access the PC with the serial port and with the machine which is connected to the port.

Thanks for reply
 
Old 10-05-2012, 06:39 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,892

Rep: Reputation: 745Reputation: 745Reputation: 745Reputation: 745Reputation: 745Reputation: 745Reputation: 745
No actual experience using it.

http://www.linuxquestions.org/questi...-linux-797851/
http://tty0tty.sourceforge.net/
 
Old 10-05-2012, 08:59 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
What you're looking for are pseudo terminals. See man pty

The BSD style ones are no longer supported; life was very easy with them. If you have an old distro (RH7 or so) they are still there. I personally find the unix98 style ones far more complicated.

Use tty0tty as indicated above; if you use the code from the linuxquestions link, it will throw a warning, so you might be better of with the sourceforge link (not checked).

Code:
wim@i3-2120:~/tty0tty$ gcc -Wall -O2 -D_GNU_SOURCE tty0tty.c -o tty0tty
tty0tty.c: In function ‘main’:
tty0tty.c:66:32: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
tty0tty.c:68:32: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
wim@i3-2120:~/tty0tty$ ls -l
total 16
-rwxrwxr-x 1 wim wim 8896 Oct  5 15:34 tty0tty
-rw-rw-r-- 1 wim wim 1075 Oct  5 15:34 tty0tty.c
Once you have an executable tty0tty, you can start it

Code:
wim@i3-2120:~/tty0tty$ ./tty0tty 
(/dev/pts/2) <=> (/dev/pts/3)
Keep it running!

Use a terminal program (e.g minicom) to use one of the two (e.g /dev/pts/2). Use your application to use the other one (e.g. /dev/pts/3).

Code:
wim@i3-2120:~$ minicom -p /dev/pts/2
Note:
you might need to configure minicom so it does not send ATZ commands

Last edited by Wim Sturkenboom; 10-05-2012 at 09:00 AM.
 
Old 10-05-2012, 09:54 PM   #4
jefro
Guru
 
Registered: Mar 2008
Posts: 11,524

Rep: Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404Reputation: 1404
Be careful on laptops and many desktops. Some have legacy parts or code that makes some apps think there really is a com1 and com2 installed.\

I think you need to test this in a virtual machine maybe or a real system that is configured like you need. Also test it with higher com port numbers such as one might find in a usb to serial adapter.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual disk/node port for serial buffer balaqemu Linux - Newbie 1 10-21-2011 11:07 AM
How to create a virtual serial/COM port in Linux archShade Linux - General 8 06-12-2010 09:51 AM
access virtual box serial port from host wykthorr Linux - Virtualization and Cloud 2 04-05-2010 11:42 PM
Serial Port Programming/virtual Device MikeGra Programming 3 04-16-2006 03:35 PM
Virtual serial port over TCP/IP ericcarlson Linux - Software 0 11-10-2004 05:39 AM


All times are GMT -5. The time now is 04:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration