I am looking for a demo/example of how to use VaBuffer to capture a data packet. The packet starts with the $ character and is 738 bytes long. I cannot use VaCapture as there are null values in the packet.
I am missing something, as I am getting garbage. Also I get a lockup when disconnecting the VaComm
Ray.
type TCapturestate = (csNone, csCaptureStart, csCaptureEnd);
var // Global varaialbes
cs: TCaptureState; RxData: array[0..1000] of byte;
procedure TSymCommsDlg.VaComm1RxChar(Sender: TObject; Count: Integer); var sig_start, sig_end: byte; b: byte; i: integer; begin cs := csNone; sig_start := $24; sig_end := $7E; i := 0;
while cs <> csCaptureEnd do begin if vacomm1.ReadBufUsed > 0 then begin vacomm1.ReadBuf(b,1); case cs of csCaptureStart: begin if b = sig_end then cs := csCaptureEnd else begin RxData := b; inc(i); end; end;
csNone: if (b = sig_Start) then cs := csCaptureStart; end; application.ProcessMessages; ProcessData; end; end; end;
I have it working, but I am not getting all the bytes. I am missing the first byte ($02),
I get E2 20 55 73 65 72 20 44 65 etc...
when it should be 02 E2 20 55 73 65 72 20 44 65 etc...
Below is the code used.
I wish TMS would add a capture VCL that would capture this type of data correctly. I just do not want to have to learn how to write my own comms code. I am happy to pay for you to do this.
Ray.
type TCapturestate = (csNone, csCaptureStart, csCaptureEnd);
var
RxData: array[1..1000] of Byte;
procedure TSymCommsDlg.VaComm1RxChar(Sender: TObject; Count: Integer); begin if Count >= 742 then begin GetData; end; end;
procedure TSymCommsDlg.GetData; var cs: TCaptureState; sig_start, sig_end: byte; b: byte; i: integer; begin cs := csNone; sig_start := $24; sig_end := $7E; i := 0;
while cs <> csCaptureEnd do begin if vacomm1.ReadBufUsed > 0 then begin vacomm1.ReadBuf(b,1);
case cs of csCaptureStart: begin if b = sig_end then cs := csCaptureEnd else begin RxData := b; inc(i); end; end;
csNone: if (b = sig_Start) then cs := csCaptureStart;
First of all, I don't understand if this code would compile at all. An assignment like
RxData := b;
should certainly fail. I see your array starts from index 1, i starts from index 0. If your array starts from index 1 you should set the first byte in RxData[1]
I see that in your code you declare a pointer to b and nowhere you allocate memory for this pointer. That will of course cause that ReadBuf() fails writing to a memory address that is not allocated.