home *** CD-ROM | disk | FTP | other *** search
- PROGRAM MINITERM;
- (*****************************************************************************
- Name: MINITERM.PAS
- Version: 1.1
- Edit Datum: 1.3.1992
- Autor: Frank Seidinger
- Kurzbeschreibung: V24 Kommunikation unter deLite
- *****************************************************************************)
-
- USES Kernel, API, Dialogs, V24, DOS;
-
- Type MiniTermSettingsType = Record
- MiniComPort : ComPortType;
- MiniBaudRate : ComBaudType;
- MiniDataBits : ComBitsType;
- MiniStopBits : ComStopType;
- MiniParity : ComDataType;
- MiniComBuffer : ComBuffType;
- MiniComMode : ComModeType;
- MiniHandShake : Word;
- End;
-
- CONST ProjektName = 'miniterm'; { so heissen alle Dateien }
- PaintColor = yellow;
- BackColor = black;
- Echo = False;
-
- BaudRates : array[ComBaudType] of ListString =
- ('110' ,'150' ,'300' ,'600' ,'1200' ,'2400' ,
- '4800' ,'9600' ,'19200' ,'38400' ,'57600' ,'115200');
-
- ComPorts : array[ComPortType] of ListString =
- ('COM1','COM2','COM3','COM4','User','NoCom');
-
- Parity : array[ComDataType] of ListString =
- ('Space','Odd','Mark','Even','None');
-
- FIFO : array[ComModeType] of ListString =
- ('Kein','Aus','FIFO 1','FIFO 4','FIFO 8','FIFO 14');
-
- TermSettings : MiniTermSettingsType = (
- MiniComPort : Com1;
- MiniBaudRate : b1200;
- MiniDataBits : d8;
- MiniStopBits : s1;
- MiniParity : NoParity;
- MiniComBuffer : KB1;
- MiniComMode : Normal;
- MiniHandShake : 0
- );
-
- VAR LaunchResult : integer;
- MyEvent : EventTyp;
- StillRunning : boolean;
-
- PosX, PosY : Integer;
- MaxX, MaxY : Integer;
-
- ComBaudPtr : ComBaudType;
- ComPortPtr : ComPortType;
- ComParityPtr : ComDataType;
- ComFIFOPtr : ComModeType;
-
- SaveFlag : Boolean;
-
- { ***************
- Hilfsprozeduren
- *************** }
-
- function CompareMemory(Location1, Location2 : Pointer; Len : Word) : Integer;
- Var Result : Integer;
- begin
- while (Len <> 0) do
- begin
- Result := Byte(Location2^) - Byte(Location1^);
- if result <> 0 Then
- begin
- CompareMemory := Result;
- exit;
- end;
- inc(LongInt(Location1));
- inc(LongInt(Location2));
- dec(Len);
- end;
- CompareMemory := 0;
- end;
-
- { **************************************************
- Speichert und lädt die Einstellungen des Com-Ports
- ************************************************** }
-
- procedure SaveSetup;
- Var TempStr : String;
- begin
- SetCursor(LoadCursor(HourGlassCursor));
- SetInitFileName ('ComPort','Device' ,ComPorts[TermSettings.MiniComPort]);
- SetInitFileName ('ComPort','Baudrate' ,BaudRates[TermSettings.MiniBaudRate]);
- SetInitFileName ('ComPort','Parity' ,Parity[TermSettings.MiniParity]);
- SetInitFileInteger('ComPort','Databits' ,Ord(TermSettings.MiniDataBits)+5);
- SetInitFileInteger('ComPort','Stopbits' ,Ord(TermSettings.MiniStopBits)+1);
- SetInitFileInteger('ComPort','Buffer' ,Ord(TermSettings.MiniComBuffer));
- SetInitFileString ('ComPort','FIFOMode' ,FIFO[TermSettings.MiniComMode]);
- SetInitFileInteger('ComPort','Handshake',TermSettings.MiniHandShake);
- SetCursor(LoadCursor(DefaultCursor));
- end;
-
- procedure ReadSetup;
- var TempStr : String;
- I : Integer;
- MyLong : LongInt;
- begin
- If GetInitFileName('ComPort','Device',TempStr) Then
- For I := Ord(Com1) to Ord(UserCom) do
- If (ComPorts[ComPortType(I)] = TempStr) Then TermSettings.MiniComPort := ComPortType(I);
-
- If GetInitFileName('ComPort','Baudrate',TempStr) Then
- For I := Ord(b110) to Ord(b115200) do
- If (BaudRates[ComBaudType(I)] = TempStr) Then TermSettings.MiniBaudRate := ComBaudType(I);
-
- If GetInitFileName('ComPort','Parity',TempStr) Then
- For I := Ord(Space) to Ord(NoParity) do
- If (Parity[ComDataType(I)] = TempStr) Then TermSettings.MiniParity := ComDataType(I);
-
- If (GetInitFileInteger('ComPort','DataBits',MyLong) and
- (MyLong >= 5) and
- (MyLong <= 8)) Then
- TermSettings.MiniDataBits := ComBitsType(MyLong-5);
-
- If (GetInitFileInteger('ComPort','StopBits',MyLong) and
- (MyLong >= 1) and
- (MyLong <= 2)) Then
- TermSettings.MiniStopBits := ComStopType(MyLong-1);
-
- If (GetInitFileInteger('ComPort','Buffer',MyLong) and
- (MyLong >= Ord(Kb1)) and
- (MyLong <= Ord(Kb16))) Then
- TermSettings.MiniComBuffer := ComBuffType(MyLong);
-
- If GetInitFileString('ComPort','FIFOMode',TempStr) Then
- For I := Ord(Normal) to Ord(FIFO14) do
- If (FIFO[ComModeType(I)] = TempStr) Then TermSettings.MiniComMode := ComModeType(I);
-
- If GetInitFileInteger('ComPort','HandShake',MyLong) Then TermSettings.MiniHandShake := Word(MyLong);
- end;
-
- { *********************************************************
- GetFirst/GetNext Prozeduren für den Konfigurations Dialog
- ********************************************************* }
-
- procedure GetNextBaud(var bd: ListString; var eol: boolean); far;
- begin
- eol := true;
- if ComBaudPtr <= b38400 then
- begin
- bd := BaudRates[ComBaudPtr];
- inc(ComBaudPtr);
- eol := false;
- end;
- end;
-
- procedure GetFirstBaud(var bd: ListString; var eol: boolean); far;
- begin
- ComBaudPtr := b110;
- GetNextBaud(bd, eol);
- end;
-
- procedure GetNextPort(var port : ListString; var eol : boolean); far;
- begin
- if ComPortPtr < NoCom Then
- begin
- port := ComPorts[ComPortPtr];
- inc(ComPortPtr);
- eol := false;
- end
- else eol := true;
- end;
-
- procedure GetFirstPort(var port : ListString; var eol : boolean); far;
- begin
- ComPortPtr := Com1;
- GetNextPort(port,eol);
- end;
-
- procedure GetNextParity(var the_parity : ListString; var eol : boolean); far;
- begin
- if ComParityPtr <= NoParity Then
- begin
- the_parity := Parity[ComParityPtr];
- inc(ComParityPtr);
- eol := false;
- end
- else eol := true;
- end;
-
- procedure GetFirstParity(var the_parity : ListString; var eol : boolean); far;
- begin
- ComParityPtr := Space;
- GetNextParity(the_parity,eol);
- end;
-
- procedure GetNextFIFO(var the_fifo : ListString; var eol : boolean); far;
- begin
- if ComFIFOPtr <= FIFO14 Then
- begin
- the_fifo := FIFO[ComFIFOPtr];
- inc(ComFIFOPtr);
- eol := false;
- end
- else eol := true;
- end;
-
- procedure GetFirstFIFO(var the_fifo : ListString; var eol : boolean); far;
- begin
- ComFIFOPtr := normal;
- GetNextFIFO(the_fifo,eol);
- end;
-
- { **********************************************************************
- Der Konfiguratons Dialog für die Einstellungen der RS232 Schnittstelle
- ********************************************************************** }
-
- procedure KonfigV24Handler(TheEvent : EventTyp); far;
- var MYDLG : PDLG;
- TheStr : String;
- begin
- MYDLG := TheEvent.DlgAdr;
- if TheEvent.Class = DialogEvent then
- Case TheEvent.MSG of
- DLG_OK : MYDLG^.DestroyDialog;
-
- DLG_CANCEL : Begin
- MYDLG^.flags := MYDLG^.flags or MF_CANCELLED;
- MYDLG^.DestroyDialog;
- End;
- DLG_BUTTON : If TheEvent.ID = 201 Then
- Begin
- SaveFlag := true;
- MYDLG^.DestroyDialog;
- End;
- End;
- End;
-
- procedure KonfigV24;
- var MyDialog : Dialog;
- MyCombo : PComboBox;
- MyButton : PButton;
- MyLabel : PLabelText;
- MyRadios : PRadioButtons;
- MyFrame : PLabelFrame;
- MyCheck : PCheckBox;
- MySettings : MiniTermSettingsType;
- TempStr : String;
- Ready : boolean;
- begin
- MySettings := TermSettings;
- SaveFlag := False;
-
- MyDialog.Init(40*FontX, 18*FontY, MF_CAPTION, KonfigV24Handler);
- MyDialog.SetCaption('RS232 Konfiguration');
- MyDialog.SetTopic('Konfig');
-
- { Communication Port beschriften und Auswahl Element installieren }
- new(MyLabel, Init( FontX, FontY + 4, 0, 'COM-Port'));
- MyDialog.AddItem(MyLabel);
- new(MyCombo, Init(10*FontX, FontY, 8, 4, 101, GetFirstPort, GetNextPort));
- MyDialog.AddItem(MyCombo);
- MyCombo^.Select(ComPorts[TermSettings.MiniComPort]);
-
- { Baudrate beschriften und Auswahl Element installieren }
- new(MyLabel, Init( FontX, 3*FontY + 4, 0, 'Baudrate'));
- MyDialog.AddItem(MyLabel);
- new(MyCombo, Init(10*FontX, 3*FontY, 8, 4, 102, GetFirstBaud, GetNextBaud));
- MyDialog.AddItem(MyCombo);
- MyCombo^.Select(BaudRates[TermSettings.MiniBaudRate]);
-
- { Parität beschriften und Auswahl Element installieren }
- new(MyLabel, Init( FontX, 5*FontY + 4, 0, 'Parität'));
- MyDialog.AddItem(MyLabel);
- new(MyCombo, Init(10*FontX, 5*FontY, 8, 4, 103, GetFirstParity, GetNextParity));
- MyDialog.AddItem(MyCombo);
- MyCombo^.Select(Parity[TermSettings.MiniParity]);
-
- { FIFO Modus beschriften un Auswahl Element installieren }
- new(MyLabel, Init( FontX, 7*FontY + 4, 0, '16550'));
- MyDialog.AddItem(MyLabel);
- new(MyCombo, Init(10*FontX, 7*FontY, 8, 4, 104, GetFirstFIFO, GetNextFIFO));
- MyDialog.AddItem(MyCombo);
- MyCombo^.Select(FIFO[TermSettings.MiniComMode]);
-
- { Datenbits beschriften und Auswahl Element installieren }
- new(MyRadios, Init( FontX, 10*FontY, 20*FontX, 2*FontY, 109, 'Datenbits:',
- new(PRadioButton, Init( FontX, FontY div 2 + 2, 112, '7 Bit' ,
- new(PRadioButton, Init(10*FontX, FontY div 2 + 2, 113, '8 Bit', NIL))))));
- MyDialog.AddItem(MyRadios);
- MyRadios^.CheckButton(110+Ord(TermSettings.MiniDataBits));
-
- { Stopbits beschriften und Auswahl Element installieren }
- new(MyRadios, Init( FontX, 13*FontY, 20*FontX, 2*FontY, 119, 'Stopbits:',
- new(PRadioButton, Init( FontX, FontY div 2 + 2, 120, '1 Bit' ,
- new(PRadioButton, Init(10*FontX, FontY div 2 + 2, 121, '2 Bit', NIL))))));
- MyDialog.AddItem(MyRadios);
- MyRadios^.CheckButton(120+Ord(TermSettings.MiniStopBits));
-
- { Hand-Shake beschriften und Auswahl Element installieren }
- new(MyFrame, Init( FontX, 16*FontY, 38*FontX, 2*FontY, 0,'Hand-Shake'));
- MyDialog.AddItem(MyFrame);
- new(MyCheck, Init( 2*FontX, 16*FontY + (1*FontY) div 2 + 2, 130, 'XON/XOFF'));
- MyDialog.AddItem(MyCheck);
- If ((TermSettings.MiniHandShake and XON) <> 0) Then MyCheck^.Check;
- new(MyCheck, Init(16*FontX, 16*FontY + (1*FontY) div 2 + 2, 131, 'CTS/RTS'));
- MyDialog.AddItem(MyCheck);
- If ((TermSettings.MiniHandShake and CTS) <> 0) Then MyCheck^.Check;
- new(MyCheck, Init(28*FontX, 16*FontY + (1*FontY) div 2 + 2, 132, 'DSR/DTR'));
- MyDialog.AddItem(MyCheck);
- If ((TermSettings.MiniHandShake and DSR) <> 0) Then MyCheck^.Check;
-
- { Puffergröße beschriften und Auswahl Element installieren }
- new(MyRadios, Init(23*FontX, 9*FontY, 16*FontX, 6*FontY, 139, 'Puffergröße:',
- new(PRadioButton, Init( FontX, FontY div 2 + 2, 140, ' 1 Kilo Byte',
- new(PRadioButton, Init( FontX, 3*FontY div 2 + 2, 141, ' 2 Kilo Byte',
- new(PRadioButton, Init( FontX, 5*FontY div 2 + 2, 142, ' 4 Kilo Byte',
- new(PRadioButton, Init( FontX, 7*FontY div 2 + 2, 143, ' 8 Kilo Byte',
- new(PRadioButton, Init( FontX, 9*FontY div 2 + 2, 144, '16 Kilo Byte', NIL))))))))))));
- MyDialog.AddItem(MyRadios);
- MyRadios^.CheckButton(140 + Ord(TermSettings.MiniComBuffer));
-
- new(MyButton, Init(23*FontX, ( 2*FontY) div 2, 16*FontX, 2*FontY, 200,'OK'));
- MyButton^.MakeDefaultItem;
- MyDialog.AddItem(MyButton);
-
- new(MyButton, Init(23*FontX, ( 7*FontY) div 2, 16*FontX, 2*FontY, 201,'Save'));
- MyDialog.AddItem(MyButton);
-
- new(MyButton, Init(23*FontX, (12*FontY) div 2, 16*FontX, 2*FontY, 202,'Cancel'));
- MyButton^.MakeCancelItem;
- MyDialog.AddItem(MyButton);
-
- MyDialog.Show;
-
- Ready := False;
- Repeat
- MyDialog.DoDialog;
- if MyDialog.WasNotCancelled then
- begin
- MyCombo := MyDialog.FindDlgItem(101);
- TempStr := MyCombo^.GetSelected;
- For ComPortPtr := Com1 to UserCom do
- If (TempStr = ComPorts[ComPortPtr]) Then MySettings.MiniComPort := ComPortPtr;
-
- MyCombo := MyDialog.FindDlgItem(102);
- TempStr := MyCombo^.GetSelected;
- For ComBaudPtr := b110 to b115200 do
- If (TempStr = BaudRates[ComBaudPtr]) Then MySettings.MiniBaudRate := ComBaudPtr;
-
- MyCombo := MyDialog.FindDlgItem(103);
- TempStr := MyCombo^.GetSelected;
- For ComParityPtr := Space to NoParity do
- If (TempStr = Parity[ComParityPtr]) Then MySettings.MiniParity := ComParityPtr;
-
- MyCombo := MyDialog.FindDlgItem(104);
- TempStr := MyCombo^.GetSelected;
- For ComFIFOPtr := Normal to FIFO14 do
- If (TempStr = FIFO[ComFIFOPtr]) Then MySettings.MiniComMode := ComFIFOPtr;
-
- MyRadios := MyDialog.FindDlgItem(109);
- MySettings.MiniDataBits := ComBitsType(MyRadios^.WhosChecked - 110);
-
- MyRadios := MyDialog.FindDlgItem(119);
- MySettings.MiniStopBits := ComStopType(MyRadios^.WhosChecked - 120);
-
- MyRadios := MyDialog.FindDlgItem(139);
- MySettings.MiniComBuffer := ComBuffType(MyRadios^.WhosChecked - 140);
-
- If (CompareMemory(@MySettings,@TermSettings,SizeOf(MiniTermSettingsType)) <> 0) Then
- begin
- If OpenCom(MySettings.MiniComPort,
- MySettings.MiniBaudRate,
- MySettings.MiniDataBits,
- MySettings.MiniParity,
- MySettings.MiniStopBits,
- MySettings.MiniComMode,
- MySettings.MiniComBuffer) Then
- begin
- TermSettings := MySettings;
- Ready := True;
- end
- else ErrWindow(100,100,'Hardware nicht verfügbar!');
- end
- else Ready := True;
- TermSettings.MiniHandShake := 0;
- MyCheck := MyDialog.FindDlgItem(130);
- If MyCheck^.IsChecked Then TermSettings.MiniHandShake := TermSettings.MiniHandShake + XON;
-
- MyCheck := MyDialog.FindDlgItem(131);
- If MyCheck^.IsChecked Then TermSettings.MiniHandShake := TermSettings.MiniHandShake + CTS;
-
- MyCheck := MyDialog.FindDlgItem(132);
- If MyCheck^.IsChecked Then TermSettings.MiniHandShake := TermSettings.MiniHandShake + DSR;
-
- SetHandShake(TermSettings.MiniHandShake);
-
- If SaveFlag Then
- SaveSetup;
- end
- else Ready := True;
- Until Ready;
- MyDialog.Done;
- end;
-
- { *********************************************************************
- Hier bitte die Prozedur kodieren, die die Meldung auf das G behandelt
- ********************************************************************* }
-
- Procedure Meldung;
- Begin
- {
- Write(#7);
- }
- End;
-
- { ***********************************************************************
- Fenster Prozeduren zum Aufbau eines Textbildschirmes bei Verwendung der
- hochauflösenden Zeichenroutinen
- *********************************************************************** }
-
- Procedure ClearTheScreen;
- begin
- ClearWindow;
- PosX := 0;
- PosY := 0;
- end;
-
- Procedure ScrollUp;
- Var X1,X2,Y1,Y2 : Integer;
- Begin
- X1 := 0; X2 := 0;
- Y1 := FontY; Y2 := 0;
- BitBlit(x1,y1,x2,y2,Succ(PortMaxX),MaxY*FontY);
- Bar(0,Pred(MaxY)*FontY,PortMaxX,MaxY*FontY,BackGndCol);
- End;
-
- Procedure IncYPosition;
- Begin
- Inc(PosY);
- if (PosY >= MaxY) Then
- Begin
- ScrollUp;
- Dec(PosY);
- End;
- End;
-
- Procedure IncXPosition;
- Begin
- Inc(PosX);
- If (PosX > MaxX) Then
- Begin
- PosX := 0;
- IncYPosition;
- End;
- End;
-
- Procedure WriteBlank;
- Var X1,X2,Y1,Y2 : Integer;
- Begin
- X1 := PosX*FontX; X2 := X1 + FontX;
- Y1 := PosY*FontY; Y2 := Y1 + FontY;
- Bar(X1,Y1,X2,Y2,BackGndCol);
- IncXPosition;
- End;
-
- Procedure WriteTTY(TheChar : Char);
- Var OutString : String[1];
- Begin
- Case TheChar Of
- #13 : PosX := 0;
-
- #10 : IncYPosition;
-
- #32 : WriteBlank;
-
- Else Begin
- OutString := TheChar;
- Bar(PosX*FontX,PosY*FontY,Succ(PosX)*FontX,Succ(PosY)*FontY,BackGndCol);
- OutTextAPI(PosX*FontX,PosY*FontY,OutString,PaintColor,0);
- IncXPosition;
- End;
- End; { Case }
- End;
-
- { ************************************************************************
- Der Event Handler der Haupt Applikation. Achtung, diese Prozedur ist nur
- dann aktiv, wenn kein Dialog und kein Menü geöffnet ist.
- ************************************************************************ }
-
- Procedure HandleMsg(MyMessage: EventTyp); far;
- Var MyChar : Char;
- Begin
- With MyMessage Do
- Case Class Of
- Menu : begin
- Case MenuItemID of
- 0 : StillRunning := false; { Ende }
- 101 : ClearTheScreen;
- 201 : KonfigV24;
- end;
- End;
-
- Void : Begin
- If IsComDataAvail Then
- Begin
- HideMouse;
- MyChar := Char(GetComData);
- If MyChar in ['g','G'] Then
- Meldung;
- WriteTTY(MyChar);
- ShowMouse;
- { Do what ever you want to do }
- End;
- End;
-
- NormKey : If Not IsComDataAvail Then
- PutComData(Ord(Attrib));
-
- CtrlKey : If Not IsComDataAvail Then
- PutComData(Ord(Attrib)-96);
- End; { Case Class }
- End;
-
- Begin
- StillRunning := true;
- LaunchResult := OpenMainApplication(HandleMsg,
- APP_NOFONT,
- ProjektName);
- If LaunchResult = 0 then { erfolgreich gestartet }
- begin
- ReadSetup;
- OpenCom(TermSettings.MiniComPort,
- TermSettings.MiniBaudRate,
- TermSettings.MiniDataBits,
- TermSettings.MiniParity,
- TermSettings.MiniStopBits,
- TermSettings.MiniComMode,
- TermSettings.MiniComBuffer);
- SetHandShake(TermSettings.MiniHandShake);
- PosX := 0;
- PosY := 0;
- MaxX := PortMaxX div FontX;
- MaxY := PortMaxY div FontY;
- while StillRunning Do
- begin
- GetEvent(MyEvent);
- DispatchMessage(MyEvent);
- end;
- CloseCom;
- CloseMainApplication;
- end
- Else
- Writeln('Programm kann nicht gestartet werden. Fehler: ',LaunchResult);
- End.
-