home *** CD-ROM | disk | FTP | other *** search
- {------------------------------------------------------------------}
- { V24UNIT Programmierung der seriellen Schnittstelle über }
- { den BIOS-Interrupt 14h }
- { (c) 1994 Peter Zwosta }
- { }
- { Literatur: }
- { Rübsam, M., V.24/RS232 Kommunikation, S. 75 ff., }
- { Düsseldorf 1. Auflage 1990, Sybex }
- { ISBN 3-88745-581-9 }
- { Tischer, M., PC-Intern 2.0, S. 959 ff., Düsseldorf }
- { 4. Auflage 1989, Data Becker ISBN 3-89011-331-6 }
- {------------------------------------------------------------------}
- Unit V24Unit;
-
-
- Interface {*******************************************************}
- uses crt, Dos,
- CommCons { wegen DataReady };
-
- const
-
- {---------------------------------------------------------------}
- { Konfigurationsbyte - Teil des Leitungssteuerregisters (LCR) }
- { für die Initialisierung (Fkt. 00h) }
- {---------------------------------------------------------------}
-
- { - Anzahl der Datenbits Bit 0-1 --------------------------- }
- { Databit5 bis Databit8 }
- { - Anzahl der Stopbits Bit 2 ----------------------------- }
- { Stopbit1 oder Stopbit2 }
- { - Art der Parität Bit 3-4 --------------------------- }
- { NoParity, OddParity, EvenParity }
- { - Übertragungsgeschwindigkeit Bit 5-7 --------------------- }
- Baud110 = $00; { 000x xxxx }
- Baud150 = $80; { 100x xxxx }
- Baud300 = $40; { 010x xxxx }
- Baud600 = $C0; { 110x xxxx }
- Baud1200 = $20; { 001x xxxx }
- Baud2400 = $A0; { 101x xxxx }
- Baud4800 = $60; { 011x xxxx }
- Baud9600 = $E0; { 111x xxxx }
-
- { ------------------------------------------------------------ }
- { für die Fehlerbehandlung }
- { - enthält: OverrunError, ParityError, FramingError, }
- { BreakInterrupt, TimeoutFehler }
- { ------------------------------------------------------------ }
- var
- bio_V24Fehler : word;
-
- Function bio_NoModemFound(ComPort : word) : boolean;
- Function bio_NoPortFound(ComPort : word) : boolean;
- Procedure bio_InitComPort(ComPort : word; Parameter : Byte);
- Procedure bio_V24WriteCh(ComPort : word; ch : char);
- Procedure bio_V24WriteStr(ComPort : word; s : string);
- Procedure bio_V24WriteCommand(ComPort : word; s : string);
- Function bio_V24ReadCh(ComPort : word) : char;
- Function bio_V24ReadStr(ComPort : word) : string;
- Function bio_V24ReadStrL(ComPort : word; Laenge : byte) : string;
- Function bio_V24Status(ComPort : word) : word;
- Procedure bio_ShowV24Status(Status : word);
-
- Implementation {***************************************************}
-
- const
- WaitCh = '~';
- Ctrl = '^';
-
- {------------------------------------------}
- { bio_NOMODEMFOUND }
- { (nach InitComPort) }
- {------------------------------------------}
- Function bio_NoModemFound(ComPort : word) : boolean;
- begin
- bio_NoModemFound := ((bio_V24Status(ComPort) and $00FF) = 0);
- end;
- {--------------------------------------------}
- { bio_NOPORTFOUND }
- { (nach InitComPort) }
- {--------------------------------------------}
- Function bio_NoPortFound(ComPort : word) : boolean;
- begin
- bio_NoPortFound := ((bio_V24Status(ComPort) and $000F) > 0);
- end;
-
- {----------------------------------------------}
- { bio_InitComPort zum Initialisieren der }
- { Schnittst. (Fkt. 00h) }
- {----------------------------------------------}
- Procedure bio_InitComPort(ComPort : word; Parameter : Byte);
- var Regs : registers;
- begin
- Regs.ah := $00; { Funktion 0 von 14h }
- Regs.dx := ComPort; { dx enthält den Port }
- Regs.al := Parameter; { Konfig-Byte setzen }
- Intr($14, Regs); { Interrupt aufrufen }
-
- { Leitungsstatusregister holen. }
- { AL enthält den Modemstatus und wird hier nicht benötigt.}
- { AH enthält das Leitungsstatusregister mit den Fehlern. }
- { Leitungsst. Modemst. }
- { $9E00 = 1001 1110 0000 0000 }
- { Die Bits 0, 5 und 6 des Leitungsstatusregisters werden }
- { nicht beachtet. }
-
- bio_V24Fehler := Regs.ax and $9E00;
- end;
- {--------------------------------------------}
- { bio_V24WriteCh zur Ausgabe eines Char am }
- { übergebenen Port (Fkt. 01h) }
- {--------------------------------------------}
- Procedure bio_V24WriteCh(ComPort : word; ch : char);
- var Regs : registers;
- begin
- Regs.ah := $01; { Funktion 01 von 14h }
- Regs.dx := ComPort;
- Regs.al := ord(ch); { Zeichen in al }
- Intr($14, Regs);
- bio_V24Fehler := Regs.ax and $9E00; { Fehler merken }
- end;
- {---------------------------------------------}
- { bio_V24WriteStr zur Ausgabe eines Strings }
- {---------------------------------------------}
- Procedure bio_V24WriteStr(ComPort : word; s : string);
- var i : integer;
- begin
- For i := 1 to Length(s) do bio_V24WriteCh(ComPort, s[i]);
- end;
- {----------------------------------------------}
- { bio_V24WriteCommand zur Ausgabe eines Comm. }
- { ^ wird übergangen. }
- {----------------------------------------------}
- Procedure bio_V24WriteCommand(ComPort : word; s : string);
- var i : integer;
- begin
- i := 1;
- While i <= Length(s) do
- begin
- if (s[i] = chr(ord(WaitCh))) then
- begin
- delay(500);
- end else
- begin
- if (s[i] = chr(ord(Ctrl))) then
- begin
- inc(i);
- if (s[i] = chr(ord('M')))
- then bio_V24WriteCh(ComPort, chr(13))
- else dec(i);
- end else
- begin
- bio_V24WriteCh(ComPort, s[i]);
- end;
- end;
- inc(i);
- end;
- end;
- {--------------------------------------------}
- { bio_V24ReadCh zum Lesen eines Char vom }
- { übergebenen Port (Fkt. 02h) }
- { Vorher sollte mit V24Status abgefragt }
- { werden, ob ein Zeichen bereitsteht. }
- {--------------------------------------------}
- Function bio_V24ReadCh(ComPort : word) : char;
- var Regs : registers;
- begin
- Regs.ah := $02; { Funktion 02 von 14h }
- Regs.dx := ComPort;
- Intr($14, Regs);
- { ah - Bit 7 = 0, dann Zeichen in al }
- { ah - Bit 7 = 1, kein Zeichen, Fehlerbits in ah }
- { in diesem Fall ist V24Fehler nach dem }
- { Aufruf der Fkt. <> 0 }
- bio_V24ReadCh := chr(Regs.al); { liefert ein undefin. }
- { Zeichen, wenn V24Fehler <> 0 }
- bio_V24Fehler := Regs.ax and $9E00;
- end;
- {--------------------------------------------}
- { bio_V24ReadStr zum Einlesen eines Strings }
- {--------------------------------------------}
- Function bio_V24ReadStr(ComPort : word) : string;
- begin
- bio_V24ReadStr := bio_V24ReadStrL(ComPort, 254);
- end;
- {---------------------------------------------}
- { bio_V24ReadStrL zum Einlesen eines Strings }
- { fester (max.) Länge }
- {---------------------------------------------}
- Function bio_V24ReadStrL(ComPort : word; Laenge : byte) : string;
- var s : string;
- ch : char;
- begin
- s := '';
- ch := #00;
- repeat
- If ((bio_V24Status(ComPort) and (DataReady shl 8)) > 0) Then
- begin
- ch := bio_V24ReadCh(ComPort);
- If (ch <> chr(13)) { Endekennzeichen CR }
- Then s := s + ch;
- end;
- until ((Length(s) = Laenge) or { Länge erreicht }
- (ch = chr(13)) or { Ende des Strings }
- (bio_V24Fehler <> 0)); { Fehler }
- bio_V24ReadStrL := s;
- end;
- {-------------------------------------------------------------}
- { bio_V24Status (Fkt. 03h) }
- { Fehler beim Initialisieren (direkt nach InitComPort) }
- { V24Status and $00FF = 0 ->> kein Modem gefunden (Modem- }
- { statusreg. = 0) }
- { V24Status and $000F > 0 ->> Schnittstelle nicht verfügbar }
- { (Delta-Werte im Mod-Stat.Reg }
- { sind auf zuf. Werte gesetzt) }
- {-------------------------------------------------------------}
- Function bio_V24Status(ComPort : word) : word;
- var Regs : registers;
- begin
- Regs.ah := $03; { Funktion 03 von 14h }
- Regs.dx := ComPort;
- Intr($14, Regs);
- bio_V24Status := Regs.ax; { AH := Leitungsstatus,}
- { AL := Modemstatus }
- bio_V24Fehler := Regs.ax and $9E00;
- end;
-
- {-------------------------------------------------------------}
- { bio_SHOWV24STATUS zeigt den durch INT 14 Funk. $03 ermit. }
- { Status am Bildschirm }
- {-------------------------------------------------------------}
- Procedure bio_ShowV24Status(Status : word);
- var i : integer;
- const MStat : array[0..15] of string =
- ('DCTS', 'DDSR', 'DRI', 'DCD', 'CTS', 'DSR', 'RI', 'CD',
- ' DataReady', 'OE', 'PE', 'FE', 'BI', 'THE', 'TE', 'TimeOut');
- begin
- writeln;
- { 0-7 zeigt das Modemstatusregister , }
- { 8-15 das Leitungsstatusregister }
- For i := 0 to 15 do
- begin
- if (Status and (1 shl i)) <> 0
- Then TextColor(LightRed)
- Else TextColor(white);
- write(MStat[i]+ ' ');
- end;
- writeln;
- TextColor(Lightgray);
- end;
-
- Begin { Initialisierung ****************************************}
-
- bio_V24Fehler := $0000; { kein Fehler }
-
- end. {*************************************************************}