Author Topic: DataPacket Detection  (Read 1323 times)

Jazz

  • Newbie
  • *
  • Posts: 3
    • View Profile
DataPacket Detection
« on: February 28, 2012, 07:39:34 am »
I'm looking to receive a packet (hex based) that has a packet header of $FE$FE$70$E0 and terminator of $FD.

I took the DataProc project and added the following:

procedure TForm1.FormCreate(Sender: TObject);
var
  dp: TnrDataPacket;
begin
  nrDataprocessor1.DataPackets.Clear;
  dp := nrDataprocessor1.DataPackets.Add;
  dp.Caption := 'Received Freq';
  dp.PacketLengthMax := 20;
  dp.PacketBegin:=#$FE#$FE#$E0#$70#$03;
  dp.PacketEnd:=#$FD;
  dp.OnPacketLength := GetReceivedFreqPacket;
end;

procedure TForm1.GetReceivedFreqPacket(Packet: TnrDataPacket;
  chData: Byte; var IsHandled: Boolean);
begin
  ShowMessage('Received Frequency');
end;

And I modified the procedure
procedure TForm1.nrDataProcessor1DataPacket(Sender: TObject;
  Packet: TnrDataPacket);
begin
  if Packet.Caption = 'Received Freq' then
    showmessage('received');

  Memo1.Lines.Add(Packet.Caption + ':' + Packet.Data );
end;



I ran the project and turn the dial to change frequency, which the nrcomm1.Terminal.Memo2 shows the command was received.  nrDataProcessor1DataPacket event is never triggered.

Am I missing something on trapping when this event happens?

I'm getting closer and closer to getting this component to do what I want for sending, but not for trapping signals received.

I send a command of
$FE$FE$70$E0$03$FD
 
and I expect a response (trapped) of $FE$FE$EO$70$03$00$30$31$14$00$FD


Thank you for assistance.

Lance

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: DataPacket Detection
« Reply #1 on: February 28, 2012, 10:45:54 am »
Hello

Thank you for information.

Please check that Active property of packet is True:

dp.Active := True;

Also I think you do not need handle OnPacketLength event if your packet has both values: PacketBegin and PacketEnd values.

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.

Jazz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: DataPacket Detection
« Reply #2 on: February 28, 2012, 04:42:08 pm »
Thank you.

I tried the active property, which I missed setting and know now that I should, and it did not work.

However, rearranged the form create event and it now works. I had the form create automatically start the com communication, which possible then prevented the dataprocessor from starting.

  nrDataprocessor1.DataPackets.Clear;
  dp := nrDataprocessor1.DataPackets.Add;
  dp.Caption := 'RCVFREQ';
  dp.PacketLength := 11;
  dp.PacketBegin:=#$FE#$FE#$E0#$70#$03;
  dp.PacketEnd:=#$FD;
  // no longer need event for packet length
  dp.Active := true;
  nrDataprocessor1.Active := true;
  CheckBox1.Checked := True;
  CheckBox1.OnClick(nil); // Turn on the com

Thank you.  It looks like I'm getting the pieces I need and hopefully will have everything needed to focus on the rest of my application.

Lance

Hello

Thank you for information.

Please check that Active property of packet is True:

dp.Active := True;


Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: DataPacket Detection
« Reply #3 on: February 28, 2012, 04:49:58 pm »
Hello

Thank you for your information.

Please note that you do not need this line of code:

Code: [Select]
dp.PacketLength := 11;
If you set PacketBegin and PacketEnd, the length of packet will be variable.

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.