Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to use setcommstate for setup baud rate and flow control.</p> <pre><code>Function OpenPort( Var fHandle: THandle; fPort: String): Boolean; Const RxBufferSize = 32; TxBufferSize = 32; Var dcb : TDCB; tms : TCOMMTIMEOUTS; Begin Result := False; Try If fHandle &lt;&gt; INVALID_HANDLE_VALUE Then CloseHandle( fhandle ); Except End; Try //fport must be \\.\ URN format fhandle := CreateFile( PChar( fPort ), GENERIC_WRITE or GENERIC_READ, FILE_SHARE_WRITE , Nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); If ( fhandle = INVALID_HANDLE_VALUE ) Then Begin result := false; exit; End; SetupComm( fhandle, RxBufferSize, TxBufferSize ); If pos( 'LPT', fPort ) &gt; 0 Then // Else Begin GetCommState( fhandle, dcb ); dcb.DCBlength := sizeof( dcb ); dcb.BaudRate := cbr_9600; dcb.Flags := 1; // binary... if dtr_rts then begin dcb.flags := dcb.Flags Or $20; //DTR HANDSHAKE dcb.Flags := dcb.Flags Or $1000; //rts handshake dcb.Flags := dcb.Flags Or 4; //Outx_CtsFlow dcb.Flags := dcb.Flags Or 8; //Outx_DsrFlow dcb.Flags := dcb.Flags Or $40; //DsrSensitivity //dcb.Flags := dcb.Flags or $100;//Outx_XonXoffFlow //dcb.Flags := dcb.Flags or $200;//Inx_XonXoffFlow end; dcb.ByteSize := 8; dcb.Parity := EVENPARITY; dcb.StopBits := ONESTOPBIT; SetCommState( fhandle, dcb ); GetCommTimeouts( fhandle, tms ); tms.ReadIntervalTimeout := 100;//you can change multipler values with tms.ReadTotalTimeoutMultiplier := 100;//your values tms.ReadTotalTimeoutConstant := 1; SetCommTimeOuts( fhandle, tms ); End; EscapeCommFunction( fhandle, CLRRTS Or CLRDTR Or SETRTS Or SETDTR );//for handshaking Result := True; Except Result := False; End; End; </code></pre> <p>usage</p> <pre><code>var fporthandle:thandle; begin if OpenPort(fporthandle,'\\.\com1') then try writefile(fporthandle,pchar('TEST')...); finally closehandle(fporthandle); end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload