[x] Welcome to LinuxSolved.com Linux help forums, here we are a community of Linux users helping each other. It is helpful to both ie. new linux users as well experienced one. We always have our experts to help you and ofcourse members help each other, so you can ask for help any time by Registering.: Click to Register

Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Linux Forums - Linux Help,Advice & support community:LinuxSolved.com  |  Forum  |  Network Troublshooting  |  General Networking Support in Linux  |  Topic: Serial port transfer
The LinuxSolved.com GNU/Linux User Communit - Forum
Welcome to LinuxCommunity You have just arrived to a friendly linux community which is helping Linux Users from Years.. You can be its part if you have not already joined it. Registration is FREE and is gateway to unlimited help and support to all your linux related needs. If you are an GNU/Linux supporter then you have come to the right place.
Pages: [1]
  Print  
Author Topic: Serial port transfer  (Read 622 times)
0 Members and 1 Guest are viewing this topic.
tklima
New Member

Offline Offline

Posts: 1


View Profile
« on: January 12, 2005, 09:10:29 AM »

Hi all,
i'm writting a programm to transfer data via serial port. I'd like to test it on my computer first, so i connected serial ports and wrote a simple program just to check the connection. I write one character into ttyS0 and want to read it from ttyS1. Writing works OK (numb_send = 1) but there is some problem with reading (numb_rec = -1). I think, port settings are OK.

ttyS0: Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4
Baud_base: 115200, close_delay: 50, divisor: 0, closing_wait: 3000

ttyS1: Line 1, UART: 16550A, Port: 0x02f8, IRQ: 3
Baud_base: 115200, close_delay: 50, divisor: 0, closing_wait: 3000

Shall I set anything else? Thank you for your advise.


#include <stdio.h>
#include <sys/signal.h>
#include <sys/types.h>


int main(void) {
        
   int fd1, fd2;
   int numb_send,numb_rec;
    char c;
   char buf[5];        

     fd1 = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
       if (fd1 < 0)      {
     //perror(devicename);
          exit(-1);
     }

     fd2 = open("/dev/ttyS1", O_RDWR | O_NOCTTY | O_NONBLOCK);
        if (fd2 < 0)      {
     //perror(devicename);
           exit(-1);
        }



   scanf("%c",&c);
        numb_send = write(fd1,&c,1);  
        numb_rec = read(fd2,buf,sizeof(buf));
   printf("sent: %d\n received: %d\n",numb_send,numb_rec);
   printf("%s\n",buf);
   close(fd1);
   close(fd2);
}
Logged
Linux Forums - Linux Help,Advice & support community:LinuxSolved.com
   

 Logged
Pages: [1]
  Print  
 
Jump to:  

Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 06:40:28 PM

Login with username, password and session length
Navigation
Recent Discussions
[November 19, 2008, 07:52:49 PM]

[November 19, 2008, 07:52:41 PM]

[November 19, 2008, 07:52:36 PM]

[November 17, 2008, 10:42:59 AM]

[November 16, 2008, 12:49:47 AM]

[November 16, 2008, 12:48:58 AM]

[November 15, 2008, 08:29:02 AM]

[November 15, 2008, 08:24:41 AM]

[November 14, 2008, 05:11:50 AM]

[November 13, 2008, 03:28:22 AM]
Members
Total Members: 6220
Latest: ahsanjee
Stats
Total Posts: 8268
Total Topics: 2253
Online Today: 13
Online Ever: 111
(June 28, 2007, 06:47:29 AM)
Users Online
Users: 0
Guests: 9
Total: 9
Privacy Policy| Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks
Theme & TinyPortal v0.9.8 © Bloc