character I/O basics


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers character I/O basics
# 8  
Old 12-10-2003
Hi again! Sorry for the delay...
Well, the comm driver is setup prior to use. I thought that serial communication would be the same with UNIX as it is with QNX. My mistake... I do:
---------------
fd=open("/dev/ser1", O_RDONLY);
read(fd, buffer, len);
close(fd);
---------------
So I'm not aware of the tty interface.

But that's not the heart of the problem anyway.
Here's what I need help on:
I tried using a fifo as suggested and it does what I need. That's the bridge I was thinking of ;-)
Here is a portion of the code to "test from user input":
Code:
// test_app
char key;
while(1)
{
   cin >> key;
   switch(key)
   {
       // issue various commands to the device
       // and read back answer from it
   }
}

So I can start the program and feed it from the keyboard to test all the cases. That simple.
Now I start it with "fifo_file" redirected as input, and I
start a shell script "feeder" with output redirected to "fifo_file".
This script loops forever: "echo" 1 sequence of character (a "word") and then sleeps a bit. This way I can automate testing.
This works very good and fills my need.

Just curious what I should do to avoid this: if I stop feeding the fifo_file, the test_app that uses it as input keeps on getting the last character it got (and very fast)!

Thanks everybody for taking the time to share your knowledge!

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 05:04 PM..
# 9  
Old 12-11-2003
starless, you really need to mention that you're using QNX. I guess that I shouldn't have remembered that you use QNX, but I didn't.

Your /dev/ser may indeed behave in ways that I don't understand. Or it may be very close to the unix tty. I'm not sure.

I'm not a c++ programmer nor do I know QNX. But I think that I understand this last character repeating business...maybe. But I'll have to explain unix system calls invoked from c.

I guessing that you're doing the equivalent of
read(fd, buffer, len)
and fd is now one side of a fifo. You need to change that to:
iret=read(fd, buffer, len)
if(iret == 0) { /* arrange to stop reading */ }
if (iret == -1) { /* error routine */ }

The read is failing, but you're not noticing this. Your buffer is not being touched. You're just assuming that it got a character. On unix, this situation would cause read to simply return a zero. In your case, you may being getting an error of some kind.

You can prove that you're not simply getting the last character... put some other character in the buffer just prior to the read. That will become the character that you seem to be reading in a loop.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help me with basics

hello everyone i have to start with unix as it is a part of my training programme and i have to do a self study, i dont know where to start from. i need some basic questions to be answerd like why we use unix ? what is a terminal? what is an editor? why we write commands inside terminal? these... (4 Replies)
Discussion started by: aryancool
4 Replies

2. Shell Programming and Scripting

ls command basics???

how do i use the ls command with a single argument to list all files whose names end with the letter 'r'? (7 Replies)
Discussion started by: lilbo4231
7 Replies

3. UNIX for Dummies Questions & Answers

awk basics

Hi, Please tell me where can I get started with awk..like the basics and the whole awk stuff. Regards, Deepti (2 Replies)
Discussion started by: gaur.deepti
2 Replies

4. AIX

DB2 basics

Dear friends I am going to study DB2 and i dont have any experience with any DB's.. Please provide me with some links or pdf's for DB2 starters. any advice will be very usefull (2 Replies)
Discussion started by: Vit0_Corleone
2 Replies

5. IP Networking

SAN basics

Hi I like to learn and practice SAN, iSCSI. Could you sugges the appropriate tutorial and small tasks to practice SAN. Thankyou (1 Reply)
Discussion started by: kingskar
1 Replies

6. UNIX for Dummies Questions & Answers

Installation basics

hello, Im new to this Os. so, can i get any information'bout installation basics of unix. (1 Reply)
Discussion started by: Abhijit Bhatt
1 Replies

7. UNIX for Dummies Questions & Answers

Unix Basics

Hey, you said this forum was for Dummies, so don't blame me for the following! :D My whole "web building" life, I've had my sites hosted in one for or another. Lately, I've gotten into PHP and MySQL and, of course, those are also hosted for me. But lately, I've been thinking of using PHP and... (2 Replies)
Discussion started by: cap97
2 Replies
Login or Register to Ask a Question