comPort控件的使用。200分!(200分)

  • 主题发起人 主题发起人 jswqg
  • 开始时间 开始时间
J

jswqg

Unregistered / Unconfirmed
GUEST, unregistred user!
那位大侠用过COMPORT串口控件。能否发个例子。一个100分。谢啦!
 
分少么?
 
MODEM TESETER

program ModTest;
{$APPTYPE CONSOLE}

uses
SysUtils,
CPort,
Windows;

var
ComPort: TComPort;
Events: TComEvents;
Answer, Data: string;
Step: Integer;

begin
try
ComPort := TComPort.Create(nil);
try
if ParamCount > 0 then
ComPort.Port := ParamStr(1)
else
ComPort.Port := 'COM1';
ComPort.Events := [];
ComPort.FlowControl.ControlDTR := dtrEnable;
ComPort.FlowControl.ControlRTS := rtsEnable;
ComPort.Open; // open port
ComPort.WriteStr('AT'#13#10); // send test command
Answer := '';
Step := 0;
repeat
Events := [evRxChar];
ComPort.WaitForEvent(Events, 2000); // wait for charachters
if evRxChar in Events then
begin
ComPort.ReadStr(Data, ComPort.InputCount);
Answer := Answer + Data;
if Pos('OK', Answer) > 0 then
Break;
end;
Inc(Step)
until (Events = []) or (Step = 20);
if Pos('OK', Answer) > 0 then
WriteLn('Modem found on ' + ComPort.Port)
else
WriteLn('Modem NOT found on ' + ComPort.Port);
finally
ComPort.Free;
end;
except
on E: Exception do
WriteLn('Error: ' + E.Message);
end;
end.
 
请问有没有并口通讯的控件?[:D][8D][:(]
 
谢谢。继续!
 
to mutex :
在OnRxChar事件中COUNT参数是表示啥意思?
 
接受缓冲区的字符个数
 
接受答案了.
 
后退
顶部