• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Packet->Data missing characters

Started by Jovans, October 27, 2011, 10:28:45 am

Previous topic - Next topic

Jovans

I am having an issue with the DataProcessor.

I have two packets both 18 chars long being sent from hardware to USB (FTDI)

Packet 1:
R,a,1,0,1,2,3,4,5,6,7,8,9,10,11,12,254,254

Packet 2:
R,b,1,0,12,11,10,9,8,7,6,5,4,3,2,1,253,254


void __fastcall TForm11::nrDataProcessor1DataPacket(TObject *Sender, TnrDataPacket *Packet)

{
if (Packet->PacketBegin == "Ra") {
  Memo1->Lines->Add(Packet->Data);
}
else if (Packet->PacketBegin == "Rb") {
   Memo2->Lines->Add(Packet->Data);
}
}


Output is "Ra" on Memo1 and "Rb" on Memo2.

The rest of the data is missing on the screen and breaking with the debugger shows Packet->Data only having 3 characters (R,a,\0 or R,b,\0). I understand that \0 is an invisible character, but shouldn't the packet data be shown in Packet->Data



How do I access the rest of the packet data. There is definitely 18 characters received?

Thanks

Roman Novgorodov

Hello

Thank you for information.

The detected packet contains 0 (zero, terminator) in data.
You can check Length of data and you will see that its length is 18.
I have tested DataProcBCB demo. All works fine with invisible chars.
You can try following code for output HEX codes of input data:

void __fastcall TForm1::nrDataProcessor1DataPacket(TObject *Sender,
      TnrDataPacket *Packet)
{
   AnsiString s = "";

   const void *d = Packet->Data.data();

   for(int i = 0; i < Packet->Data.Length(); i++)
   {
   s += IntToHex( ((PAnsiChar)d)[i], 2) + " ";
   }

   Memo1->Lines->Add(Packet->Caption + ":" + IntToStr(Packet->Data.Length()) + " == " + s + " === " + Packet->Data + "\r\n");

}


Roman Novgorodov
DeepSoftware LLC
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.