Solved

asynchronous I/O in SCO/UNIX

Posted on 1998-11-22
2
369 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now