Author Topic: Some questions, please  (Read 2623 times)

BigSphinx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Some questions, please
« on: April 02, 2010, 02:21:36 pm »
I have to rewrite a piece of source code that uses the component TapdComport. I'd like to replace the component TnsCom I find most enjoyable.
1 / I would like to know if there is an equivalent of the "FlushInputBuffer" with TnrCom or, the "TnrCom-> FlushOutputBuffer" has the same property?
(I can use and ClearDeviceInput ClearDeviceOutput?)

2 / How can I replace the functions "ApdComPort-> PeekBlock (buffer, 6)

and, for example, "ApdComPort-> GetBlock (buffer, 6)?

(I can use Read (buffer, 6) and SendData (buffer, 6)?)
Thank you for responding.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Some questions, please
« Reply #1 on: April 03, 2010, 10:38:22 am »
Hello

1) You can try following methods for clear serial port buffers:

TnrComm.ClearDeviceInput();
TnrComm.ClearDeviceOutput();
TnrComm.ClearDeviceBuffers();

2) I can't explain what exactly you can use for replace APro class. You can choose from following methods:

// reads needed number of data and waits if necessary
TnrComm.Read(Buffer:PAnsiChar;Len:cardinal);

// gets all received (are in input buffer) bytes
TnrComm.ReadAll(Buffer:PAnsiChar);

// get MaxLen bytes and waits if necessary
TnrComm.ReadMax(Buffer:PAnsiChar; MaxLen:integer):integer;

// gets all received bytes as string
TnrComm.ReadString:AnsiString;

// sends (writes) single byte synchronously
TnrComm.SendChar(const Ch:Char);

// sends (writes) single AHEAD byte synchronously
TnrComm.SendAheadChar(const Ch:Char);

// sends (writes) string of bytes synchronously
TnrComm.SendString(const S:AnsiString);

// sends (writes) byte array asynchronously
TnrComm.SendData(const Buff:PAnsiChar;const N:cardinal);

// waits necessary length (Count) of incoming data Ms milliseconds
TnrComm.WaitForBytes(Count, Ms: cardinal): boolean;

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

BigSphinx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Some questions, please
« Reply #2 on: April 05, 2010, 07:55:22 am »
Thanks you very much.  This is well explained .

BigSphinx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Some questions, please
« Reply #3 on: April 10, 2010, 12:45:37 pm »
Help me please to find a solution. I read a string which is as follows:
Sequence 1: 4 characters, + #13
Sequence 2: 64 characters + #13
Sequence 3: string, length unknown

I tried this:

TForm1.nrDataProcessor1DataPacket procedure (Sender: TObject;
  Packet: TnrDataPacket);
begin
  Memo1.Lines.Add (Packet.Caption + ':' + Packet.Data);
end;


I respected the properties of items TnrDataProcessor.
Nothing received.

On the other hand, without used component TnrDataProcessor, I only get the first 4 characters when I use the method ncComm1-> AfterReceive. The parameter Received  returns always the number 4.

Excuse my ignorance, I'm a beginner, but is there a way to "jump" the character #13? Thank you and excuse my bad English.
« Last Edit: April 10, 2010, 12:50:32 pm by BigSphinx »

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Some questions, please
« Reply #4 on: April 11, 2010, 06:15:42 pm »
Hello

If your form contains nrDataProcessor1 component, you can add needed packets at runtime:

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  with nrDataProcessor1.DataPackets.Add do begin
    Active := True;
    PacketLength := 4;
    PacketEnd := #13;
    ResetOthers := True;
    Caption := '1st packet type';
  end;
  with nrDataProcessor1.DataPackets.Add do begin
    Active := True;
    PacketLength := 64;
    PacketEnd := #13;
    ResetOthers := True;
    Caption := '2nd packet type';
  end;
  with nrDataProcessor1.DataPackets.Add do begin
    Active := True;
    PacketEnd := #13;
    ResetOthers := True;
    Caption := '3rd packet type';
  end;
end;

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

BigSphinx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Some questions, please
« Reply #5 on: April 12, 2010, 07:23:13 am »
Thank you for your response! I think I have done here but, on the Object Inspector, not in runtime.
I'll try this formula.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Some questions, please
« Reply #6 on: April 12, 2010, 07:44:21 am »
Hello

It is difficult to enter invisible char #13 in string property of object inspector.

I have checked your message with packet description again.
It seems like something wrong in your logic.
It's impossible to detect three different packets by your conditions.

You can just detect packet by #13 end char and analyze its real length in event handler.
You need following packet only:

Code: [Select]
with nrDataProcessor1.DataPackets.Add do begin
    Active := True;
    PacketEnd := #13;
    ResetOthers := True;
    Caption := 'String packet type';
  end;


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

BigSphinx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Some questions, please
« Reply #7 on: April 12, 2010, 11:08:38 am »
Excuse me, I misspoke. Indeed, this is not the # 13 but # 0.
If I may, I am sending you a PM to better explain
Thank you again for your availability.