LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2012, 03:44 AM   #1
Leena
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Displaying I/O possible when reading data from the tty(serial) port in Fedora


Hi
I have got a problem while reading from the serial port. Whenever I'm trying to read any data through the serial port, it's displaying I/O Possible and the application is being terminated in Fedora.I have highlighted that line in the code Though the same code works fine in RHEL. Kindly advice. Here are snippets of my code

void Serialinit()
{
struct termios options;
printf("\nSerial Port is open\n");
portfd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
if (portfd == -1) {
/* Could not open the port.*/
perror("open_port: Unable to open /dev/ttyS0 - ");
}

options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cflag = B4800|CS8|CLOCAL|CREAD;
options.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
tcflush(portfd,TCIFLUSH);
fcntl(portfd, F_SETFL, FASYNC);

if(tcsetattr(portfd, TCSANOW, &options))
{
perror("cannot set the attributes\n");
}
tcflush(portfd, TCIOFLUSH);

}
then in main

do
{
int no_of_char_read = 0;

no_of_char_read =read(portfd, &datas,1);

//printf("datas:%x\n", datas);

if(count < 0)
count = 0;
buffers[count] = datas; // store in buffers array
printf("buffers[%d]: %x\n", count, buffers[count]);

}

Last edited by Leena; 01-13-2012 at 03:46 AM.
 
Old 01-14-2012, 06:46 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
Hi Leena, I actually replied to this in the other thread, but I'll add it here as well. You either need to turn off NDELAY before doing your read or you need to check your error and see if it is EAGAIN in the loop and not exit out of the loop if it is EAGAIN. NDELAY just tells the read turn return immediately if there is no data with the EAGAIN error (which I'm guessing is what is getting translated into I/O possible for you).
 
  


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
Displaying I/O possible when reading data from the serial port makphy Programming 9 06-18-2013 05:14 AM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 06:10 AM
help reading data from a serial port skydemon Linux - General 1 08-10-2006 08:48 AM
reading data from a serial port mchitrakar Linux - Networking 3 12-04-2004 01:24 PM


All times are GMT -5. The time now is 01:08 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration