• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 19, 2024, 12:43:47 pm

News:

SMF - Just Installed!


Some questions, please

Started by BigSphinx, April 02, 2010, 11:21:36 am

Previous topic - Next topic

BigSphinx

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

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

Thanks you very much.  This is well explained .

BigSphinx

April 10, 2010, 09:45:37 am #3 Last Edit: April 10, 2010, 09:50:32 am by BigSphinx
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.

Roman Novgorodov

Hello

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


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

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

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:

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

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.