![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 procedure Tfrm_FoldingCloth.btn1Click(Sender: TObject); 2 var 3 SND:array of byte; 4 begin 5 if Not cnrs232.Connected then cnrs232.StartComm ; 6 Sleep(40); 7 Setlength(SND,8); 8 SND[0]:=($01); 9 SND[1]:=($03); 10 SND[2]:=($00); 11 SND[3]:=($14); 12 SND[4]:=($00); 13 SND[5]:=($02); 14 SND[6]:=($84); 15 SND[7]:=($0F); 16 if not cnrs232.WriteCommData((@SND[0]),8) then ShowMessage('send error'); 17 end;
和RS232、socket等通讯,打开设备后,需要发送数据:
1、byte,pansichar型的处理:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
procedure Tfrm_FoldingCloth.cnrs232ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var RcvData:Array[0..1024] of byte; ChkStr:string; tmp : Integer; begin move(buffer^,pchar(@RcvData)^,8); ChkStr := inttostr(RcvData[3]*256 +RcvData[4]) + inttostr(RcvData[5]*256 +RcvData[6]); try tmp := strtoint(ChkStr); except tmp := 0; end; GetRS232DateLen :=Format( '%.2f',[(tmp)/1000]); end;
2、电脑太快了,别忘记一个提示or延时几十个ms。否则找不出原因没有反馈。
3、和RS232通讯,接受数据要等待 。当你事办完后才接收到数据。怎么办:
application.ProcessMessages;
如果效果不明显,那么感觉蛮好的地方多放几个。