Solved

asynchronous I/O in SCO/UNIX

Posted on 1998-11-22
2
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

740 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