• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 23, 2024, 05:07:46 pm

News:

SMF - Just Installed!


Send more strings

Started by lopezan, March 27, 2014, 04:36:11 pm

Previous topic - Next topic

lopezan

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

Hello

There are several ways to implement such tasks.

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

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

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

So, it's not possibile to do a such thing of operation with your component?