home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / programm / 6015 next >
Encoding:
Text File  |  1993-01-21  |  4.4 KB  |  126 lines

  1. Xref: sparky comp.unix.programmer:6015 comp.lang.c:20000
  2. Newsgroups: comp.unix.programmer,comp.lang.c
  3. Path: sparky!uunet!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!sun4nl!dutrun!donau!duteca.et.tudelft.nl!tirza
  4. From: tirza@duteca.et.tudelft.nl (Tirza van Rijn)
  5. Subject: Serial communication over leased line in C (UNIX)?
  6. Message-ID: <1993Jan20.234220.3068@donau.et.tudelft.nl>
  7. Sender: news@donau.et.tudelft.nl (UseNet News System)
  8. Nntp-Posting-Host: duteca.et.tudelft.nl
  9. Organization: Delft University of Technology, Dept. of Electrical Engineering
  10. Date: Wed, 20 Jan 1993 23:42:20 GMT
  11. Lines: 113
  12.  
  13.  
  14. Hallo *,
  15.  
  16.  
  17. I'm trying to write a little program to send database requests down a leased
  18. (direct) line and save the answers to a file, but I can't get it to work.
  19.  
  20. My side of the line is the second RS232 port (ttyd2) of a Silicon Graphics
  21. Iris Indigo running IRIX 4.0.1, the other side is an always stand-by database
  22. server, the communication should be at 4800 baud, 8 bits/char, no parity,
  23. 1 stopbit, and there is no login procedure involved: you can just send a
  24. request anytime and get back a reply. I can successfully contact the database
  25. server with Kermit (set line ttyd2, set baud 4800) and cu (-s4800 -lttyd2).
  26.  
  27. A normal session with the database server looks something like:
  28. question:                                     answer:
  29. TI[LF]                                    =>  ? 0 Cmd error [LF]
  30.                                               (1th request usually fails)
  31. TI[LF]                                    =>  ! 18-JAN-93 12:03:46 [LF]
  32. DB GSS6,HE1,+24:00,00:00,28-DEC-92[LF]    =>  ! #79 #80 #82 #82....... [LF]
  33.  
  34. My program looks as follows:
  35.  
  36. -8<--------------------------------------------------------------------
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39.  
  40. #define CR      '\r'
  41. #define LF      '\n'
  42.  
  43. main()
  44. {
  45.     FILE *in, *out, *output;
  46.     char c;
  47.     char linebuf[500];
  48.     char answer[500];
  49.     char request1[] = "TI";
  50.     char request2[] = "DB GSS6,HE1,+24:00,00:00,28-DEC-92";
  51.     int i;
  52.  
  53.     system("sleep 10000000 < /dev/ttyd2 &");
  54.     system("stty 4800 < /dev/ttyd2");
  55.     in = fopen("/dev/ttyd2","r");
  56.     out = fopen("/dev/ttyd2","w+");
  57.     output = fopen("outfile", "w");
  58.  
  59. /* Ask MNZ for time */
  60.     fprintf(stderr, "request1 = *%s*\n", request1);
  61.     fprintf(out, "%s\n", request1);
  62.     i = 0;
  63.     while ((c = fgetc(in)) != LF)
  64.     {
  65.         fprintf(stderr, "c = %c\n", c);
  66.         answer[i++] = c;
  67.     }
  68.     answer[i] = '\0';
  69.     fprintf(stderr, "answer = *%s*\n", answer);
  70.     fprintf(output, "%s\n", answer);
  71.  
  72. /* Ask MNZ for time again */
  73.     fprintf(stderr, "request1 = *%s*\n", request1);
  74.     fprintf(out, "%s\n", request1);
  75.     i = 0;
  76.     while ((c = fgetc(in)) != LF)
  77.     {
  78.         fprintf(stderr, "c = %c\n", c);
  79.         answer[i++] = c;
  80.     }
  81.     answer[i] = '\0';
  82.     fprintf(stderr, "answer = *%s*\n", answer);
  83.     fprintf(output, "%s\n", answer);
  84.  
  85. /* Ask MNZ for spectal wave height band 200-500mHz from Marex on MPN */
  86.     fprintf(stderr, "request2 = *%s*\n", request2);
  87.     fprintf(out, "%s\n", request2);
  88.     i = 0;
  89.     while ((c = fgetc(in)) != LF)
  90.     {
  91.         fprintf(stderr, "c = %c\n", c);
  92.         answer[i++] = c;
  93.     }
  94.     answer[i] = '\0';
  95.     fprintf(stderr, "answer = *%s*\n", answer);
  96.     fprintf(output, "%s\n", answer);
  97.  
  98.     fclose(output);
  99. }
  100.  
  101. -end------------------------------------------------------------------------
  102.  
  103. It looks like I'm receiving the answers from the database server correctly,
  104. but that is always a '? 0 Cmd error '. But if I run my program while at the same
  105. time I am giving requests through 'cu -s4800 -lttyd2', it does receive about
  106. half of the "sensible" answers (such as  '! 18-JAN-93 12:03:46 '), the other
  107. half goes to cu.
  108.  
  109. I've got the feeling that my requests are not gettting through at all so that
  110. I never get a "sensible" answer back.
  111.  
  112. Does any communications guru out there know what I'm doing wrong? Or can
  113. sombody tell me where to find an example program for this kind of problem?
  114.  
  115.  ______
  116.    |_          Thanks in advance for your consideration,
  117.    |_)
  118.    |v\                         Tirza
  119.  
  120. --------------------------------------------------------------------------------
  121. Tirza van Rijn                       | e-mail: tirza@duteca.et.tudelft.nl
  122. Department of Electrical Engineering |
  123. Delft University of Technology       | Thou art beautiful, Oh my love, as Tirzah
  124. Delft, The Netherlands               |                       Song of Salomon 6:4
  125. --------------------------------------------------------------------------------
  126.