home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / dec / 4560 < prev    next >
Encoding:
Text File  |  1992-08-16  |  4.6 KB  |  151 lines

  1. Path: sparky!uunet!olivea!apple!apple!rutgers!uwvax!veronica.cs.wisc.edu!elliott
  2. From: elliott@veronica.cs.wisc.edu (James Elliott)
  3. Newsgroups: comp.sys.dec
  4. Subject: Help with DECstation 3100 serial ports
  5. Summary: Help me control my neat electronic sign and I'll post my software. :)
  6. Keywords: Receive problems; low-level control?
  7. Message-ID: <1992Aug16.234918.10482@cs.wisc.edu>
  8. Date: 16 Aug 92 23:49:18 GMT
  9. Sender: news@cs.wisc.edu (The News)
  10. Organization: U of Wisconsin Madison - Computer Sciences
  11. Lines: 138
  12.  
  13. I'm at the end of my rope... I just bought a really spiffy multi-color
  14. electronic sign (for very cheap at Sam's!), which I plan to mount in
  15. my office window so my students can get class notices as well as
  16. weather forecasts or whatever.
  17.  
  18. I'm presently writing a daemon to allow people to configure the
  19. messages on the sign remotely so that, for example, my office-mate can
  20. have a few message slots on the sign too.
  21.  
  22. I'm very close to having this work but have hit a frustrating hitch.
  23. Here's the situation:
  24.  
  25. I've built a serial cable conforming to the specs in the instructions.
  26. This works fine when I try to configure the sign using my Macintosh at
  27. home. It >almost< works on my DECstation. I can send characters to the
  28. sign, but the echo characters that come back (important for
  29. confirmation, and even more important for flow control) just are not
  30. getting to me. I never get anything back from the sign on the
  31. DECstation.
  32.  
  33. The RS232 parameters I'm supposed to use are: 300 baud, 2 stop bits, 8
  34. data bits, no parity. As I've said, this works fine with the same
  35. cable and these settings on my Mac.
  36.  
  37. Here's a code fragment I've written to configure the serial port, and
  38. the routine that writes to the sign and waits for confirmation:
  39.  
  40.  
  41. #include <sys/types.h>
  42. #include <termios.h>
  43. #include <memory.h>
  44. #include <errno.h>
  45.  
  46. /* ...stuff deleted */
  47.  
  48. extern int
  49.   open_port(char *filename)
  50. {
  51.   struct termios t;
  52.  
  53.   /* Open the serial port, unless someone else is using it */
  54.   if ((portFD = open(filename, O_RDWR | O_NDELAY | O_BLKANDSET, 0)) < 0)
  55.     return(portFD);
  56.  
  57.   /* Get the current state of the serial port */
  58.   if (tcgetattr(portFD, &t) < 0) {
  59. punt:
  60.     close(portFD);
  61.     return -1;
  62.   }
  63.  
  64.   /* Save the old port state so we can restore it at exit */
  65.   memcpy(&oldState, &t, sizeof(oldState));
  66.  
  67.   /*
  68.    * Configure the port the way the sign wants it:
  69.    */
  70.  
  71.   /* Do no fancy input nor output processing whatsoever */
  72.   t.c_iflag = 0;
  73.   t.c_oflag = 0;
  74.   t.c_lflag = 0;
  75.  
  76.   /* Wait for up to three seconds for reads to complete. */
  77.   t.c_cc[VMIN] = 0;
  78.   t.c_cc[VTIME] = 30;
  79.  
  80.   /* 8 bit chars, 2 stop bits, no modem control, 300 baud */
  81.   t.c_cflag = CS8 | CSTOPB | CLOCAL | CREAD;
  82.   if (cfsetispeed(&t, B300) < 0)
  83.     goto punt;
  84.   if (cfsetospeed(&t, B300) < 0)
  85.     goto punt;
  86.  
  87.   /* Now, make the call to have these settings take effect */
  88.   if (tcsetattr(portFD, TCSANOW, &t) < 0)
  89.     goto punt;
  90.  
  91.   /* We succeeded */
  92.   return(0);
  93. }
  94.  
  95.  
  96. /*
  97.  * Routine to write a character to the sign and wait for the echo
  98.  */
  99. extern int
  100.   port_sendchar(unsigned char c)
  101. {
  102.   int count;
  103.   char buffer[10];
  104.  
  105.   if (write(portFD, &c, 1) < 1)
  106.     return(-1);
  107.  
  108.   /* Wait for up to three seconds to get our echo back. Note that this
  109.      read will magically behave that way, because of the way we configured
  110.      the port using termios above. */
  111.   count = read(portFD, buffer, 1);
  112.  
  113.   if (count == 1) {  /* We got the right number of characters */
  114.     if (buffer[0] != c) {
  115.       /* But not the right ones! Have we drifted out of synch? */
  116.       errno = EALIGN;
  117.       return -1;
  118.     }
  119.   }
  120.   else if (count == 0) {  /* We got nothing */
  121.     errno = ETIMEDOUT;
  122.     return -1;
  123.   }
  124.   else  /* We got an error return */
  125.     return(-1);
  126.  
  127.   return 0;
  128. }
  129.  
  130.  
  131. It seems to me that this should work, but what happens is that I never
  132. get back the echos, and port_sendchar always returns ETIMEDOUT. If I
  133. ignore those, then it crawls along configuring the sign, waiting three
  134. seconds per character sent. It WORKS, but it's slow and ugly. If I go
  135. too much faster, I risk having characters dropped when the sign is
  136. asked to do something complicated.
  137.  
  138. Can anyone help me? Or suggest other newsgroups where I should post
  139. this?
  140.  
  141.  
  142. Jim Elliott----------------------------------------elliott@cs.wisc.edu
  143.  "There is perhaps no phenomenon which contains so much destructive
  144.   feeling as moral indignation, which permits envy or hate to be acted
  145.   out under the guise of virtue."  -- Erich Fromm
  146. -- 
  147. Jim Elliott----------------------------------------elliott@cs.wisc.edu
  148.  "There is perhaps no phenomenon which contains so much destructive
  149.   feeling as moral indignation, which permits envy or hate to be acted
  150.   out under the guise of virtue."  -- Erich Fromm
  151.