Page 1 of 1

Write "Input/output error" after Timeperiod on Fre

Posted: Tue Mar 18, 2008 9:24 am
by jprinzler
Hello !

I hope you can understand me. My english is bad ;-(

Since one week i have portet my linux server to freebsd 6.3 server.

Now i must compile my source to connect my LCD2041 serial display.

The problem is that the write command after time period produce
Input/output error's (code 5). I think it's the problem is initialising the display or full write buffer or another application will work on serial port and chrashes my application ?


Here is my code snipped (without error handling) :


int id = open("/dev/cuad5", O_RDWR|O_NOCTTY);

struct termios portset;

tcgetattr(id, &portset);

cfmakeraw(&portset);

cfsetospeed(&portset, B9600);
cfsetispeed(&portset, B0);

tcsetattr(id, TCSANOW, &portset);

bool bError = false;
int iWritten = 0;
char out[256] = "";

while(!bError)
{
// clear screen
snprintf(out,sizeof(out),"\xFE" "X");
if((iWritten = write(id, out, 2)) != 2)
{
fprintf(stderr,"\nError (%d)... [%d %s]", iWritten, errno, strerror(errno));
bError = true;
}

for(int i=0; i<4 && !bError; i++)
{
// set cursor
snprintf(out,sizeof(out),"\xFE" "G" "%c%c",i,i);
if((iWritten = write(id, out, 4)) != 4)
{
fprintf(stderr,"\nError (%d)... [%d %s]", iWritten, errno, strerror(errno));
bError = true;
}

// write text
if((iWritten = write(id, "0123456789", 10)) != 10)
{
fprintf(stderr,"\nError (%d)... [%d %s]", iWritten, errno, strerror(errno));
bError = true;
}

// waiting a while
// usleep(100000); // 0.1 sec
}
}
}
}

close(id);
}

------->

after a time period betwen 10 minutes to 2 hours the write command in the middle from the script fails an produce error 5 - Input/output error ?

Can someone tell me what i can doing ?

Thanx 4 ever !

...Jaro (from Germany)

Posted: Tue Mar 18, 2008 9:47 am
by Ray
Didn't see any explicit mention of it in your source, so it might be by default but make sure flow control (Xon/Xoff and CTS/RTS) is tunred off.

Posted: Tue Mar 18, 2008 10:04 am
by jprinzler
Ray wrote:Didn't see any explicit mention of it in your source, so it might be by default but make sure flow control (Xon/Xoff and CTS/RTS) is tunred off.
Hello!

Now i have added follow lines...

portset.c_cflag &= ~(CNEW_RTSCTS);
portset.c_iflag &= ~(IXON|IXOFF|IXANY);

I hope thats all and it works ?

Posted: Tue Mar 18, 2008 10:23 am
by Ray
I Hope so too, let me know if its not, I'll try to get a freebsd system and see if i can reproduce the error.

Posted: Wed Mar 19, 2008 6:38 am
by jprinzler
Sorry !

The script is running over night without errors ?! Wow !!
Now after restart the same comes errors back ?! Fu...

Here my logfile...

1903 1328 Starting...
1903 1330 Errror on write (-1) [5 Input/output error]
1903 1330 Exiting...

1903 1353 Starting...
1903 1358 Error on write (-1) [5 Input/output error]
1903 1358 Exiting...

1903 1412 Starting...
1903 1417 Error on write (-1) [5 Input/output error]
1903 1417 Exiting...

Here is my modifyed code :

---> SNIP

int id = open("/dev/cuad5", O_RDWR|O_NOCTTY|O_NONBLOCK);

tcgetattr(id, &options);

// Speed to 9600 baud
cfsetospeed(&options, B9600);
cfsetispeed(&options, B9600);

// RAW Mode
cfmakeraw(&options);

// 8N1 with no Parity
options.c_cflag &= ~(CSIZE|PARENB);
options.c_cflag |= CS8;

// all flow controls off ?
options.c_cflag &= ~(CRTSCTS);
options.c_iflag &= ~(IXON|IXOFF|IXANY);

tcsetattr(id, TCSANOW, &options);

while(write(id, "0123456789", 10) == 10);

close(id);

---> SNIP

Do you have any ideas ?

Thanx...

Posted: Thu Mar 20, 2008 3:20 am
by jprinzler
Hello !

Now i hope this is the solution. The Display works now since
last night without errors.

---> SNIP

tcgetattr(id, &options);

options.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
options.c_oflag &= ~(OPOST);
options.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
options.c_cflag &= ~(CSIZE|PARENB|CRTSCTS);
options.c_cflag |= (CS8|CREAD|CLOCAL);

cfsetospeed(&options, B9600);
cfsetispeed(&options, B0);

tcsetattr(id, TCSANOW, &options);

---> SNIP

Hope, hope, hope...
I have no more any ideas ?!

...Jaro

Posted: Thu Mar 20, 2008 7:23 am
by Ray
Same here :) Since our display doesn't do hardware flow control it can't generate any io errors, so if you still have problems try using a different cable or computer?

Posted: Sat Mar 22, 2008 3:55 am
by jprinzler
I works perfect now ;-)