如何用Delphi实现串口通信,如何批量的采集多个传感器信号
发布网友
发布时间:2022-04-30 04:36
我来回答
共1个回答
热心网友
时间:2023-10-13 05:15
1、首先要设置通信双方的COM口设置一致,不然是通信不了的;
2、发送信息:
设置ComPort:TComm;
ComPort.WriteCommData(Pchar(WriteStr),Length(WriteStr));
3、读信息(只要有信息发送过来就会自动接收):
procere TMainFrm.ComReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word);
var
i: word;
str: string;
p: PChar;
begin
SetLength(str, BufferLength);
p := Buffer;
for i := 1 to BufferLength do
begin
Str[i] := p^;
RBit[i]:=StrToInt('$'+IntToHex(Ord(Str[i]),2));
inc(p);
end;
热心网友
时间:2023-10-13 05:15
1、首先要设置通信双方的COM口设置一致,不然是通信不了的;
2、发送信息:
设置ComPort:TComm;
ComPort.WriteCommData(Pchar(WriteStr),Length(WriteStr));
3、读信息(只要有信息发送过来就会自动接收):
procere TMainFrm.ComReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word);
var
i: word;
str: string;
p: PChar;
begin
SetLength(str, BufferLength);
p := Buffer;
for i := 1 to BufferLength do
begin
Str[i] := p^;
RBit[i]:=StrToInt('$'+IntToHex(Ord(Str[i]),2));
inc(p);
end;