home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / CUG / RS232EXP.C < prev    next >
Text File  |  1993-12-01  |  12KB  |  407 lines

  1. /*
  2.     HEADER:        CUG000.00;
  3.     TITLE:        RS232 Diagnostic Helper (Kila86);
  4.     DATE:        05/17/1987;
  5.     DESCRIPTION:    "Helps diagnose problems with the RS232 serial port.";
  6.     VERSION:    1.1;
  7.     KEYWORDS:    Serial port, RS-232;
  8.     FILENAME:    RS232EXP.C;
  9.     SEE-ALSO:    RS232EXP.DOC;
  10.     COMPILERS:    vanilla;
  11.     AUTHORS:    J. Kilar, W. C. Colley III;
  12. */
  13.  
  14. /*  Portability Note:  This program was originally written for the DeSmet C
  15.     compiler.  That compiler supplies a number of quirky functions that
  16.     operate the screen on the IBM PC.  This program uses two of them:
  17.  
  18.     void scr_rowcol(r,c)        Set the cursor to row r (1-24),
  19.     int r, c;            column c (1-80).
  20.  
  21.     void scr_clr()            Clear the screen.
  22.  
  23.     Users on other systems will have to use equivalents from their C compilers'
  24.     libraries or write equivalents.
  25.  
  26.     The Eco-C88 compiler has equivalent routines (that require ANSI.SYS to be
  27.     installed) as follows:
  28.  
  29. void clrscr(), scr_pos();
  30. #define scr_rowcol(r,c)        scr_pos((r)-1,(c)-1)
  31. #define scr_clr            clrscr
  32.  
  33.     Folks using serial terminals (like my Z-19) can write routines like these:
  34.  
  35. void scr_rowcol(r,c)
  36. int r, c;
  37. {
  38.     fprintf(stderr,"\033Y%c%c",r + (' '-1),c + (' '-1));
  39. }
  40.  
  41. void scr_clr()
  42. {
  43.     fprintf(stderr,"\033Y  \033E");
  44. }
  45.  
  46.     You can also work directly into the ANSI.SYS driver or work into an ANSI
  47.     serial terminal like this:
  48.  
  49. void scr_rowcol(r,c)
  50. int r, c;
  51. {
  52.     fprintf(stderr,"\033[%d;%dH",r,c);
  53. }
  54.  
  55. void scr_clr()
  56. {
  57.     fprintf(stderr,"\033[2J");
  58. }
  59.  
  60. */
  61. #include <stdio.h>
  62.  
  63. /*  Portability Note:  A few compilers don't know the additional type
  64.     void.  If yours is one of these, uncomment the following #define.    */
  65.  
  66. /* #define    void        int                    */
  67.  
  68. int baudrate(), bothpc(), bothterm(), chkcable(), databits(), dcedte();
  69. int decterm(), deviceoff(), fullcable(), parity(), pc(), pcmale();
  70. int pcmodem(), pcport(), pcprint(), pcterm(), resp(), respny(), term();
  71. void blank(), clear(), devincomp(), heading(), nullmodem(), wait();
  72.  
  73. void main()
  74. {
  75.     while (1) {
  76.     heading();            /* display heading */
  77.     if (deviceoff()) break;        /* check that devices are on */
  78.     if (chkcable()) break;        /* check cable connected */
  79.     if (baudrate()) break;        /* check baud rate */
  80.     if (parity()) break;        /* parity */
  81.     if (databits()) break;        /* check data bits */
  82.     if (pc()) {            /* handle PC involved case */
  83.         if (pcmale()) break;    /* on serial not parallel port? */
  84.         if (pcport()) break;    /* COM1 or COM2 */
  85.         if (bothpc()) break;    /* two PCs case */
  86.         if (pcterm()) break;    /* PC to a terminal case */
  87.         if (pcmodem()) break;    /* PC to a modem case */
  88.         if (pcprint()) break;    /* PC to a printer */
  89.         if (fullcable()) break;    /* try full straight thru cable */
  90.         devincomp();  break;
  91.     }
  92.     else if (term()) {        /* no PC, terminal case */
  93.         if (pcmodem()) break;
  94.         if (decterm()) break;    /* DEC terminal */
  95.         if (bothterm()) break;    /* both terminals */
  96.         if (fullcable()) break;    /* try 25 lead straight thru cable */
  97.         if (dcedte()) break;
  98.         devincomp();  break;
  99.     }
  100.     else {
  101.         if (dcedte()) break;
  102.         devincomp();  break;
  103.     }
  104.     }
  105.     blank();  blank();
  106.     printf("Glad I could be of service to you.\n");
  107. }
  108.  
  109. /* heading - displays header for program */
  110. void heading()
  111. {
  112.     clear();
  113.     printf("RS-232 MINI EXPERT SYSTEM.\n");
  114.     printf("Version 1.1   by   Joe Kilar\n");
  115.     blank();
  116.     printf("This program will help you solve RS-232 serial communications ");
  117.     printf("problems.\n");
  118.     printf("Examples are connecting PCs to serial printers, modems, or");
  119.     printf(" terminals.\n");
  120.     blank();
  121.     printf("If you're not sure about an answer you may try skipping it by\n");
  122.     printf("answering no to whether the devices are communicating.  ");
  123.     printf("Jot down\n");
  124.     printf("the question in case further aids don't result in success.\n");
  125.     wait();
  126.     return;
  127. }
  128.  
  129.  
  130. int deviceoff()
  131. {
  132.     clear();
  133.     printf("Check that power to both devices is on.  If power is not \n");
  134.     printf("on, turn it on. \n");
  135.     return respny();
  136. }
  137.  
  138.  
  139. int chkcable()
  140. {
  141.     clear();
  142.     printf("Check that the serial cable is firmly connected to both ");
  143.     printf("devices.\nIf not, ensure a good connection. \n");
  144.     return respny();
  145. }
  146.  
  147. int baudrate()
  148. {
  149.     clear();
  150.     printf("Check that the baud rates selected or required for both devices");
  151.     printf("\nare the same.   Baud rate reflects the speed at which data is");
  152.     printf("\ncommunicated.  Typical baud rates are 300,1200,2400,9600, and ");
  153.     printf("19.2K\n");
  154.     blank();
  155.     printf("Some devices have auto-baud.  They lock onto the baud rate of\n");
  156.     printf("the other device sending successive RETURNs (sometimes SPACEs). ");
  157.     printf("At times\nnoise ");
  158.     printf("may make it lock onto the wrong baud rate.  Try turning it\n");
  159.     printf("off and then back on to reset it.\n");
  160.     blank();
  161.     printf("Ensure that the baud rates are identical and/or reset any\n");
  162.     printf("device using auto-baud.\n");
  163.     return respny();
  164. }
  165.  
  166. int parity()
  167. {
  168.     clear();
  169.     printf("Check that the parity's selected or required for both devices\n");
  170.     printf("are the same.   Parity has to do with an extra bit sent that can");
  171.     printf("\nhelp detect transmission errors.  It is usually set to even, ");
  172.     printf("odd\nor none.\n");
  173.     blank();
  174.     printf("Ensure that the parity's are identical.\n");
  175.     return respny();
  176. }
  177.  
  178. int databits()
  179. {
  180.     clear();
  181.     printf("Check that each device is set for the same number of data bits.");
  182.     printf("\nUsual values are  7  or  8.\n");
  183.     blank();
  184.     printf("Ensure that the data bits selected are identical. \n");
  185.     return respny();
  186. }
  187.  
  188. int pc()
  189. {
  190.     clear();
  191.     printf("Is one or both devices an IBM or compatible PC? \n");
  192.     return resp("No", "Yes");
  193. }
  194.  
  195. int pcmale()
  196. {
  197.     clear();
  198.     printf("Check that the cable is connected to the PC's serial and\n");
  199.     printf("not parallel port.\n");
  200.     printf("The serial port has male pins protruding from it, the parallel\n");
  201.     printf("port is female. \n");
  202.     blank();
  203.     printf("Make sure the cable is connected to the serial port.\n");
  204.     return respny();
  205. }
  206.  
  207. int pcport()
  208. {
  209.     clear();
  210.     printf("If you have more than one serial port or have a PCjr, make sure");
  211.     printf("\nyou are connected to the correct serial port.\n");
  212.     blank();
  213.     printf("The port that comes on an XT, usually closest to the side with\n");
  214.     printf("the power switch, is COM1.  The serial port on back of a PCjr\n");
  215.     printf("may look like COM1 or COM2 depending on the way the software\n");
  216.     printf("accesses it.  Try switching to the other port if you\n");
  217.     printf("are in doubt.\n");
  218.     blank();
  219.     printf("Double check which port is used, switch the cable, or tell the\n");
  220.     printf("program to use the other if there is another or you have a PCjr.");
  221.     printf("\n");
  222.     return respny();
  223. }
  224.  
  225. int bothpc()
  226. {
  227.     int r;
  228.  
  229.     clear();
  230.     printf("Are both devices IBM or compatible PCs?\n");
  231.     if (r = resp("No","Yes")) nullmodem();
  232.     return r;
  233. }
  234.  
  235. int pcterm()
  236. {
  237.     int r;
  238.  
  239.     clear();
  240.     printf("Is the other device a terminal?\n");
  241.     if (r = resp("No","Yes")) nullmodem();
  242.     return r;
  243. }
  244.  
  245. int pcmodem()
  246. {
  247.     int r;
  248.  
  249.     clear();
  250.     printf("Is the other device a modem?\n");
  251.     if (r = resp("No","Yes")) (void)fullcable();
  252.     return r;
  253. }
  254.  
  255. int pcprint()
  256. {
  257.     int r;
  258.  
  259.     clear();
  260.     printf("Is the other device a printer?\n");
  261.     if (r = resp("No","Yes")) {
  262.     clear();
  263.     blank();
  264.     printf("Make sure the printer is an RS-232 device and not a ");
  265.     printf("Centronics\nparallel device.  If it is Centronics, you need ");
  266.     printf("to attach it\nto the parallel port of the PC.\n");
  267.     wait();
  268.     }
  269.     return r;
  270. }
  271.  
  272. int fullcable()
  273. {
  274.     clear();  blank();
  275.     printf("Try a straight thru cable that uses all 25 pins.  Make sure the");
  276.     printf("\ncable is not a null modem cable.\n");
  277.     return respny();
  278. }
  279.  
  280. void nullmodem()
  281. {
  282.     clear();
  283.     printf("You need a null modem cable.  You can purchase one from a\n");
  284.     printf("computer store.  You can also make one yourself by wiring\n");
  285.     printf("up a cable as shown below.\n");
  286.     blank();
  287.     printf("     2 ------------------------------------------------ 3\n");
  288.     printf("     3 ------------------------------------------------ 2\n");
  289.     printf("     4 ------------------------------------------------ 5\n");
  290.     printf("     5 ------------------------------------------------ 4\n");
  291.     printf("     6 ------------------------------------------------ 20\n");
  292.     printf("     7 ------------------------------------------------ 7\n");
  293.     printf("    20 ------------------------------------------------ 6\n");
  294.     blank();
  295.     printf("If the null modem cable doesn't work, see someone in Digital\n");
  296.     printf("Electronics for help.\n");
  297.     wait();
  298.     return;
  299. }
  300.  
  301. int term()
  302. {
  303.     clear();
  304.     printf("Is one or both devices a terminal?\n");
  305.     return resp("No","Yes");
  306. }
  307.  
  308. int decterm()
  309. {
  310.     clear();
  311.     printf("If the terminal is a DEC model such as VT100 or VT220\n");
  312.     printf("and other device is not a DEC computer or modem to a DEC\n");
  313.     printf("computer (e.g. VAX), turn off the XON/XOFF feature.\n");
  314.     return respny();
  315. }
  316.  
  317. int bothterm()
  318. {
  319.     int r;
  320.  
  321.     clear();
  322.     printf("Are both devices terminals?\n");
  323.     if (r = resp("No","Yes")) nullmodem();
  324.     return r;
  325. }
  326.  
  327. int dcedte()
  328. {
  329.     clear();
  330.     printf("RS-232 devices fall into two classes - DTE (Data Terminal ");
  331.     printf("Equip.)\nand DCE (Data Communications Equip.).  Try a full 25 ");
  332.     printf("pin straight\nthrough cable if one device is DTE and the other ");
  333.     printf("DCE.  If both\ndevices are DTEs or DCEs, you need a null modem ");
  334.     printf("cable. The device\nmanual may indicate the device's type.\n");
  335.     blank();
  336.     printf("Devices that are usually DTEs: terminals and IBM compatible PCs.");
  337.     printf("\nDevices that are usually DCEs: modems, ports to minicomputers,");
  338.     printf("\n   printers, VME bus serial ports, and devices designed to ");
  339.     printf("talk\n   with terminals such as serial ports on micro ");
  340.     printf("development\n   systems.\n");
  341.     blank();
  342.     printf("Does it seem that you need a null modem cable as the devices are");
  343.     printf("\nboth DTEs or DCEs?\n");
  344.     if (resp("No","Yes")) nullmodem();
  345.     clear();
  346.     return respny();
  347. }
  348.  
  349. void devincomp()
  350. {
  351.     clear();
  352.     printf("The devices are probably not supplying all the signals required");
  353.     printf("\nby the other.  See someone in Digital Electronics for help.\n");
  354.     wait();
  355.     return;
  356. }
  357.  
  358.  
  359. int respny()
  360. {
  361.     blank();
  362.     printf("    Are the devices communicating properly now?\n");
  363.     return resp("No","Yes");
  364. }
  365.  
  366.  
  367. int resp(zero,one)
  368. char *zero,*one;
  369. {
  370.     char buf[256], *gets();
  371.  
  372.     blank();  blank();
  373.     printf("            0  - %s \n",zero);
  374.     blank();
  375.     printf("            1 -  %s \n",one);
  376.  
  377.     do {
  378.     scr_rowcol(22,10);
  379.     printf("Enter either 0 or 1, then hit <return>: ");
  380.     } while (*gets(buf) != '0' && *buf != '1');
  381.     return *buf == '1';
  382. }
  383.  
  384. void wait()
  385. {
  386.     char buf[256], *gets();
  387.  
  388.     scr_rowcol(22,10);
  389.     printf("Hit <return> to continue.....");
  390.     (void)gets(buf);
  391.     return;
  392. }
  393.  
  394.  
  395. void clear()
  396. {
  397.     scr_clr();    scr_rowcol(1,1);
  398.     return;
  399. }
  400.  
  401. void blank()
  402. {
  403.     printf("\n");
  404.     return;
  405. }
  406.  
  407.