LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2011, 07:30 AM   #1
bhanu001
LQ Newbie
 
Registered: Feb 2008
Location: Pune, Maharastra, India
Posts: 9

Rep: Reputation: 0
Communication between two computers using Null Modem Serial Port Connectin


Hi Everyone,

I'm trying to connect two computers using a serial port (using null modem connection) as shown in the figure below.

On one computer (let's call it sender), i'm opening a serial port connection using open() system call as

Code:
int fd = open("/dev/ttyS0", O_RDONLY | O_NOCTTY | N_NDELAY);
and write data into the port using write() system call as

Code:
char *ptr = new char[SIZE];
int no_of_bytes = write(fd, (void *) ptr, SIZE);
And on the other computer (let's call it receiver), i'm opening a serial port using open() syscall and reading the data using read() syscall as
Code:
char *ptr = new ptr[SIZE];
int no_of_bytes = read(fd, (void *)ptr, SIZE);
When the value of SIZE is less than 20 or so, i'm able to read "all" the bytes in one-go. But when the value exceeds 500 or 1000 Bytes (even 100 B, for that matter), I'm unable to receive all the bytes I've sent on the receiver side, even after repetitive read() syscalls !

So please someone shed some light. And thank you for your time.

Bhanu Kiran C
Attached Thumbnails
Click image for larger version

Name:	nullmodem.jpg
Views:	26
Size:	18.8 KB
ID:	8004  

Last edited by bhanu001; 09-17-2011 at 07:32 AM.
 
Old 09-17-2011, 08:24 AM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
define 'connect', that could mean any of a myriad of things.

in what manner are you attempting to communicate between the two machines?

if you are looking for just a command line then you could accomplish the task with agetty on the 'transmitting' end and minicom on the 'receiving' end

if you are looking for full networking then you need pppd on both ends, i forget exactly how to do it but i have done so.
and yes you are correct to use a null modem.
 
Old 09-19-2011, 01:40 AM   #3
bhanu001
LQ Newbie
 
Registered: Feb 2008
Location: Pune, Maharastra, India
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
define 'connect', that could mean any of a myriad of things.

in what manner are you attempting to communicate between the two machines?
i've soldered a wire (null modem connection) to two female serial pins (one on each end) and connected them to both computers (to male serial plugs, one on each end).

Quote:
if you are looking for just a command line then you could accomplish the task with agetty on the 'transmitting' end and minicom on the 'receiving' end

if you are looking for full networking then you need pppd on both ends, i forget exactly how to do it but i have done so.
and yes you are correct to use a null modem.
I have defined a new structure on one computer (size 3000 bytes, which is obtained by reading some information from a file, doing some processing etc) and i would like to transfer the structure to the other computer using a serial port. And after receiving the data, I would type-cast the data into the structure back again ...

Now can you suggest where I'm doing it wrong ???
 
Old 09-19-2011, 02:09 AM   #4
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
Have you read the serial howto?

http://tldp.org/HOWTO/Serial-HOWTO-4.html

I'm asking this because there are a couple of buffers between your app and the port, and it doesen't matter if you define your variable with a size or another if you are not counting with those buffers and how they are fed. I once did a programing communication with a null modem (long time ago, I don't even remember) but I think there was an issue with those buffers to get the correct hole bytes sent.
 
Old 09-20-2011, 01:55 AM   #5
bhanu001
LQ Newbie
 
Registered: Feb 2008
Location: Pune, Maharastra, India
Posts: 9

Original Poster
Rep: Reputation: 0
Mr. rodrifra,

Quote:
Have you read the serial howto?

http://tldp.org/HOWTO/Serial-HOWTO-4.html
I've gone through the document and checked the baud rates of both the serial links and checked other details too, everything is fine ... even then i'm losing a lot of data (i mean when is send 100 bytes from one side, i receive only 20 bytes or so on the other).

So what else do I need to trouble shoot ?

Many thanks for your participation.

BhanuKiran C
 
Old 09-20-2011, 09:06 AM   #6
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
In the next link you have programming examples, hope that helps.

http://www.lafn.org/~dave/linux/Seri...ng-HOWTO-B.txt
 
Old 09-23-2011, 12:48 AM   #7
bhanu001
LQ Newbie
 
Registered: Feb 2008
Location: Pune, Maharastra, India
Posts: 9

Original Poster
Rep: Reputation: 0
Hi "rodrifra"

Quote:
In the next link you have programming examples, hope that helps.

http://www.lafn.org/~dave/linux/Seri...ng-HOWTO-B.txt
I've followed these tips too, but still I'm losing data. When I send 2000 or more bytes, I receive only 1000 odd bytes.

Please can you suggest some more tips.

Thank you,
BhanuKiran
 
Old 09-23-2011, 06:20 AM   #8
dilbert_uk
Member
 
Registered: Aug 2011
Location: Lima, Peru
Distribution: Debian 10.4, xubuntu 20.04, Ubuntu 20.04 LTS
Posts: 83

Rep: Reputation: 4
I am not sure what "SIZE" is. If that gives a wrong number because it's not portable code or what ever else then maybe you could loose characters. Try to use "strlen()" instead or a constant like buffer size.

Then, if you use the same file descriptor for read and write, did you use the select() function from those how-to examples, too?
 
  


Reply



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
Serial port communication.. brianbek Linux - Software 2 01-23-2006 12:43 PM
serial port communication vidyaraj Linux - Software 2 03-14-2004 11:32 PM
serial port communication vidyaraj Linux - Software 6 03-02-2004 06:46 PM
communication via serial port perdesiz Linux - Software 0 11-13-2003 06:23 AM
serial communication - null modem cable sg3 Linux - Networking 3 07-17-2003 06:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:39 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration