Author Topic: Send more strings  (Read 927 times)

lopezan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Send more strings
« on: March 27, 2014, 07:36:11 pm »
Hello,
I have to send more strings to a serial device.
After each string, I have to wait a reply from the serial device and then send the next string.
How can I do this.
Regards.

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Send more strings
« Reply #1 on: March 28, 2014, 03:53:00 pm »
Hello

There are several ways to implement such tasks.

Please take a look source code of
Demos\SimplePacket\SimplePacket.dpr sample project.

Code: [Select]
procedure TForm1.DoSomethingWithPacket(S:string);
begin
   nrComm1.SendString('My new outgoing string ');
end;

procedure TForm1.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;
  Received: Cardinal);
var i:integer;
    ch:AnsiChar;
begin
  for i := 0 to Received - 1 do begin
    ch := PAnsiChar(Buffer)[I];
    if ch = EndOfPacket[idxEOP] then begin
      if idxEOP >= Length(EndOfPacket) then begin
        DoSomethingWithPacket(DataPacket);
        DataPacket := '';
        idxEOP := 1;
      end;
      Inc(idxEOP);
    end else begin
      idxEOP := 1;
      DataPacket := DataPacket + ch;
    end;
  end;
end;

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.

lopezan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Send more strings
« Reply #2 on: March 28, 2014, 05:34:57 pm »
Hello,
thanks,
but I need to send a string, then I wait to receive a string from the device connected to RS232 and if the packet received is ok I will send the next string and so on.

lopezan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Send more strings
« Reply #3 on: April 01, 2014, 06:34:40 am »
So, it's not possibile to do a such thing of operation with your component?