Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: USB to RS232 adapter



Here's one headsup. I've got a USA-19QW keyspan adapter with up to date drivers and I've been happy with it until, coincidentally, this AM. I tried to use some termios code with VMIN and VTIME timeouts that works on FreeBSD, cygwin, and RTEMS unchanged and I couldn't get it to work on my powerbook. I finally gave up and hacked in a SIGALRM timeout with interrupted system calls enabled after trying for an hour or so to figure out what was wrong, checking driver revs, etc.

Here are the code snippets if anyone notices anything.

Pertinent setup, TIMEOUTS_BROKEN set for Apple:
#if TIMEOUTS_BROKEN
siginterrupt(SIGALRM, 1); // Cause reads to be interrupted
signal(SIGALRM, timed_out);
#else
ntermio.c_lflag &= ~(ECHO|ICANON|ISIG); // No echo, non-canonical input, no signals


/*
* Don't strip to seven bits, do XON or XOFF, ignore CR, or map things around..
*/
ntermio.c_iflag &= ~(ICRNL|IGNCR|ISTRIP|INPCK|IXON|IXOFF|INLCR);


    ntermio.c_oflag &= ~(OPOST);    // Don't do output processing.

// Don't monitor modem, clear size bits, disable parity detect:
ntermio.c_cflag &= ~(CSIZE|CSTOPB|PARENB); // Clear size field, one stop bit, no parity
ntermio.c_cflag |= (CLOCAL|CREAD|CS8); // No modem control, enable receiver, 8-bits.
#endif


then later read the data:

#if TIMEOUTS_BROKEN == 0

        // Get the first character with a half second timeout.

        ntermio.c_cc[VMIN] = 0;
        ntermio.c_cc[VTIME] = 5;    // 5 times .1 is 1/2 second
        if (tcsetattr(fd, TCSANOW, &ntermio)) {
            return latch_errno("tcsetattr");
        }

if ((n = read(fd, inbuf, 1)) != 1) {
if (n == 0) {
return crash("No response from the OncoScanner.");
}
fprintf(stderr, "Read %d characters from the OncoScanner instead of 1.\n", (int)n);
return latch_errno("read");
}


// We know it is out there. Set an inter-byte timeout to get the rest.
// XXX Still could hang if the device disappears
ntermio.c_cc[VMIN] = 4; // four more bytes.
ntermio.c_cc[VTIME] = 1; // They shouldn't be more than .1 seconds apart.
if (tcsetattr(fd, TCSANOW, &ntermio)) {
return latch_errno("tcsetattr");
}


if ((n = read(fd, inbuf + 1, 4)) != 4) {
fprintf(stderr, "Read returned %d, not 4.\n", (int)n);
return latch_errno("read");
}
#else
alarm(2);
if ((n = read(fd, inbuf, 5)) != 5) {
fprintf(stderr, "Read returned %d bytes, not 5 bytes.\n", (int)n);
return latch_errno("read");
}
alarm(0);
#endif



Peter

Peter Dufault
HD Associates, Inc.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Scitech mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/scitech/email@hidden

This email sent to email@hidden
References: 
 >USB to RS232 adapter (From: David Linker <email@hidden>)
 >Re: USB to RS232 adapter (From: Thomas Jordan <email@hidden>)
 >Re: USB to RS232 adapter (From: Emmanuel <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.