Article View: comp.sys.dec
Article #1345Help with DECstation 3100 serial ports
From: James Elliott
Date: Sun, 16 Aug 1992 23:49
Date: Sun, 16 Aug 1992 23:49
138 lines
4866 bytes
4866 bytes
I'm at the end of my rope... I just bought a really spiffy multi-color
electronic sign (for very cheap at Sam's!), which I plan to mount in
my office window so my students can get class notices as well as
weather forecasts or whatever.
I'm presently writing a daemon to allow people to configure the
messages on the sign remotely so that, for example, my office-mate can
have a few message slots on the sign too.
I'm very close to having this work but have hit a frustrating hitch.
Here's the situation:
I've built a serial cable conforming to the specs in the instructions.
This works fine when I try to configure the sign using my Macintosh at
home. It >almost< works on my DECstation. I can send characters to the
sign, but the echo characters that come back (important for
confirmation, and even more important for flow control) just are not
getting to me. I never get anything back from the sign on the
DECstation.
The RS232 parameters I'm supposed to use are: 300 baud, 2 stop bits, 8
data bits, no parity. As I've said, this works fine with the same
cable and these settings on my Mac.
Here's a code fragment I've written to configure the serial port, and
the routine that writes to the sign and waits for confirmation:
#include <sys/types.h>
#include <termios.h>
#include <memory.h>
#include <errno.h>
/* ...stuff deleted */
extern int
open_port(char *filename)
{
struct termios t;
/* Open the serial port, unless someone else is using it */
if ((portFD = open(filename, O_RDWR | O_NDELAY | O_BLKANDSET, 0)) < 0)
return(portFD);
/* Get the current state of the serial port */
if (tcgetattr(portFD, &t) < 0) {
punt:
close(portFD);
return -1;
}
/* Save the old port state so we can restore it at exit */
memcpy(&oldState, &t, sizeof(oldState));
/*
* Configure the port the way the sign wants it:
*/
/* Do no fancy input nor output processing whatsoever */
t.c_iflag = 0;
t.c_oflag = 0;
t.c_lflag = 0;
/* Wait for up to three seconds for reads to complete. */
t.c_cc[VMIN] = 0;
t.c_cc[VTIME] = 30;
/* 8 bit chars, 2 stop bits, no modem control, 300 baud */
t.c_cflag = CS8 | CSTOPB | CLOCAL | CREAD;
if (cfsetispeed(&t, B300) < 0)
goto punt;
if (cfsetospeed(&t, B300) < 0)
goto punt;
/* Now, make the call to have these settings take effect */
if (tcsetattr(portFD, TCSANOW, &t) < 0)
goto punt;
/* We succeeded */
return(0);
}
/*
* Routine to write a character to the sign and wait for the echo
*/
extern int
port_sendchar(unsigned char c)
{
int count;
char buffer[10];
if (write(portFD, &c, 1) < 1)
return(-1);
/* Wait for up to three seconds to get our echo back. Note that this
read will magically behave that way, because of the way we configured
the port using termios above. */
count = read(portFD, buffer, 1);
if (count == 1) { /* We got the right number of characters */
if (buffer[0] != c) {
/* But not the right ones! Have we drifted out of synch? */
errno = EALIGN;
return -1;
}
}
else if (count == 0) { /* We got nothing */
errno = ETIMEDOUT;
return -1;
}
else /* We got an error return */
return(-1);
return 0;
}
It seems to me that this should work, but what happens is that I never
get back the echos, and port_sendchar always returns ETIMEDOUT. If I
ignore those, then it crawls along configuring the sign, waiting three
seconds per character sent. It WORKS, but it's slow and ugly. If I go
too much faster, I risk having characters dropped when the sign is
asked to do something complicated.
Can anyone help me? Or suggest other newsgroups where I should post
this?
Jim Elliott----------------------------------------elliott@cs.wisc.edu
"There is perhaps no phenomenon which contains so much destructive
feeling as moral indignation, which permits envy or hate to be acted
out under the guise of virtue." -- Erich Fromm
--
Jim Elliott----------------------------------------elliott@cs.wisc.edu
"There is perhaps no phenomenon which contains so much destructive
feeling as moral indignation, which permits envy or hate to be acted
out under the guise of virtue." -- Erich Fromm
Technical Details
Message-ID:
<1992Aug16.234918.10482@cs.wisc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!apple!apple!rutgers!uwvax!veronica.cs.wisc.edu!elliottShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!apple!apple!rutgers!uwvax!veronica.cs.wisc.edu!elliott From: elliott@veronica.cs.wisc.edu (James Elliott) Newsgroups: comp.sys.dec Subject: Help with DECstation 3100 serial ports Summary: Help me control my neat electronic sign and I'll post my software. :) Keywords: Receive problems; low-level control? Message-ID: <1992Aug16.234918.10482@cs.wisc.edu> Date: 16 Aug 92 23:49:18 GMT Sender: news@cs.wisc.edu (The News) Organization: U of Wisconsin Madison - Computer Sciences Lines: 138