SetCommState(DCB);
end;
procedureTComm.SetReadBufferSize(Value:Word);
begin
FReadBufferSize:=Value;
SetPort(FPort);
end;
procedureTComm.SetWriteBufferSize(Value:Word);
begin
FWriteBufferSize:=Value;
SetPort(FPort);
end;
procedureTComm.SetRxFull(Value:Word);
begin
FRxFull:=Value;
ifhComm<0 thenexit;
EnableCommNotification(hComm,FWindowHandle,FRxFull,FTxLow);
end;
procedureTComm.SetTxLow(Value:Word);
begin
FTxLow:=Value;
ifhComm<0 thenexit;
EnableCommNotification(hComm,FWindowHandle,FRxFull,FTxLow);
end;
procedureTComm.SetEvents(Value:TCommEvents);
varEventMask:Word;
begin
FEvents:=Value;
ifhComm<0 thenexit;
EventMask:=0;
iftceBreak inFEvents theninc(EventMask,EV_BREAK);
iftceCts inFEvents theninc(EventMask,EV_CTS);
iftceCtss inFEvents theninc(EventMask,EV_CTSS);
iftceDsr inFEvents theninc(EventMask,EV_DSR);
iftceErr inFEvents theninc(EventMask,EV_ERR);
iftcePErr inFEvents theninc(EventMask,EV_PERR);
iftceRing inFEvents theninc(EventMask,EV_RING);
iftceRlsd inFEvents theninc(EventMask,EV_RLSD);
iftceRlsds inFEvents theninc(EventMask,EV_RLSDS);
iftceRxChar inFEvents theninc(EventMask,EV_RXCHAR);
iftceRxFlag inFEvents theninc(EventMask,EV_RXFLAG);
iftceTxEmpty inFEvents theninc(EventMask,EV_TXEMPTY);
SetCommEventMask(hComm,EventMask);
end;
procedureTComm.WndProc( varMsg:TMessage);
begin
withMsg do begin
ifMsg=WM_COMMNOTIFY then begin
caselParamLo of
CN_EVENT:
DoEvent;
CN_RECEIVE:
DoReceive;
CN_TRANSMIT:
DoTransmit;
end;
end elseResult:=DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;
end;
procedureTComm.DoEvent;
var
CommEvent:TCommEvents;
EventMask:Word;
begin
if(hComm<0) or notAssigned(FOnEvent) thenexit;
EventMask:=GetCommEventMask(hComm,Integer($FFFF));
CommEvent:=[];
if(tceBreak inEvents) and(EventMask andEV_BREAK<>0) thenCommEvent:=CommEvent+[tceBreak];
if(tceCts inEvents) and(EventMask andEV_CTS<>0) thenCommEvent:=CommEvent+[tceCts];
if(tceCtss inEvents) and(EventMask andEV_CTSS<>0) thenCommEvent:=CommEvent+[tceCtss];
if(tceDsr inEvents) and(EventMask andEV_DSR<>0) thenCommEvent:=CommEvent+[tceDsr];
if(tceErr inEvents) and(EventMask andEV_ERR<>0) thenCommEvent:=CommEvent+[tceErr];
if(tcePErr inEvents) and(EventMask andEV_PERR<>0) thenCommEvent:=CommEvent+[tcePErr];
if(tceRing inEvents) and(EventMask andEV_RING<>0) thenCommEvent:=CommEvent+[tceRing];
if(tceRlsd inEvents) and(EventMask andEV_RLSD<>0) thenCommEvent:=CommEvent+[tceRlsd];
if(tceRlsds inEvents) and(EventMask andEV_Rlsds<>0) thenCommEvent:=CommEvent+[tceRlsds];
if(tceRxChar inEvents) and(EventMask andEV_RXCHAR<>0) thenCommEvent:=CommEvent+[tceRxChar];
if(tceRxFlag inEvents) and(EventMask andEV_RXFLAG<>0) thenCommEvent:=CommEvent+[tceRxFlag];
if(tceTxEmpty inEvents) and(EventMask andEV_TXEMPTY<>0) thenCommEvent:= CommEvent+[tceTxEmpty];
FOnEvent(Self,CommEvent);
end;
procedureTComm.DoReceive;
varStat:TComStat;
begin
if(hComm<0) or notAssigned(FOnReceive) thenexit;
GetCommError(hComm,Stat);
FOnReceive(Self,Stat.cbInQue);
GetCommError(hComm,Stat);
end;
procedureTComm.DoTransmit;
varStat:TComStat;
begin
if(hComm<0) or notAssigned(FOnTransmit) thenexit;
GetCommError(hComm,Stat);
FOnTransmit(Self,Stat.cbOutQue);
end;
procedureTComm.Loaded;
begin
inheritedLoaded;
HasBeenLoaded:=True;
SetPort(FPort);
end;
constructorTComm.Create(AOwner:TComponent);
begin
Читать дальше