sRece1:string; //接收到的字符串 rbuf:array[1..20] of byte;//把接收到的二进制转化为整数,存储在数组里 pDataToWrite:array[1..20] of char; // 要发送的,转化为字符procedure TForm_TZ_JuanQuL.Bbtn_SureClick(Sender: TObject); begin Comm1.StartComm; pDataToWrite[1]:=chr(byte($D1)); LDate:=1; Comm1.Inx_XonXoffFlow:=false; Comm1.Outx_XonXoffFlow:=false; Comm1.WriteCommData(@(pDataToWrite),LDate); dtTmp:=Now; while ((not (sRece1='CC')) and ((Now-dtTmp)<(10000 /(24*60*60*1000)))) do begin Application.ProcessMessages; end;end; procedure TForm_TZ_JuanQuL.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var i:integer; begin sRece1:=''; move(buffer^,pchar((@rbuf)^),bufferlength); for i:=1 to bufferlength do begin sRece1:=sRece1+ inttohex(rbuf[i],2); end; end; end.
用了lxhong1980(娶个善善良良的妻子,养个聪聪明明的孩子) , 还是不行,我用MSCOMM实现的代码如下,用SPCOMM改来现实.怎么改写: procedure send(sender:Tobject) var buf:variant; bf: array of byte; begin mscomm1.settings:=4800,n,8,1 mscomm1.inputMode:=1 - comInputModeBinary; SetLength(Bf,2); bf[0]:=2; bf[1]:=6; Buf:=Bf;mscomm1.Output:=Buf; end;
//参数在控件里面设置 Comm1.StartComm; pDataToWrite[1]:=chr(2); pDataToWrite[1]:=chr(6); LDate:=1; Comm1.Inx_XonXoffFlow:=false; Comm1.Outx_XonXoffFlow:=false; Comm1.WriteCommData(@(pDataToWrite),LDate); dtTmp:=Now; while ((Now-dtTmp)<(1000 /(24*60*60*1000)))) do begin Application.ProcessMessages; end;
sRece1:string; //接收到的字符串
rbuf:array[1..20] of byte;//把接收到的二进制转化为整数,存储在数组里
pDataToWrite:array[1..20] of char; // 要发送的,转化为字符procedure TForm_TZ_JuanQuL.Bbtn_SureClick(Sender: TObject);
begin
Comm1.StartComm;
pDataToWrite[1]:=chr(byte($D1));
LDate:=1;
Comm1.Inx_XonXoffFlow:=false;
Comm1.Outx_XonXoffFlow:=false;
Comm1.WriteCommData(@(pDataToWrite),LDate);
dtTmp:=Now;
while ((not (sRece1='CC')) and ((Now-dtTmp)<(10000 /(24*60*60*1000)))) do
begin
Application.ProcessMessages;
end;end;
procedure TForm_TZ_JuanQuL.Comm1ReceiveData(Sender: TObject;
Buffer: Pointer; BufferLength: Word);
var
i:integer;
begin
sRece1:='';
move(buffer^,pchar((@rbuf)^),bufferlength);
for i:=1 to bufferlength do
begin
sRece1:=sRece1+ inttohex(rbuf[i],2);
end;
end;
end.
还是不行,我用MSCOMM实现的代码如下,用SPCOMM改来现实.怎么改写:
procedure send(sender:Tobject)
var buf:variant;
bf: array of byte;
begin
mscomm1.settings:=4800,n,8,1
mscomm1.inputMode:=1 - comInputModeBinary;
SetLength(Bf,2);
bf[0]:=2;
bf[1]:=6;
Buf:=Bf;mscomm1.Output:=Buf;
end;
Comm1.StartComm;
pDataToWrite[1]:=chr(2);
pDataToWrite[1]:=chr(6);
LDate:=1;
Comm1.Inx_XonXoffFlow:=false;
Comm1.Outx_XonXoffFlow:=false;
Comm1.WriteCommData(@(pDataToWrite),LDate);
dtTmp:=Now;
while ((Now-dtTmp)<(1000 /(24*60*60*1000)))) do
begin
Application.ProcessMessages;
end;