home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN3X / MSTARTER.ARJ / V24UNIT.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1995-01-04  |  10.4 KB  |  255 lines

  1. {------------------------------------------------------------------}
  2. { V24UNIT   Programmierung der seriellen Schnittstelle über        }
  3. {           den BIOS-Interrupt 14h                                 }
  4. {           (c) 1994 Peter Zwosta                                  }
  5. {                                                                  }
  6. { Literatur:                                                       }
  7. {      Rübsam, M., V.24/RS232 Kommunikation, S. 75 ff.,            }
  8. {                  Düsseldorf 1. Auflage 1990, Sybex               }
  9. {                  ISBN 3-88745-581-9                              }
  10. {      Tischer, M., PC-Intern 2.0, S. 959 ff., Düsseldorf          }
  11. {                  4. Auflage 1989, Data Becker ISBN 3-89011-331-6 }
  12. {------------------------------------------------------------------}
  13. Unit V24Unit;
  14.  
  15.  
  16. Interface  {*******************************************************}
  17. uses crt, Dos,
  18.      CommCons { wegen DataReady };
  19.  
  20. const
  21.  
  22.    {---------------------------------------------------------------}
  23.    { Konfigurationsbyte - Teil des Leitungssteuerregisters (LCR)   }
  24.    {                      für die Initialisierung (Fkt. 00h)       }
  25.    {---------------------------------------------------------------}
  26.  
  27.    { - Anzahl der Datenbits  Bit 0-1 ---------------------------   }
  28.    {   Databit5 bis Databit8                                       }
  29.    { - Anzahl der Stopbits   Bit 2  -----------------------------  }
  30.    {   Stopbit1 oder Stopbit2                                      }
  31.    { - Art der Parität       Bit 3-4  ---------------------------  }
  32.    {   NoParity, OddParity, EvenParity                             }
  33.    { - Übertragungsgeschwindigkeit  Bit 5-7 ---------------------  }
  34.    Baud110    = $00;    { 000x xxxx                                }
  35.    Baud150    = $80;    { 100x xxxx                                }
  36.    Baud300    = $40;    { 010x xxxx                                }
  37.    Baud600    = $C0;    { 110x xxxx                                }
  38.    Baud1200   = $20;    { 001x xxxx                                }
  39.    Baud2400   = $A0;    { 101x xxxx                                }
  40.    Baud4800   = $60;    { 011x xxxx                                }
  41.    Baud9600   = $E0;    { 111x xxxx                                }
  42.  
  43.    { ------------------------------------------------------------ }
  44.    { für die Fehlerbehandlung                                     }
  45.    { - enthält: OverrunError, ParityError, FramingError,          }
  46.    {            BreakInterrupt, TimeoutFehler                     }
  47.    { ------------------------------------------------------------ }
  48. var
  49.    bio_V24Fehler : word;
  50.  
  51. Function bio_NoModemFound(ComPort : word) : boolean;
  52. Function bio_NoPortFound(ComPort : word)  : boolean;
  53. Procedure bio_InitComPort(ComPort : word; Parameter : Byte);
  54. Procedure bio_V24WriteCh(ComPort : word; ch : char);
  55. Procedure bio_V24WriteStr(ComPort : word; s : string);
  56. Procedure bio_V24WriteCommand(ComPort : word; s : string);
  57. Function  bio_V24ReadCh(ComPort : word) : char;
  58. Function  bio_V24ReadStr(ComPort : word) : string;
  59. Function  bio_V24ReadStrL(ComPort : word; Laenge : byte) : string;
  60. Function  bio_V24Status(ComPort : word) : word;
  61. Procedure bio_ShowV24Status(Status : word);
  62.  
  63. Implementation {***************************************************}
  64.  
  65. const
  66.    WaitCh   = '~';
  67.    Ctrl     = '^';
  68.  
  69. {------------------------------------------}
  70. { bio_NOMODEMFOUND                         }
  71. { (nach InitComPort)                       }
  72. {------------------------------------------}
  73. Function bio_NoModemFound(ComPort : word) : boolean;
  74. begin
  75.   bio_NoModemFound := ((bio_V24Status(ComPort) and $00FF) = 0);
  76. end;
  77. {--------------------------------------------}
  78. { bio_NOPORTFOUND                            }
  79. { (nach InitComPort)                         }
  80. {--------------------------------------------}
  81. Function bio_NoPortFound(ComPort : word) : boolean;
  82. begin
  83.   bio_NoPortFound := ((bio_V24Status(ComPort) and $000F) > 0);
  84. end;
  85.  
  86. {----------------------------------------------}
  87. { bio_InitComPort zum Initialisieren der       }
  88. {         Schnittst. (Fkt. 00h)                }
  89. {----------------------------------------------}
  90. Procedure bio_InitComPort(ComPort : word; Parameter : Byte);
  91. var Regs : registers;
  92. begin
  93.   Regs.ah := $00;                    { Funktion 0 von 14h   }
  94.   Regs.dx := ComPort;                { dx enthält den Port  }
  95.   Regs.al := Parameter;              { Konfig-Byte setzen   }
  96.   Intr($14, Regs);                   { Interrupt aufrufen   }
  97.  
  98.   { Leitungsstatusregister holen.                           }
  99.   { AL enthält den Modemstatus und wird hier nicht benötigt.}
  100.   { AH enthält das Leitungsstatusregister mit den Fehlern.  }
  101.   {         Leitungsst. Modemst.                            }
  102.   { $9E00 = 1001 1110   0000 0000                           }
  103.   { Die Bits 0, 5 und 6 des Leitungsstatusregisters werden  }
  104.   { nicht beachtet.                                         }
  105.  
  106.   bio_V24Fehler := Regs.ax and $9E00;
  107. end;
  108. {--------------------------------------------}
  109. { bio_V24WriteCh zur Ausgabe eines Char am   }
  110. {            übergebenen Port (Fkt. 01h)     }
  111. {--------------------------------------------}
  112. Procedure bio_V24WriteCh(ComPort : word; ch : char);
  113. var Regs : registers;
  114. begin
  115.    Regs.ah := $01;                   { Funktion 01 von 14h  }
  116.    Regs.dx := ComPort;
  117.    Regs.al := ord(ch);               { Zeichen in al        }
  118.    Intr($14, Regs);
  119.    bio_V24Fehler := Regs.ax and $9E00;   { Fehler merken        }
  120. end;
  121. {---------------------------------------------}
  122. { bio_V24WriteStr zur Ausgabe eines Strings   }
  123. {---------------------------------------------}
  124. Procedure bio_V24WriteStr(ComPort : word; s : string);
  125. var i : integer;
  126. begin
  127.   For i := 1 to Length(s) do bio_V24WriteCh(ComPort, s[i]);
  128. end;
  129. {----------------------------------------------}
  130. { bio_V24WriteCommand zur Ausgabe eines Comm.  }
  131. {               ^ wird übergangen.             }
  132. {----------------------------------------------}
  133. Procedure bio_V24WriteCommand(ComPort : word; s : string);
  134. var i : integer;
  135. begin
  136.   i := 1;
  137.   While i <= Length(s) do
  138.     begin
  139.        if (s[i] = chr(ord(WaitCh))) then
  140.          begin
  141.            delay(500);
  142.          end else
  143.          begin
  144.            if (s[i] = chr(ord(Ctrl))) then
  145.              begin
  146.                inc(i);
  147.                if (s[i] = chr(ord('M')))
  148.                   then bio_V24WriteCh(ComPort, chr(13))
  149.                   else dec(i);
  150.              end else
  151.              begin
  152.                bio_V24WriteCh(ComPort, s[i]);
  153.              end;
  154.          end;
  155.        inc(i);
  156.     end;
  157. end;
  158. {--------------------------------------------}
  159. { bio_V24ReadCh  zum Lesen eines Char vom    }
  160. {            übergebenen Port (Fkt. 02h)     }
  161. { Vorher sollte mit V24Status abgefragt      }
  162. { werden, ob ein Zeichen bereitsteht.        }
  163. {--------------------------------------------}
  164. Function  bio_V24ReadCh(ComPort : word) : char;
  165. var Regs : registers;
  166. begin
  167.   Regs.ah := $02;                    { Funktion 02 von 14h  }
  168.   Regs.dx := ComPort;
  169.   Intr($14, Regs);
  170.   { ah - Bit 7 = 0, dann Zeichen in al                      }
  171.   { ah - Bit 7 = 1, kein Zeichen, Fehlerbits in ah          }
  172.   {                 in diesem Fall ist V24Fehler nach dem   }
  173.   {                 Aufruf der Fkt. <> 0                    }
  174.   bio_V24ReadCh := chr(Regs.al);   { liefert ein undefin.   }
  175.                              { Zeichen, wenn V24Fehler <> 0 }
  176.   bio_V24Fehler := Regs.ax and $9E00;
  177. end;
  178. {--------------------------------------------}
  179. { bio_V24ReadStr zum Einlesen eines Strings  }
  180. {--------------------------------------------}
  181. Function  bio_V24ReadStr(ComPort : word) : string;
  182. begin
  183.    bio_V24ReadStr := bio_V24ReadStrL(ComPort, 254);
  184. end;
  185. {---------------------------------------------}
  186. { bio_V24ReadStrL zum Einlesen eines Strings  }
  187. {              fester (max.) Länge            }
  188. {---------------------------------------------}
  189. Function  bio_V24ReadStrL(ComPort : word; Laenge : byte) : string;
  190. var s  : string;
  191.     ch : char;
  192. begin
  193.     s  := '';
  194.     ch := #00;
  195.     repeat
  196.        If ((bio_V24Status(ComPort) and (DataReady shl 8)) > 0) Then
  197.          begin
  198.              ch := bio_V24ReadCh(ComPort);
  199.              If (ch <> chr(13))         { Endekennzeichen CR }
  200.                       Then s := s + ch;
  201.          end;
  202.     until ((Length(s) = Laenge)  or       { Länge erreicht   }
  203.            (ch        = chr(13)) or       { Ende des Strings }
  204.            (bio_V24Fehler <> 0));       { Fehler           }
  205.     bio_V24ReadStrL := s;
  206. end;
  207. {-------------------------------------------------------------}
  208. { bio_V24Status     (Fkt. 03h)                                }
  209. { Fehler beim Initialisieren (direkt nach InitComPort)        }
  210. { V24Status and $00FF = 0 ->> kein Modem gefunden (Modem-     }
  211. {                             statusreg. = 0)                 }
  212. { V24Status and $000F > 0 ->> Schnittstelle nicht verfügbar   }
  213. {                             (Delta-Werte im Mod-Stat.Reg    }
  214. {                              sind auf zuf. Werte gesetzt)   }
  215. {-------------------------------------------------------------}
  216. Function  bio_V24Status(ComPort : word) : word;
  217. var Regs : registers;
  218. begin
  219.   Regs.ah := $03;                    { Funktion 03 von 14h  }
  220.   Regs.dx := ComPort;
  221.   Intr($14, Regs);
  222.   bio_V24Status := Regs.ax;        { AH := Leitungsstatus,}
  223.                                    { AL := Modemstatus    }
  224.   bio_V24Fehler := Regs.ax and $9E00;
  225. end;
  226.  
  227. {-------------------------------------------------------------}
  228. { bio_SHOWV24STATUS  zeigt den durch INT 14 Funk. $03 ermit.  }
  229. {                  Status am Bildschirm                       }
  230. {-------------------------------------------------------------}
  231. Procedure bio_ShowV24Status(Status : word);
  232. var i : integer;
  233. const MStat : array[0..15] of string =
  234.      ('DCTS', 'DDSR', 'DRI', 'DCD', 'CTS', 'DSR', 'RI', 'CD',
  235.       '   DataReady', 'OE', 'PE', 'FE', 'BI', 'THE', 'TE', 'TimeOut');
  236. begin
  237.   writeln;
  238.   { 0-7 zeigt das Modemstatusregister , }
  239.   { 8-15 das Leitungsstatusregister     }
  240.   For i := 0 to 15 do
  241.     begin
  242.       if (Status and (1 shl i)) <> 0
  243.           Then TextColor(LightRed)
  244.           Else TextColor(white);
  245.       write(MStat[i]+ ' ');
  246.     end;
  247.   writeln;
  248.   TextColor(Lightgray);
  249. end;
  250.  
  251. Begin    { Initialisierung ****************************************}
  252.  
  253.      bio_V24Fehler := $0000; { kein Fehler }
  254.  
  255. end. {*************************************************************}