property RxFullCount:Word read FRxFull write SetRxFull default RxFullDefault;
property TxLowCount:Word read FTxLow write SetTxLow default TxLowDefault;
property Events:TCommEvents read FEvents write SetEvents default EventsDefault;
property OnEvent:TNotifyEventEvent read FOnEvent write FOnEvent;
property OnReceive:TNotifyReceiveEvent read FOnReceive write FOnReceive;
property OnTransmit:TNotifyTransmitEvent read FOnTransmit write FOnTransmit;
end;
procedure Register;
implementation
procedure TComm.SetPort(Value:TPort);
const CommStr:PChar='COM1:';
begin
FPort:=Value;
if (csDesigning in ComponentState) or (Value=tptNone) or (not HasBeenLoaded) then exit;
if hComm>=0 then CloseComm(hComm);
CommStr[3]:=chr(48+ord(Value));
hComm:=OpenComm(CommStr,ReadBufferSize,WriteBufferSize);
if hComm<0 then begin
Error:=True;
exit;
end;
SetBaudRate(FBaudRate);
SetParity(FParity);
SetDataBits(FDataBits);
SetStopBits(FStopBits);
SetEvents(FEvents);
EnableCommNotification(hComm,FWindowHandle,FRxFull,FTxLow);
end;
procedure TComm.SetBaudRate(Value:TBaudRate);
var DCB:TDCB;
begin
FBaudRate:=Value;
if hComm>=0 then begin
GetCommState(hComm,DCB);
case Value of
tbr110:
DCB.BaudRate:=CBR_110;
tbr300:
DCB.BaudRate:=CBR_300;
tbr600:
DCB.BaudRate:=CBR_600;
tbr1200:
DCB.BaudRate:=CBR_1200;
tbr2400:
DCB.BaudRate:=CBR_2400;
tbr4800:
DCB.BaudRate:=CBR_4800;
tbr9600:
DCB.BaudRate:=CBR_9600;
tbr14400:
DCB.BaudRate:=CBR_14400;
tbr19200:
DCB.BaudRate:=CBR_19200;
tbr38400:
DCB.BaudRate:=CBR_38400;
tbr56000:
DCB.BaudRate:=CBR_56000;
tbr128000:
DCB.BaudRate:=CBR_128000;
tbr256000:
DCB.BaudRate:=CBR_256000;
end;
SetCommState(DCB);
end;
end;
procedure TComm.SetParity(Value:TParity);
var DCB:TDCB;
begin
FParity:=Value;
if hComm<0 then exit;
GetCommState(hComm,DCB);
case Value of
tpNone:
DCB.Parity:=0;
tpOdd:
DCB.Parity:=1;
tpEven:
DCB.Parity:=2;
tpMark:
DCB.Parity:=3;
tpSpace:
DCB.Parity:=4;
end;
SetCommState(DCB);
end;
procedure TComm.SetDataBits(Value:TDataBits);
var DCB:TDCB;
begin
FDataBits:=Value;
if hComm<0 then exit;
GetCommState(hComm,DCB);
case Value of
tdbFour:
DCB.ByteSize:=4;
tdbFive:
DCB.ByteSize:=5;
tdbSix:
DCB.ByteSize:=6;
tdbSeven:
DCB.ByteSize:=7;
tdbEight:
DCB.ByteSize:=8;
end;
SetCommState(DCB);
end;
procedure TComm.SetStopBits(Value:TStopBits);
var DCB:TDCB;
begin
FStopBits:=Value;
if hComm<0 then exit;
GetCommState(hComm,DCB);
case Value of
tsbOne:
DCB.StopBits:=0;
tsbOnePointFive:
DCB.StopBits:=1;
tsbTwo:
DCB.StopBits:=2;
end;
SetCommState(DCB);
end;
procedure TComm.SetReadBufferSize(Value:Word);
begin
FReadBufferSize:=Value;
SetPort(FPort);
end;
procedure TComm.SetWriteBufferSize(Value:Word);
begin
FWriteBufferSize:=Value;
SetPort(FPort);
end;
procedure TComm.SetRxFull(Value:Word);