读取com口接收byte数据的处理
1 procedure Tfrm_CheckCloth.cnrs232ReceiveData(Sender: TObject; Buffer: Pointer; 2 BufferLength: Word); 3 var 4 MyRcvData:Array[0..8] of byte; 5 ChkStr:string; 6 tmp : Integer; 7 begin 8 move(buffer^,pchar(@MyRcvData)^,8); 9 // ChkStr := inttostr(MyRcvData[3]*256 +MyRcvData[4]) + inttostr(MyRcvData[5]*256 +MyRcvData[6]); 10 ChkStr := Format('%0.2x%0.2x%0.2x%0.2x', [MyRcvData[3], MyRcvData[4],MyRcvData[5],MyRcvData[6]]); 11 try 12 tmp := strtoint('$'+ChkStr); 13 except 14 tmp := 0; 15 end; 16 GetRS232DateLen :=Format( '%.2f',[(tmp)/1000]); 17 end;
烟台一码表厂的码表:
通讯举例:仪表地址假设为1
读取当前显示值(假设当前显示值为1000)
上位机发送(HEX) 01 03 00 14 00 02 84 0F
仪表回应(HEX): 01 03 04 00 00 03 E8 FA 8D
红字表示码表数值。