procedure TMainFrm.SpcommReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
Str:string;
rbuf:array[1..16] of byte;
crc,i:integer;
begin
Str:='';
move(buffer^,Pchar(@rbuf)^,bufferlength);
crc := 0; // CRC初始值
for i:=1 to bufferlength-1 do
crc := CalCRC8(rbuf,crc,$8C); // 按位计算CRC
if rbuf[bufferlength]<>crc then
begin
SendParameter:=false;
SendBill:=false;
TxDTimer.enabled:=false;
Application.MessageBox('传输数据错误','错误',MB_ICONError+MB_OK);
exit;
end;
if rbuf[1]=$A0 then
begin
TxDTimer.Enabled:=false;
ClockBtn.Enabled:=true;
Application.MessageBox('时钟校正完毕','提示',MB_ICONInformation+MB_OK);
SendClock:=false;
end;
if rbuf[1]=$A1 then
begin
TxDTimer.Enabled:=false;
ParameterBtn.enabled:=true;
Application.MessageBox('系统参数设置完毕','提示',MB_ICONInformation+MB_OK);
SendParameter:=false;
end;
if rbuf[1]=$C0 then
BillSendData();
if rbuf[1]=$C1 then
begin
TxDTimer.Enabled:=false;
Application.MessageBox('票据参数设置完毕','提示',MB_ICONInformation+MB_OK);
SendBill:=false;
BillBtn.Enabled:=true;
end;
end;