?
Solved

asynchronous I/O in SCO/UNIX

Posted on 1998-11-22
2
Medium Priority
?
401 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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.
Suggested Courses

809 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