문제

i'm working on ecr software.

This software talks with hardware that has com port.

I'm programming in delphi and i'm using TComPort and TDataPacket component.

I have a problem (i think, or maybe i don't understand how tdatapacket works).

For printing a receipt i have to send to the hardware some string formatted by protocol rules.

The protocolo for printing is this:

Me: ENQ

HW: ACK

Me: STX + string + checksum(string) + ETX

HW: ACK

Me: STX + string + checksum(string) + ETX (closing string)

HW: ACK and print the receipt

I wrote this code:

procedure TForm1.Button4Click(Sender: TObject);
var
  snd, ckSum: String;
  checkSum : Byte;
begin
  if ack = #$06 then
  begin
    snd := '5/1/0.00//1.000000/SALDO/';
    checkSum := calcCheckSum(snd);
    ckSum := formatfloat('00',checkSum);
    ComPort.WriteStr(#$02 + snd + ckSum + #$03);
  end;
end;

and on the datapacket on packet event this:

procedure TForm1.ComDataPacket1Packet(Sender: TObject; const Str: string);
begin
  ack := Str;
end;

But if i try to print the value of ack i always have empty string, what i'm doing wrong?

올바른 솔루션이 없습니다

다른 팁

Try using ComPort.Read and get the readed data buffer, after you can parse it according at all that you need.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top