Communication between two computers using Null Modem Serial Port Connectin
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
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.
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 ...
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.
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).
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.