home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / JBCOMM50.ZIP / JBCOMM50.DOC < prev    next >
Encoding:
Text File  |  1989-01-29  |  33.5 KB  |  1,127 lines

  1.  
  2. JBCOMM: v5.0 by Jim Berg, (c)Copyright 1988,1989
  3.  
  4. The following procedures and functions are to assist the general
  5. public with communications programming in Turbo Pascal v5.0.  Feel
  6. free to use these routines in your private programs or programs
  7. intended for the Public Domain.  If you intend to use these routines
  8. in a program that you will receive money for, be it Shareware,
  9. Commercial, or part of your professional program library, you must
  10. send $50 to (note: if you already sent, or offered to send, the
  11. previously requested $15, additional money is not neccassary, but would
  12. be appreciated):
  13.  
  14. Jim Berg
  15. 650 Minnetonka Highland Lane
  16. Long Lake, MN 55356
  17.  
  18. If you find any bugs or have any suggestions, please feel free to
  19. write me a letter.  And please, if you dig up my phone number somewhere,
  20. don't call me on the weekends.  I may be around after 6pm CST on the
  21. weekdays, but don't call after 9pm either.  I have to make a living too.
  22.  
  23. I may also be reached through the National Pascal Echo Mail area.
  24.  
  25.              ********* DISCLAIMER *************
  26.  
  27. If something goes wrong with your hardware while using this library,
  28. I hereby free myself from any liability with this disclaimer.  As far
  29. as I know, these routines work.  If something does go wrong, please
  30. contact me anyway so I may attempt to fix the program.
  31.  
  32.  
  33.  
  34. Name:     porttype
  35.  
  36. Usage:    cp : porttype;
  37.  
  38. Description:
  39.  
  40.           type porttype = (com0, com1, com2, com3, com4,
  41.                                  com5, com6, com7, com8);
  42.  
  43.           This is the type declaration for com port numbers.  JBCOMM
  44.           now supports COM0 through COM8.  COM0 is a dummy com port
  45.           that I have used for local operation of a multiuser BBS. It
  46.           works the same as the others, but you must insert the data
  47.           into the receive buffer of the port with the c_insertc and
  48.           c_inserts commands.
  49.  
  50.  
  51. Name:     parityt
  52.  
  53. Usage:    parity  : parityt;
  54.  
  55. Description:
  56.  
  57.           type parityt = (p_none,p_even,p_odd,p_even_stick,p_odd_stick);
  58.  
  59.           This is the type declaration for parity.  See c_set_uart for
  60.           more information on parity.  I won't describe the last two since
  61.           those who know what they can be used for already know enough not
  62.           to have it explained.
  63.  
  64.  
  65.  
  66. Name:     checkstr
  67.  
  68. Usage:    checklist  : array [1..n] of checkstr;
  69.  
  70. Description:
  71.  
  72.           type checkstr = string[80];
  73.  
  74.           See c_waitsn.
  75.  
  76.  
  77. Name:     com_info_rec
  78.  
  79. Usage:    info : com_info_rec;
  80.  
  81. Description:
  82.  
  83.           type
  84.             com_info_rec = record
  85.                              offset,            Base address of serial port.
  86.                              speed   : word;    Current speed setting.
  87.                              parity  : parityt; Current Parity Setting.
  88.                              data,              Current Data size.
  89.                              stops   : byte;    Current Stop bits.
  90.                              active,            TRUE if port is active.
  91.                              ints_on : boolean  TRUE if interrupts are active.
  92.                            end;
  93.  
  94.           See c_port_info and accompanying program example.
  95.  
  96.  
  97.  
  98. Name:     ESC_ON
  99.  
  100. Usage:    ESC_ON:=TRUE; or ESC_ON:=FALSE;
  101.  
  102. Description:
  103.  
  104.           var ESC_ON : boolean;
  105.  
  106.           If ESC_ON is set to TRUE, it will allow you to exit out of
  107.           c_getb and c_waitsn if the user hits ESC.  The default is
  108.           ESC_ON:=TRUE.
  109.  
  110.           See c_getb and c_waitsn.
  111.  
  112.  
  113. Name:     c_set_speed
  114.  
  115. Usage:
  116.  
  117.           procedure c_set_speed  (cp       : porttype;
  118.                                   speed    : word      );
  119. Description:
  120.  
  121.           C_set_speed will set the current speed that your serial
  122.           port will operate at.
  123.  
  124. Returns:  Nothing
  125.  
  126. Example:
  127.           If you want to set COM1 to operation at 2400 baud, you
  128.           would use it the following way:
  129.  
  130.             c_set_speed(com1,2400);
  131.  
  132.  
  133.  
  134. Name:     c_set_uart
  135.  
  136. Usage:
  137.  
  138.           procedure c_set_uart   (cp       : porttype;
  139.                                   parity   : parityt;
  140.                                   data,
  141.                                   stops    : byte    );
  142.  
  143. Description:
  144.  
  145.           C_set_uart sets the current operating format of the serial
  146.           port.  This includes the parity, data size, and stop bits
  147.           used.
  148.  
  149.           Data Bits explained:
  150.  
  151.           Most BBSes you call allow you to download binary files.  These
  152.           files are made up of a byte which are 8 bits wide.  In order
  153.           for your program to download these types of files, you have to
  154.           set your serial port for 8 data bits.  If you are calling a board
  155.           that only allows text transfers because it only uses the first
  156.           128 characters of the ASCII set, you may want to only use 7 data
  157.           bits, since that is all that is required for this type of use.
  158.           Anything less than 7 is very uncommon.
  159.  
  160.           Parity explained:
  161.  
  162.           Parity is a very simple way of doing error correction.  If you
  163.           were to select EVEN parity, this means that it will send an equal
  164.           number of 1 bits as it does 0 bits.  If you receive a character
  165.           that has more 1 bits, or more 0 bits than its opposite, they you
  166.           can assume that the character was sent wrong.  The serial port
  167.           will set some bits in the Line Status Register to inform you of
  168.           these type of errors.
  169.  
  170.           ODD is the opposite of EVEN obviously. This means that an odd
  171.           number of bits will be sent.
  172.  
  173.           NONE means that there is no parity at all.  This has to be used if
  174.           you are using 8 data bits.
  175.  
  176.           Stop bits explained:
  177.  
  178.           A stop bit tells when a character is finished.  There is
  179.           no real difference between 1 and 2, but most people use 1.
  180.  
  181. Returns:  Nothing
  182.  
  183. Example:
  184.           Say you wanted to write a program to call your local Opus board
  185.           and you wanted to get all of the special text graphic characters
  186.           and be able to download a binary game.  You would then have to
  187.           set your serial port 1 to use 8 data bits, No Parity, and 1 stop
  188.           bit.  To do this you would use:
  189.  
  190.             c_set_uart(com1,p_none,8,1);
  191.  
  192.  
  193.  
  194. Name:     c_open
  195.  
  196. Usage:
  197.  
  198.           procedure c_open       (cp       : porttype;
  199.                                   speed    : word;
  200.                                   parity   : parityt;
  201.                                   data,
  202.                                   stops    : byte;
  203.                                   ibuffs,
  204.                                   obuffs   : word     );
  205.  
  206. Description:
  207.  
  208.          C_open starts the ball rolling for communications.  It sets
  209.          up the serial port to use interrupts and sets the size of
  210.          the input buffer and output buffer.  You should call this
  211.          procedure before using any of the other communication
  212.          routines.  If a command can be used without calling this
  213.          first, I will let you know.
  214.  
  215.          Speed, parity, data and stops are pretty much explained above.
  216.          C_open calls those routines.  IBUFFS and OBUFFS are the only
  217.          things really new here.  JBCOMM uses both an output and input
  218.          buffer.
  219.  
  220.          If your program does a lot of extra things before grabbing the
  221.          character from the serial port, that character may be lost if
  222.          you do not grab it before a new character comes in.  To get
  223.          around this JBCOMM uses the ability of the serial port to cause
  224.          and interrupt.  What this means is that when a character is
  225.          received, the computer will save your spot in the program, then
  226.          jump automatically to a routine to grab the character and then
  227.          puts that character into a buffer to store it until you need it.
  228.          This is what IBUFFS is for. It sets aside the number of bytes you
  229.          specify for an input buffer.
  230.  
  231.          The serial port also has the ability to cause an interrupt when
  232.          its transmit register becomes empty.  This makes it possible
  233.          for you to load characters into a buffer and the interrupt routine
  234.          will send them when it is able.  This makes it so you are not
  235.          always having to wait for your character to be sent.  OBUFFS is
  236.          used to tell JBCOMM how much space to set aside for your output
  237.          buffer.
  238.  
  239. Example:
  240.          You want to communicate with an Opus system and you want an input
  241.          buffer of 4096 bytes and an output buffer of 256 bytes.  You would
  242.          then use.
  243.  
  244.            c_open(com1,2400,p_none,8,1,4096,256);
  245.  
  246.  
  247.  
  248. Name:    c_close
  249.  
  250. Usage:
  251.  
  252.          procedure c_close      (cp       : porttype;
  253.                                  dropdtr  : boolean  );
  254.  
  255. Description:
  256.  
  257.          C_close turns off interrupts and releases memory reserved with
  258.          c_open.  See c_open.  Dropdtr tells whether you want to leave
  259.          the port active, or to turn it off completely.  If you leave
  260.          the port active by passing dropdtr as FALSE, you can leave your
  261.          program without hanging up or disconnecting.  This may be useful
  262.          if you are writing a BBS that uses doors, or if you want to write
  263.          a COMM program that uses external protocals.  When you come back
  264.          into the program, you can do another call to c_open.
  265.  
  266. Returns: Nothing.
  267.  
  268. Example:
  269.  
  270.          You are all done with communications and you want to shutdown the
  271.          serial port and interrupts.  You would then use.
  272.  
  273.            c_close(com1,TRUE);
  274.  
  275.          You want to execute or leave your program to run a program that
  276.          has its own communication handler so you want to turn off your
  277.          interrupts but leave the port active.  You would then use.
  278.  
  279.            c_close(com1,FALSE);
  280.  
  281.  
  282.  
  283. Name:    c_inready
  284.  
  285. Usage:
  286.  
  287.          function  c_inready( cp : porttype ) : word;
  288.  
  289. Description:
  290.  
  291.          C_inready is a function that returns the number of characters
  292.          waiting in the input buffer.
  293.  
  294. Returns: Number of characters waiting to be read in input buffer.
  295.  
  296. Example:
  297.  
  298.          C_inready can be used much like Keypressed.  C_inready returns
  299.          more information however.  If you want to use it just like
  300.          Keypressed, you can use.
  301.  
  302.            if c_inready(com1)>0 then { get character from buffer}
  303.  
  304.          C_inready can also be used to wait for a certain number of
  305.          characters are in the buffer before you do something.  Say
  306.          you needed to wait for 30 characters, then you would use.
  307.  
  308.            repeat until c_inready(com1)>=30;
  309.  
  310.  
  311.  
  312. Name:    c_outready
  313.  
  314. Usage:
  315.  
  316.          function  c_outready( cp :porttype ):word;
  317.  
  318. Description:
  319.  
  320.          Will return the number of characters waiting in the output
  321.          buffer to be sent.  This is much like c_inready except it
  322.          is for the outgoing characters.
  323.  
  324. Returns: Number of characters waiting in output buffer.
  325.  
  326. Example:
  327.  
  328.          C_outready can be useful for monitoring how communications are
  329.          going, or if you don't want to overflow the outgoing buffer.
  330.  
  331.          You could use it if you want to make sure you don't try to add
  332.          more characters to the output buffer if it is already half full.
  333.          Say you have a 1k output buffer, you could use.
  334.  
  335.            repeat until c_outready(com1)<512;
  336.            {  Send characters }
  337.  
  338.  
  339.  
  340. Name:    c_putc
  341.  
  342. Usage:
  343.  
  344.          procedure c_putc(cp : porttype;
  345.                           ch : char     );
  346.  
  347. Description:
  348.  
  349.          Sends character ch out through the serial port.  If the buffer
  350.          is full, it will wait 2 seconds for space to become available
  351.          and then exit after the 2 seconds.  It would be best to check
  352.          the port with c_outready to make sure room is available so
  353.          characters wont be lost.
  354.  
  355. Returns: Nothing.
  356.  
  357. Example:
  358.  
  359.          Use it if you simply want to send a character through the serial
  360.          port.
  361.  
  362.            c_putc(com1,^M);
  363.  
  364.          The above sends a carriage return through the serial port.
  365.  
  366.  
  367.  
  368. Name:    c_insertc
  369.  
  370. Usage:
  371.  
  372.          procedure c_insertc(cp : porttype;
  373.                              ch : char      );
  374.  
  375. Description:
  376.  
  377.          This procedure will put a character in the input buffer as if
  378.          it were received from the serial port.
  379.  
  380. Returns: Nothing.
  381.  
  382. Example:
  383.  
  384.          C_insertc has an advanced usage.  I use it for a multi-user
  385.          BBS I am working on.  I have several tasks running at the same
  386.          time and one of them is a local sysop task.  What it does is to
  387.          monitor the keyboard to see if a normal key has been pressed, and
  388.          if one is, it grabs the character and inserts it into the input
  389.          buffer of the currently selected active BBS task.  If it is a
  390.          function key, I just execute the sysop command that goes with it.
  391.          It is something like this.
  392.  
  393.            var ch          : char;
  394.                active_port : porttype;
  395.  
  396.            begin
  397.              repeat
  398.                if keypressed then
  399.                begin
  400.                  ch:=readkey;
  401.                  if ch=#0 then
  402.                  begin
  403.                    ch:=readkey;
  404.                    case ch of
  405.                      #59:{function key 1 thing};
  406.                      #60:{function key 2 thing};
  407.                      . . .
  408.                    end
  409.                  end
  410.                  else c_insertc(active_port,ch)
  411.                end
  412.              until {whatever is needed to exit};
  413.            end.
  414.  
  415.          When the character is inserted, it will be read from the
  416.          serial port as if it came over the modem or from some other
  417.          form of serial device.
  418.  
  419.  
  420.  
  421. Name:    c_inserts
  422.  
  423. Usage:
  424.  
  425.          procedure c_inserts(cp       : porttype;
  426.                              outstr   : comstr   );
  427.  
  428. Description:
  429.  
  430.          This does pretty much the same as c_insertc except that it
  431.          sends a whole string rather than a single character.  If
  432.          you put a | in the string, it will be interpreted as a
  433.          carriage return.
  434.  
  435. Returns: Nothing.
  436.  
  437. Example:
  438.  
  439.          The example is pretty much the same as for c_insertc except
  440.          it can be used to fool your program into thinking a certain
  441.          string has been sent.  I use it to fool the modem into thinking
  442.          a CONNECT has been sent from the modem.
  443.  
  444.            c_inserts(com1,'CONNECT|'#10);
  445.  
  446.  
  447.  
  448. Name:     c_getc
  449.  
  450. Usage:
  451.  
  452.           function c_getc(cp : porttype ) : char;
  453.  
  454. Description:
  455.  
  456.           Gets a character from the input buffer.  This is much like
  457.           readkey except it is for the serial port.  If character is
  458.           not in input buffer, it will wait for a character to be
  459.           available.
  460.  
  461. Returns:  Character that has been received by serial port and stored
  462.           in input buffer.
  463.  
  464. Example:
  465.           This is pretty basic.  Use it when you want to get a character
  466.           from the serial port.
  467.  
  468.             var ch : char;
  469.  
  470.             begin
  471.               ...
  472.               ch:=c_getc(com1);
  473.             end;
  474.  
  475.  
  476.  
  477. Name:     c_peekc
  478.  
  479. Usage:
  480.  
  481.           function  c_peekc(cp : porttype ) : char;
  482.  
  483. Description:
  484.  
  485.           This is much like c_getc except that it will return the character
  486.           waiting in the input buffer, but will not remove it.  It will
  487.           allow you to "peek" at the character before you "get" the character.
  488.  
  489. Returns:  It will return the value of the next character waiting in input
  490.           buffer.
  491.  
  492. Example:
  493.  
  494.           Use it to watch incoming characters and dispose of unwanted
  495.           characters until the one you want is found.  Maybe there is
  496.           a string that begins with and ESC that you want to get, but
  497.           you don't want any of the characters before the escape.  You
  498.           could use
  499.  
  500.             var ch : char;
  501.  
  502.             begin
  503.               . . .
  504.               while peekc(com1)<>#27 then ch:=c_getc(com1);
  505.               . . .
  506.             end.
  507.  
  508.           Yes, I know, this isn't the best example, but it does have a
  509.           use.  The keyboard BIOS has something similar.
  510.  
  511. Name:     c_flush_in
  512.  
  513. Usage:
  514.  
  515.           procedure c_flush_in(cp : porttype );
  516.  
  517. Description:
  518.  
  519.           Clears the input buffer.  Removes characters that may be
  520.           waiting in the input buffer.
  521.  
  522. Returns:  Nothing.
  523.  
  524. Example:
  525.  
  526.           In an Xmodem transfer you may get more characters then you
  527.           wanted and the extra characters are most likely unwanted
  528.           so you would use c_flush_in to clear the input buffer.
  529.  
  530.             c_flush_in(com1);
  531.  
  532.  
  533.  
  534. Name:     c_flush_out
  535.  
  536. Usage:
  537.  
  538.           procedure c_flush_out(cp : porttype );
  539.  
  540. Description:
  541.  
  542.           Clears the output buffer of any characters that have not been
  543.           sent yet.
  544.  
  545. Returns:  Nothing.
  546.  
  547. Example:
  548.           If you are sending out a file and you receive a ^C to cancel it,
  549.           you may want to flush the buffer to make it act more quickly.
  550.  
  551.             c_flush_out(com1);
  552.  
  553.  
  554.  
  555. Name:     c_carrier
  556.  
  557. Usage:
  558.  
  559.           function c_carrier(cp : porttype ):boolean;
  560.  
  561. Description:
  562.  
  563.           Tells you if your serial port detects that a carrier is present.
  564.  
  565. Returns:  TRUE if there is a carrier present.
  566.  
  567. Example:
  568.  
  569.           In a BBS program, this would be used to monitor whether someone
  570.           is still online, or if they hangup.
  571.  
  572.             if c_carrier(com1) then
  573.               {person is still connected}
  574.             else
  575.               {person has hung up}
  576.  
  577.  
  578.  
  579. Name:     c_toggle_DTR
  580.  
  581. Usage:
  582.  
  583.           procedure c_toggle_DTR (cp : porttype );
  584.  
  585. Description:
  586.  
  587.           Turn DTR bit on if it is off, or off if it is on.
  588.  
  589. Returns:  Nothing.
  590.  
  591. Example:
  592.  
  593.           The DTR is what keeps a port active.  When you open the
  594.           serial port the DTR is set on.  If you wanted to disconnect
  595.           someone, you would clear the DTR to off for a certain amount
  596.           of time, then turn it back on.
  597.  
  598.             c_toggle_DTR(com1);
  599.             delay(500); {half second}
  600.             c_toggle_DTR(com1);
  601.  
  602.           NOTE:  This will not work correctly if your modem is set so
  603.           that the DTR is always on.
  604.  
  605.  
  606.  
  607. Name:     c_send_break
  608.  
  609. Usage:
  610.  
  611.           procedure c_send_break (cp       : porttype;
  612.                                   duration : word     );
  613.  
  614. Description:
  615.  
  616.           This sends a break signal over the serial port for
  617.           duration hundreds of a second.
  618.  
  619. Returns:  Nothing.
  620.  
  621. Example:
  622.           Sometimes certain systems require you to send a break
  623.           signal to stop something, or to disconnect properly.
  624.  
  625.             c_send_break(com1,100);
  626.  
  627.           The above example sends a break signal for 1 second.
  628.  
  629.  
  630.  
  631. Name:     c_puts
  632.  
  633. Usage:
  634.           procedure c_puts(cp       : porttype;
  635.                            outstr   : comstr   );
  636.  
  637. Description:
  638.  
  639.           This sends a string out through the serial port.  A | is
  640.           sent as a carriage return and a ~ is used as a 1/4 second
  641.           delay.  This is a lot like a lot of terminal init strings.
  642.  
  643. Returns:  Nothing.
  644.  
  645. Example:
  646.  
  647.           Use this to send init strings or dialing commands.
  648.  
  649.             c_puts(com1,'ATDT 555-5555|~~~');
  650.  
  651.           The above sends the dialing command followed by a carriage
  652.           return and a 3 quarters of a second delay.
  653.  
  654.  
  655.  
  656. Name:     c_getb
  657.  
  658. Usage:
  659.           function  c_getb(cp       : porttype;
  660.                            timeout  : word     ) : integer;
  661.  
  662. Description:
  663.  
  664.           This waits timeout hundreds of a second for a character.
  665.  
  666. Returns:  ASCII value character received, or a -1 if it times out, or
  667.           a -2 if ESC is hit.
  668.  
  669. Example:
  670.  
  671.           Use this for download procedures.  There are times when you
  672.           have to wait a certain amount of time for a character, and
  673.           if it doesn't arrive, you return and error.
  674.  
  675.             var inch : integer;
  676.  
  677.             begin
  678.               . . .
  679.               inch:=c_getb(com1,100);  { Wait 1 second for character}
  680.               if inch=-1 then
  681.                 writeln('Timeout')
  682.               else
  683.               begin
  684.                 {chr(lo(inch)) equals character you received.'}
  685.               end
  686.             end;
  687.  
  688.  
  689.  
  690. Name:     c_waits
  691.  
  692. Usage:
  693.  
  694.           function  c_waits(cp       : porttype;
  695.                             chkstr   : checkstr;
  696.                             timeout  : word     ) : boolean;
  697.  
  698. Description:
  699.  
  700.           This function will wait timeout hundreds of a second for
  701.           string chkstr to be received from the serial port.
  702.  
  703. Returns:  TRUE if string is received.  FALSE if it times out.
  704.  
  705. Example:
  706.  
  707.           Sometimes you may want to wait for a certain string to be
  708.           returned through the serial port.  I had to write a program
  709.           once that checked to see if the modem supported 2400 baud or
  710.           not.  The only way I could check was to set the serial port for
  711.           2400 baud, enter an AT <CR>, and wait to see if it returned OK.
  712.           If it didn't, I knew it didn't like 2400 baud.
  713.  
  714.             c_set_speed(com1,2400);
  715.             c_puts(com1,'AT|~');
  716.             if c_waits(com1,'OK',500) then
  717.               writeln('Modem supports 2400 baud.')
  718.             else
  719.               writeln('Modem doesn''t support 2400 baud.');
  720.  
  721.           NOTE:  Some modems will communicate with the serial port at speeds
  722.           that the modem does not support.
  723.  
  724.  
  725.  
  726. Name:     c_waitsn
  727.  
  728. Usage:
  729.  
  730.           function  c_waitsn(cp       : porttype;
  731.                              var clst;{:array[1..n] of checkstr}
  732.                              n        : byte;
  733.                              timeout  : word     ) : integer;
  734.  
  735. Description:
  736.  
  737.           This will wait timeout hundreds of a second for a string
  738.           in clst to be returned from the modem.  n tells you the
  739.           number of strings in clst.
  740.  
  741. Returns:  -2 if ESC is hit, -1 if it times out, or the number of the
  742.           string that matched.
  743.  
  744. Example:
  745.  
  746.           This is one of the most useful commands of JBCOMM.  Use it for
  747.           autodialing.
  748.  
  749.           var  checklist : array [1..5] of checkstr;
  750.                result    : integer;
  751.  
  752.           begin
  753.             . . .
  754.             checklist[1]:='CONNECT'#13#10;
  755.             checklist[2]:='CONNECT 1200'#13#10;
  756.             checklist[3]:='CONNECT 2400'#13#10;
  757.             checklist[4]:='NO CARRIER'#13#10;
  758.             checklist[5]:='BUSY'#13#10;
  759.             repeat
  760.               c_puts(com1,'ATDT 555-5555|~~');
  761.               result:=c_waitsn(com1,checklist,5,6000);
  762.               case result of
  763.                -2:writeln('Dialing aborted');
  764.                -1:writeln('Timeout');
  765.                 1:writeln('Connected at 300 baud');
  766.                 2:writeln('Connected at 1200 baud');
  767.                 3:writeln('Connected at 2400 baud');
  768.                 4:writeln('No Carrier');
  769.                 5:writeln('Busy')
  770.               end;
  771.             until ((result<4) and (result>0)) or (result=-1);
  772.             . . .
  773.           end.
  774.  
  775.  
  776.  
  777. Name:    c_get_stream
  778.  
  779. Usage:
  780.          function  c_get_stream (cp       : porttype;
  781.                                  var getbuf;
  782.                                  n        : word     ) : word;
  783.  
  784. Description:
  785.  
  786.          This will grab n bytes out of the input buffer and store
  787.          them in getbuf.  If n bytes are not available, it will
  788.          return with whatever bytes were available.
  789.  
  790. Returns: Actual number of bytes grabbed.
  791.  
  792. Example:
  793.  
  794.          This is useful for getting blocks of data from the serial
  795.          port.  Say you wanted to get 131 characters from the input
  796.          buffer, you could use:
  797.  
  798.            var buffer   : array [1..131] of byte;
  799.                received : word;
  800.  
  801.            begin
  802.              . . .
  803.              received:=c_get_stream(com1,buffer,131);
  804.              if received<131 then
  805.                writeln('All data not received.')
  806.              else
  807.                writeln('Data received.');
  808.              . . .
  809.            end.
  810.  
  811.          CAUTION:  Make sure you have the correct amount of space
  812.          reserved for getbuf, or it may overwrite some important data.
  813.  
  814.  
  815.  
  816. Name:     c_tget_stream
  817.  
  818. Usage:
  819.  
  820.           function  c_tget_stream(cp       : porttype;
  821.                                   var getbuf;
  822.                                   n,
  823.                                   timeout  : word       ) : word;
  824.  
  825. Description:
  826.  
  827.           This is similar to c_get_stream, except that it will wait
  828.           timeout hundreds of a second to receive each byte of the
  829.           data.  This means that if there is no data received within
  830.           timeout hundreds of a second, it will exit with what it was
  831.           able to get.
  832.  
  833. Returns:  Number of bytes received.
  834.  
  835. Example:
  836.  
  837.          This is useful for getting blocks of data from the serial
  838.          port in transfer protocals.  Say you wanted to get 131
  839.          characters from the input buffer like in c_get_stream, but
  840.          you wanted it to wait 1 second before it timed out, you would
  841.          use:
  842.  
  843.            var buffer   : array [1..131] of byte;
  844.                received : word;
  845.  
  846.            begin
  847.              . . .
  848.              received:=c_tget_stream(com1,buffer,131,100);
  849.              if received<131 then
  850.                writeln('All data not received. Timed out.')
  851.              else
  852.                writeln('Data received.');
  853.              . . .
  854.            end.
  855.  
  856.          CAUTION:  Make sure you have the correct amount of space
  857.          reserved for getbuf, or it may overwrite some important data.
  858.  
  859.  
  860.  
  861. Name:    c_put_stream
  862.  
  863. Usage:
  864.  
  865.          function  c_put_stream (cp       : porttype;
  866.                                  var putbuf;
  867.                                  n        : word     ) : word;
  868.  
  869. Description:
  870.  
  871.          This will put n number of characters in putbuf in to the output
  872.          buffer.  If the output buffer is full, it will just quit.
  873.  
  874. Returns: Number of characters successfully put in output buffer.
  875.  
  876. Example:
  877.  
  878.          This is useful for putting blocks of data to the serial
  879.          port in transfer protocals.  Say you wanted to send 131
  880.          characters to the output buffer, you would use:
  881.  
  882.            var buffer   : array [1..131] of byte;
  883.                sent     : word;
  884.  
  885.            begin
  886.              . . .
  887.              sent:=c_put_stream(com1,buffer,131);
  888.              if sent<131 then
  889.                writeln('All data not sent. Buffer is full.')
  890.              else
  891.                writeln('Data sent.');
  892.              . . .
  893.            end.
  894.  
  895.  
  896.  
  897. Name:     c_statusm
  898.  
  899. Usage:
  900.  
  901.           function  c_statusm(cp : porttype ) : byte;
  902.  
  903. Description:
  904.  
  905.           Gets the contents of the Modem Status Register at last
  906.           modem status interrupt.
  907.  
  908.           c_DCTS            = 1;   Delta CTS.  This means that CTS status
  909.                                    has changed.
  910.           c_DDSR            = 2;   Delta DSR.  This means that DSR status
  911.                                    has changed.
  912.           c_TERI            = 4;   Tail End Ring Indicator.  This tells you
  913.                                    whether the phone is ringing.
  914.           c_DRLSD           = 8;   Delta Received Line Signal Detect.  This
  915.                                    tells you if the carrier status has changed.
  916.           c_CTS             = 16;  Current status of CTS.
  917.           c_DSR             = 32;  Current status of DSR.
  918.           c_RI              = 64;  Current status of Ring Indicator.
  919.           c_RLSD            = 128; Current Carrier Status.
  920.  
  921. Returns:  Contents of Modem Status Register.
  922.  
  923. Example:  None of this is all that useful, but if you need to use it you
  924.           can check if a certain bit is set by ANDing the CONST you want
  925.           with the result of c_statusm.
  926.  
  927.             var result : byte;
  928.  
  929.             begin
  930.               . . .
  931.               result:=c_statusm(com1);
  932.               if result and c_RLSD>0 then
  933.                 writeln('Carrier was on at last Modem Status Interrupt.');
  934.               . . .
  935.             end.
  936.  
  937.  
  938.  
  939. Name:     c_statusl
  940.  
  941. Usage:
  942.           function  c_statusl(cp : porttype ) : byte;
  943.  
  944. Description:
  945.  
  946.           Gets the contents of the Line Status Register at last
  947.           line status register interrupt.
  948.  
  949.           c_DR              = 1;   Data waiting in Receive buffer register.
  950.           c_OR              = 2;   Data overun error.
  951.           c_PE              = 4;   Parity Error.
  952.           c_FE              = 8;   Framing Error.
  953.           c_BI              = 16;  Break Interrupt.
  954.           c_THRE            = 32;  Transmitter Holding Register empty.
  955.           c_TSRE            = 64;  Transmitter Shift Register empty.
  956.           c_BO              = 128; Buffer Overflow.
  957.  
  958. Returns:  Value of LSR at last line status interrupt.
  959.  
  960. Example:  None of this is all that useful, but if you need to use it you
  961.           can check if a certain bit is set by ANDing the CONST you want
  962.           with the result of c_statusl.  The reason this isn't very useful
  963.           is that JBCOMM takes care of most of this.  c_OR, c_PE, c_FE, c_BI
  964.           and c_BO may be some things you would want to check.
  965.  
  966.             var result : byte;
  967.  
  968.             begin
  969.               . . .
  970.               result:=c_statusl(com1);
  971.               if result and c_BI>0 then
  972.                 writeln('Break was sent.');
  973.               . . .
  974.             end.
  975.  
  976.  
  977.  
  978. Name:     c_lastint
  979.  
  980. Usage:
  981.  
  982.           function  c_lastint(cp : porttype ):byte;
  983.  
  984. Description:
  985.  
  986.           Gets the contents of the interrupt ID register at last interrupt.
  987.  
  988.           c_NONE            = 1;  There was no interrupt.
  989.           c_DATA_READY      = 4;  Data came in through serial port.
  990.           c_THR_EMPTY       = 2;  Data sent through serial port.
  991.           c_LINE_STATUS     = 6;  Line Status has changed.
  992.           c_MODEM_STATUS    = 0;  Modem Status has changed.
  993.  
  994. Returns:  Value of Interrupt ID register at last interrupt.
  995.  
  996. Example:  None of this is all that useful, but if you need to use it you
  997.           can check if a certain bit is set by ANDing the CONST you want
  998.           with the result of c_lastint.
  999.  
  1000.             var result : byte;
  1001.  
  1002.             begin
  1003.               . . .
  1004.               result:=c_lastint(com1);
  1005.               if result and c_DATA_READY>0 then
  1006.                 writeln('The last interrupt was a data ready interrupt.');
  1007.               . . .
  1008.             end.
  1009.  
  1010.  
  1011.  
  1012. Name:     c_port_info
  1013.  
  1014. Usage:
  1015.  
  1016.           procedure c_port_info(cp       : porttype;
  1017.                                 var info : com_info_rec);
  1018.  
  1019. Description:
  1020.  
  1021.           Returns current status of serial port in a record of type:
  1022.  
  1023.           com_info_rec = record
  1024.                            offset,             Base address of serial port.}
  1025.                            speed   : word;     Current speed setting.      }
  1026.                            parity  : parityt;  Current Parity Setting.
  1027.                            data,               Current Data size.
  1028.                            stops   : byte;     Current Stop bits.
  1029.                            active,             TRUE if port is active.
  1030.                            ints_on : boolean   TRUE if interrupts are active.
  1031.                          end;
  1032.  
  1033. Returns:  Information in info.
  1034.  
  1035. Example:
  1036.           See accompanying program example.
  1037.  
  1038.  
  1039.  
  1040. Name:     c_port_data
  1041.  
  1042. Usage:
  1043.  
  1044.           procedure c_port_data(cp       : porttype;
  1045.                                 offset   : word;
  1046.                                 irql     : byte     );
  1047.  
  1048. Description:
  1049.  
  1050.           Sets up the additional information needed to access ports beyond
  1051.           COM2.  This procedure is for the advanced user who wants to be
  1052.           able to open more than the standard 2 serial ports.  Certain
  1053.           multiport serial cards give you the ability to set what port
  1054.           offsets you wish to use and what IRQ levels to use.  This
  1055.           procedure is used to tell JBCOMM what these values are.
  1056.  
  1057. Returns:  Nothing.
  1058.  
  1059. Example:
  1060.           The code to set up COM1 would look like this:
  1061.  
  1062.           c_port_data(com1,$3F8,4);
  1063.  
  1064.           Note that it is not neccassary to set up COM1 or COM2, I use COM1
  1065.           as an example because you are probably already familiar with the
  1066.           values it uses.
  1067.  
  1068.  
  1069.  
  1070. Name:     CRC_update
  1071.  
  1072. Usage:
  1073.           function  CRC_update(crc      : word;
  1074.                                b        : byte     ) : word;
  1075.  
  1076. Description:
  1077.  
  1078.           Calculates b into a CRC.
  1079.  
  1080. Returns:  Updated CRC.
  1081.  
  1082. Example:
  1083.           This is for doing Xmodem CRC transfers.
  1084.  
  1085.             var CRC    : word;
  1086.                 buffer : array [1..128] of byte;
  1087.                 i      : word;
  1088.             begin
  1089.               . . .
  1090.               CRC:=0;
  1091.               for i:=1 to 128 do CRC:=CRC_update(CRC,buffer[i]);
  1092.               CRC:=CRC_update(CRC,0);
  1093.               CRC:=CRC_update(CRC,0);
  1094.               . . . {CRC now contains the CRC of the 128 byte block.}
  1095.             end.
  1096.  
  1097.  
  1098.  
  1099. Name:     block_CRC
  1100.  
  1101. Usage:
  1102.  
  1103.           function  block_CRC(var block;
  1104.                               n        : word ) : word;
  1105.  
  1106. Description:
  1107.  
  1108.           Calculates a CRC for n bytes of memory starting with block.
  1109.  
  1110. Returns:  CRC for n bytes of memory pointed to by block.
  1111.  
  1112. Example:
  1113.           This is for doing Xmodem CRC transfers.  block_CRC does the
  1114.           same as the example for CRC_update.
  1115.  
  1116.             var CRC    : word;
  1117.                 buffer : array [1..128] of byte;
  1118.                 i      : word;
  1119.             begin
  1120.               . . .
  1121.               CRC:=block_CRC(buffer,128);
  1122.               . . . {CRC now contains the CRC of the 128 byte block.}
  1123.             end.
  1124.  
  1125.  
  1126.  
  1127.