HSG |
|
procedure TForm1.OpenComClick(Sender: TObject); var res,error : integer; PortStr : string; begin if Sender = bOpenCom1 then PortStr := 'COM1'; if Sender = bOpenCom2 then PortStr := 'COM2'; res := CreateFile(PChar(PortStr), GENERIC_READ or GENERIC_WRITE, 0,nil,OPEN_EXISTING,0,0); if res > 0 then begin PortHandle := res; EscapeCommFunction(PortHandle,CLRRTS); EscapeCommFunction(PortHandle,CLRBREAK); EscapeCommFunction(PortHandle,CLRDTR); end else begin error := GetLastError; ShowMessage('Fehler: '+IntToStr(error)); end; end; .... procedure TForm1.bCloseClick(Sender: TObject); begin CloseHandle(PortHandle); end; procedure TForm1.bEinlesenClick(Sender: TObject); var ein : DWORD; function bin(a : integer) : string; var s : string; begin s :=''; while a > 0 do begin if a mod 2 = 1 then s := '1'+s else s := '0'+s; a := a div 2; end; if s='' then result := '0' else result := s; end; function b8(b : string) : string; var i : integer; begin for i := Length(b)+1 to 8 do b := '0'+b; result := b; end; begin GetCommModemStatus(PortHandle,ein); lEingaben.caption := b8(bin(integer(ein))); if (ein and 128) > 0 then lDCD.Caption := 'DCD = 1' else lDCD.Caption := 'DCD = 0'; if (ein and 32) > 0 then lDSR.Caption := 'DSR = 1' else lDSR.Caption := 'DSR = 0'; if (ein and 16) > 0 then lCTS.Caption := 'CTS = 1' else lCTS.Caption := 'CTS = 0'; if (ein and 64) > 0 then lRI.Caption := 'RI = 1' else lRI.Caption := 'RI = 0'; end; procedure TForm1.cbRTSClick(Sender: TObject); begin if cbRTS.checked then EscapeCommFunction(PortHandle,SETRTS) // ein else EscapeCommFunction(PortHandle,CLRRTS); // aus end; procedure TForm1.cbTxDClick(Sender: TObject); begin if cbTxD.checked then EscapeCommFunction(PortHandle,SETBREAK) // ein else EscapeCommFunction(PortHandle,CLRBREAK); // aus end; procedure TForm1.cbDTRClick(Sender: TObject); begin if cbDTR.checked then EscapeCommFunction(PortHandle,SETDTR) // ein else EscapeCommFunction(PortHandle,CLRDTR); // aus end;
Messungen ergaben an einem Desktop-PC 9,2 mA Kurzschlussstrom RTS-GND in beiden Richtungen. RTS-CTS ergab 2 mA in beiden Richtungen.