Solved

asynchronous I/O in SCO/UNIX

Posted on 1998-11-22
2
382 Views
Last Modified: 2013-12-05
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    I have been developing a program to communicate with a IC Reader Device via serial port. What i really want is it
can write & read any characters range from 0x00 to 0xff in
the very raw mode.
    But when it read from the Reader, sometimes it missed some characters. After comparing
with the characters it should receive, i found the missing characters were those behind the 0x11
character, which was stop_character (Ctrl+q). But it does not always like this. In ordinary it
works right way.
( .
1. When right, the data i receive:
    10 00 00 14 05 1a 3b 2f 00 00 48 44 4d 11 98 37 01 40 00 01 f3 00 90 00 d7
2. When error, the data i receive:
                                                                         98 37 01 40 00 01 f3 00 90 00 d7
 * i read & write a character everytime.
)

I doubt that there is a mistake in the communication mode somehow . But i am not sure of the cause.


Thank you for reply in advance.


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* SCO/unix */
//The following is my codes:
#include <termio.h>

int srl_fd;

set_serial_mode()
{
 struct termio  tiopck, tiopck_;

 if ( (srl_fd = open("/dev/tty1a", O_RW)) < 0 )
  return -1;

     ioctl(srl_fd, TCGETA, &tiopck );
     tiopck_ = tiopck;

 tiopck_.c_iflag = 0;
 tiopck_.c_oflag = 0;
//9600, 8bit, no parity
 tiopck_.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
 tiopck_.c_lflag &= ~(ICANON | ECHO | ISIG);
 tiopck_.c_line = 0;
 memset( tiopck_.c_cc,  0x00 , NCC );
 tiopck_.c_cc[VMIN] = 1;
 tiopck_.c_cc[VTIME] = 0;
       
 if ( ioctl(srl_fd, TCSETAW, &tiopck_ ) < 0 )
  return -1;

 return 0;
}


0
Comment
Question by:xxz
2 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 100 total points
ID: 2008004
You are losing characters becase of the interpretation of 0x11 which is XOFF. You must switch off XON/XOFF control on that port. SAince I am at home with a cold I can't tell you which parameter to set (if it is not obvious from the manual). So if you can't switch off XON/XOFF reject this answer and when I get back to work tomorrow or the day after I'll look in the manual for you.
0
 

Author Comment

by:xxz
ID: 2008005
Bigbat,
     Thank you for your reply. In fact in my codes, the statement "  tiopck_.c_iflag = 0; "  has switch off the XON/XOFF.
     I have solved this problem by setting " tiopck_.c_cc[VMIN] = read_num; " . I used to read  one byte each time (" tiopck_.c_cc[VMIN] = 1; "), and it worked very well in previous condition. But this time, i read all the bytes sent out by Reader Device, so I have to change read_num each time when  i read from serial port.
     I wonder the differences between " tiopck_.c_cc[VMIN] = read_num; " and "tiopck_.c_cc[VMIN] = 1; ".So far,  i am not understand why.
     
                                  * read_num is the number of bytes which Reader Device  send out.
    Good Health!
                                                                                                                   Xu XiaoZhou
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question