LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Displaying I/O possible when reading data from the tty(serial) port in Fedora (https://www.linuxquestions.org/questions/linux-newbie-8/displaying-i-o-possible-when-reading-data-from-the-tty-serial-port-in-fedora-923560/)

Leena 01-13-2012 03:44 AM

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]);

}

estabroo 01-14-2012 06:46 PM

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).


All times are GMT -5. The time now is 03:19 AM.