home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 192_01 / rs232exp.c < prev    next >
Text File  |  1979-12-31  |  10KB  |  445 lines

  1.  
  2. main()
  3. {
  4.  char res;
  5.  
  6.  while (1)
  7.   {
  8.    heading();                   /* display heading */
  9.  
  10.    if (deviceoff())             /* check that devices are on */
  11.      break;
  12.  
  13.    if (chkcable())              /* check cable connected */
  14.      break;
  15.  
  16.    if (baudrate())              /* check baud rate */
  17.      break;
  18.  
  19.    if (parity())                /* parity */
  20.      break;
  21.  
  22.    if (databits())              /* check data bits */
  23.      break;
  24.  
  25.    if (pc())                    /* handle PC involved case */
  26.     {
  27.      if (pcmale())              /* on serial not parallel port? */
  28.        break;
  29.  
  30.      if (pcport())              /* COM1 or COM2 */
  31.        break;
  32.  
  33.      if (bothpc())              /* two PCs case */
  34.        break;
  35.  
  36.      if (pcterm())              /* PC to a terminal case */
  37.        break;
  38.  
  39.      if (pcmodem())             /* PC to a modem case */
  40.        break;
  41.  
  42.      if (pcprint())             /* PC to a printer */
  43.        break;
  44.    
  45.      if (fullcable());          /* try full straight thru cable */
  46.        break;
  47.   
  48.      devincomp();
  49.      break;
  50.   }
  51.    else if (term())             /* no PC, terminal case */
  52.     {
  53.      if (pcmodem())
  54.        break;
  55.  
  56.      if (decterm())             /* DEC terminal */
  57.        break;
  58.  
  59.      if (bothterm())            /* both terminals */
  60.        break;
  61.  
  62.      if (fullcable())           /* try 25 lead straight thru cable */
  63.        break;
  64.  
  65.      if (dcedte())
  66.        break;
  67.  
  68.      devincomp();
  69.      break;
  70.     }
  71.  
  72.    else
  73.     {
  74.      if (dcedte())
  75.        break;
  76.  
  77.      devincomp();
  78.      break;
  79.     }
  80.  }
  81.  
  82.  blank();
  83.  blank();
  84.  printf("Glad I could be of service to you.\n");
  85. }
  86.  
  87. /* heading - displays header for program */
  88. heading()
  89. {
  90.  clear();
  91.  printf("RS-232 MINI EXPERT SYSTEM.\n");
  92.  printf("Version 1.0   by   Joe Kilar \n");
  93.  blank();
  94.  printf("This program will help you solve RS-232 serial communications ");
  95.  printf("problems. \n");
  96.  printf("Examples are connecting PCs to serial printers, modems, or"); 
  97.  printf(" terminals. \n");
  98.  blank();
  99.  printf("If you're not sure about an answer you may try skipping it by \n");
  100.  printf("answering no to whether the devices are communicating.  Jot down \n");
  101.  printf("the question in case further aids don't result in success. \n");
  102.  wait();
  103.  return;
  104. }
  105.  
  106.  
  107. deviceoff()
  108. {
  109.  char r;
  110.  
  111.  clear();
  112.  printf("Check that power to both devices is on.  If power is not \n");
  113.  printf("on, turn it on. \n");
  114.  r = respny();
  115.  return(r);
  116. }
  117.  
  118.  
  119. chkcable()
  120. {
  121.  char r;
  122.  
  123.  clear();
  124.  printf("Check that the serial cable is firmly connected to both devices.\n");
  125.  printf("If not, ensure a good connection. \n");
  126.  r = respny();
  127.  return(r);
  128. }
  129.  
  130. baudrate()
  131. {
  132.  char r;
  133.  
  134.  clear();
  135.  printf("Check that the baud rates selected or required for both devices \n");
  136.  printf("are the same.   Baud rate reflects the speed at which data is \n");
  137.  printf("communicated.  Typical baud rates are 300,1200,2400,9600, and "); 
  138.  printf("19.2K\n");
  139.  blank();
  140.  printf("Some devices have auto-baud.  They lock onto the baud rate of\n");
  141.  printf("the other device sending successive RETURNs (sometimes SPACEs). "); 
  142.  printf("At times \n");
  143.  printf("noise may make it lock onto the wrong baud rate.  Try turning it \n");
  144.  printf("off and then back on to reset it.\n");
  145.  blank();
  146.  printf("Ensure that the baud rates are identical and/or reset any \n");
  147.  printf("device using auto-baud. \n");
  148.  r = respny();
  149.  return(r);
  150. }
  151.  
  152. parity()
  153. {
  154.  char r;
  155.  
  156.  clear();
  157.  printf("Check that the parity's selected or required for both devices \n");
  158.  printf("are the same.   Parity has to do with an extra bit sent that can \n");
  159.  printf("help detect transmission errors.  It is usually set to even, odd \n");
  160.  printf("or none. \n");
  161.  blank();
  162.  printf("Ensure that the parity's are identical. \n");
  163.  r = respny();
  164.  return(r);
  165. }
  166.  
  167. databits()
  168. {
  169.  char r;
  170.  
  171.  clear();
  172.  printf("Check that each device is set for the same number of data bits. \n");
  173.  printf("Usual values are  7  or  8.\n");
  174.  blank();
  175.  printf("Ensure that the data bits selected are identical. \n");
  176.  r = respny();
  177.  return(r);
  178. }
  179.  
  180. pc()
  181. {
  182.  char r;
  183.  
  184.  clear();
  185.  printf("Is one or both devices an IBM or compatible PC? \n");
  186.  r = resp("No","Yes");
  187.  return(r);
  188. }
  189.  
  190. pcmale()
  191. {
  192.  char r;
  193.  
  194.  clear();
  195.  printf("Check that the cable is connected to the PC's serial and \n");
  196.  printf("not parallel port.\n");
  197.  printf("The serial port has male pins protruding from it, the parallel\n"); 
  198.  printf("port is female. \n");
  199.  blank();
  200.  printf("Make sure the cable is connected to the serial port. \n");
  201.  r = respny();
  202.  return(r);
  203. }
  204.  
  205. pcport()
  206. {
  207.  char r;
  208.  
  209.  clear();
  210.  printf("If you have more than one serial port or have a PCjr, make sure\n");
  211.  printf("you 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. \n");
  221.  r = respny();
  222.  return(r);
  223. }
  224.  
  225. bothpc()
  226. {
  227.  char r;
  228.  
  229.  clear();
  230.  printf("Are both devices IBM or compatible PCs? \n");
  231.  r = resp("No","Yes");
  232.  if (r)
  233.    nullmodem();
  234.  return(r);
  235. }
  236.  
  237. pcterm()
  238. {
  239.  char r;
  240.  
  241.  clear();
  242.  printf("Is the other device a terminal? \n");
  243.  r = resp("No","Yes");
  244.  if (r)
  245.    nullmodem();
  246.  return(r);
  247. }
  248.  
  249. pcmodem()
  250. {
  251.  char r;
  252.  
  253.  clear();
  254.  printf("Is the other device a modem? \n");
  255.  r = resp("No","Yes");
  256.  if (r)
  257.    fullcable();
  258.  return(r);
  259. }
  260.  
  261. pcprint()
  262. {
  263.  char r;
  264.  
  265.  clear();
  266.  printf("Is the other device a printer? \n");
  267.  r = resp("No","Yes");
  268.  if (r)
  269.   {
  270.    clear();
  271.    blank();
  272.    printf("Make sure the printer is an RS-232 device and not a Centronics \n");
  273.    printf("parallel device.  If it is Centronics, you need to attach it \n");
  274.    printf("to the parallel port of the PC. \n");
  275.    wait();
  276.   }
  277.  return(r);
  278. }
  279.  
  280. fullcable()
  281. {
  282.  char r;
  283.  
  284.  clear();
  285.  blank();
  286.  printf("Try a straight thru cable that uses all 25 pins.  Make sure the \n");
  287.  printf("cable is not a null modem cable. \n");
  288.  r = respny();
  289.  return(r);
  290. }
  291.  
  292.  
  293. nullmodem()
  294. {
  295.  clear();
  296.  printf("You need a null modem cable.  You can purchase one from a \n");
  297.  printf("computer store.  You can also make one yourself by wiring \n");
  298.  printf("up a cable as shown below. \n");
  299.  blank();
  300.  printf("     2 ------------------------------------------------ 3 \n");
  301.  printf("     3 ------------------------------------------------ 2 \n");
  302.  printf("     4 ------------------------------------------------ 5 \n");
  303.  printf("     5 ------------------------------------------------ 4 \n");
  304.  printf("     6 ------------------------------------------------ 20\n");
  305.  printf("     7 ------------------------------------------------ 7 \n");
  306.  printf("    20 ------------------------------------------------ 6 \n");
  307.  blank();
  308.  printf("If the null modem cable doesn't work, see someone in Digital \n");
  309.  printf("Electronics for help.\n");
  310.  wait();
  311.  return;
  312. }
  313.  
  314. term()
  315. {
  316.  char r;
  317.  
  318.  clear();
  319.  printf("Is one or both devices a terminal? \n");
  320.  r = resp("No","Yes");
  321.  return(r);
  322. }
  323.  
  324. decterm()
  325. {
  326.  char r;
  327.  
  328.  clear();
  329.  printf("If the terminal is a DEC model such as VT100 or VT220 \n");
  330.  printf("and other device is not a DEC computer or modem to a DEC \n");
  331.  printf("computer (e.g. VAX), turn off the XON/XOFF feature. \n");
  332.  r = respny();
  333.  return(r);
  334. }
  335.  
  336. bothterm()
  337. {
  338.  char r;
  339.  
  340.  clear();
  341.  printf("Are both devices terminals? \n");
  342.  r = resp("No","Yes");
  343.  if (r)
  344.    nullmodem();
  345.  return(r);
  346. }
  347.  
  348. dcedte()
  349. {
  350.  char r;
  351.  
  352.  clear();
  353.  printf("RS-232 devices fall into two classes - DTE (Data Terminal Equip.)\n");
  354.  printf("and DCE (Data Communications Equip.).  Try a full 25 pin straight\n");
  355.  printf("through cable if one device is DTE and the other DCE.  If both \n");
  356.  printf("devices are DTEs or DCEs, you need a null modem cable. The device\n");
  357.  printf("manual may indicate the device's type.\n");
  358.  blank();
  359.  printf("Devices that are usually DTEs: terminals and IBM compatible PCs.\n");
  360.  printf("Devices that are usually DCEs: modems, ports to minicomputers,\n");
  361.  printf("   printers, VME bus serial ports, and devices designed to talk \n");
  362.  printf("   with terminals such as serial ports on micro development \n");
  363.  printf("   systems. \n");
  364.  blank();
  365.  printf("Does it seem that you need a null modem cable as the devices are\n");
  366.  printf("both DTEs or DCEs? \n");
  367.  r = resp("No","Yes");
  368.  if (r)
  369.    nullmodem();
  370.  clear();
  371.  r = respny();
  372.  return(r);
  373. }
  374.  
  375.  
  376. devincomp()
  377. {
  378.  clear();
  379.  printf("The devices are probably not supplying all the signals required \n");
  380.  printf("by the other.  See someone in Digital Electronics for help. \n");
  381.  wait();
  382.  return;
  383. }
  384.  
  385.  
  386. respny()
  387. {
  388.  char r;
  389.  
  390.  blank();
  391.  printf("    Are the devices communicating properly now? \n");
  392.  r = resp("No","Yes");
  393.  return(r);
  394. }
  395.  
  396.  
  397. resp(zero,one)
  398. char *zero,*one;
  399. {
  400.  char r;
  401.  
  402.  blank();
  403.  blank();
  404.  printf("            0  - %s \n",zero);
  405.  blank();
  406.  printf("            1 -  %s \n",one);
  407.  
  408. tryagain:
  409.  scr_rowcol(22,10);
  410.  printf("Strike either the  0  or  1  key for appropriate response \n");
  411.  r = getchar();
  412.  if (r == '0')
  413.    r = 0;
  414.  else if (r == '1')
  415.    r = 1;
  416.  else
  417.    goto tryagain;
  418.  return(r);
  419. }
  420.  
  421.  
  422.  
  423. wait()
  424. {
  425.  scr_rowcol(22,10);
  426.  printf("Strike any key to continue \n");
  427.  getchar();
  428.  return;
  429. }
  430.  
  431.  
  432. clear()
  433. {
  434.  scr_clr();
  435.  scr_rowcol(1,1);
  436.  return;
  437. }
  438.  
  439. blank()
  440. {
  441.  printf(" \n");
  442.  return;
  443. }
  444.  
  445.