使用ApdComPort
发送数据:
TSendArray = array of byte; var b_arr:TSendArray; begin SetLenght(b_arr, 10); b_arr[0]:=$4; b_arr[1]:=$5; … for iLen:=Low(b_arr) to High(b_arr) do ApdComPort1.PutChar(Char(b_arr[iLen])); end;
接收数据:
procedure TFHatch.ApdComPort1TriggerAvail(CP: TObject; Count: Word); var i:Integer; s:string; begin for i:=1 to count do s:=s+comport.GetChar; end;
ApdDataPacket使用:
apd1.AutoEnable:=True; apd1.StartCond:=scString; apd1.StartString:=#0#0#4+'?'+#11#11; apd1.EndCond:=[ecPacketSize]; apd1.PacketSize:=17; apd1.IncludeStrings:=True;
接收数据:
procedure TFHatch.apd1Packet(Sender: TObject; Data: Pointer; Size: Integer); var s_arr:array of Byte; i:Integer; begin SetLength(s_arr, Size); Move(Data^, s_arr[0], Size); end;