LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 05-04-2005, 01:05 PM   #1
buckles
LQ Newbie
 
Registered: Jun 2003
Posts: 7

Rep: Reputation: 0
Problem w/ 'read' system call - RH 7.3


Hello, all. Here is a snippet of kernel space code written to test read/write of an rs485 interface board. Ports 1 & 2 are connected via a loopback cable. System is Pentium 4 PC running RedHat 7.3
__________________________________________

unsigned char tempChar, buf[255];

...

fs = get_fs();
set_fs(get_ds());

if((fd_ttyS4 = open("/dev/ttyS4", O_RDWR | O_NOCTTY, 0)) < 0)
{
exit(1);
}

if((fd_ttyS5 = open("/dev/ttyS5", O_RDWR | O_NDELAY | O_NONBLOCK , 0)) < 0)
{
exit(1);
}

write(fd_ttyS5,&tempChar, 1)
read(fd_ttyS4,buf,1)

...

______________________________________

Seems simple. The loopback works fine when tempChar is initialized to a value between 0 and 0x7f. But when tempChar is 0x80 or greater, the subsequent read hangs forever. I am new to linux, so maybe I am missing something simple??? Thank you for any help you may provide.

Also, here is how I set the port attributes:

newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;

Last edited by buckles; 05-04-2005 at 01:38 PM.
 
Old 05-04-2005, 03:21 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
Are you only writing/reading one character? It may be a buffering issue. You may flush the port, make the read port non-blocking (and read in a loop).

BTW Are you sure that write was succesful? It may fail.
 
Old 05-04-2005, 03:49 PM   #3
buckles
LQ Newbie
 
Registered: Jun 2003
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for the reply.

1. I did make sure that the write was successful. I had some debug error messages that I omitted in this post.
2. I will check the buffering scheme... thanks.

Here is another piece of info:

The same code works fine when executed from userspace. Any char value gets successfully read back, even greater than 0x7f. Its just when executed from a kernel program that the read hangs. As you may already know, in order to execute a system call from kernelspace, the following steps have to be taken:

1. the directive __KERNEL_SYSCALLS__ must be included in the source file
2. set_fs(), get_fs(), get_ds() must be used appropriately to resolve any kernel/user addressing incompatibilities.

Also noticed that the read()/write() definitions in /usr/include/unistd.h (userspace) and /usr/src/linux/include/asm/unistd.h (kernelspace) differ slightly between files. One takes a 'void *' as the 2nd parameter, while the other takes a 'char *', or a 'const char *'. These definitions are included via the __KERNEL_SYSCALLS__ directive. Maybe this is why I can use values less than 0x7f, as well as any character string (since the highest ASCII value of any character is 0x7F) with successful results.
 
Old 05-07-2005, 12:03 AM   #4
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
just incase you missed my answer to the thread in software got moved to the programming board
 
  


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
problem with adding a system call newcat Programming 17 04-08-2006 06:50 AM
I am trying implement sleep in read system call problem sbharsha Programming 1 09-18-2005 11:48 PM
Problem using 'read' system call buckles Programming 6 05-10-2005 11:45 AM
difficulties with large files and system call read/write jwstric2 Programming 2 08-22-2004 11:42 PM
maximum value of count in read system call udayan Programming 2 06-13-2002 06:51 AM


All times are GMT -5. The time now is 01:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration