Author Topic: OnData event: How to catch back the strings complete..?  (Read 23703 times)

ppaing126

  • Guest
OnData event: How to catch back the strings complete..?
« on: April 15, 2013, 03:08:22 PM »
Hello Mike,

I read the thread about a forum memeber about getting incomplete data via SPP.
http://forum.btframework.com/index.php/topic,620.0.html

I have the same problem. I realized the OnData sometimes get my 10 chars string but sometimes it get one char then nex time gets the other 9.
I need it to be 10 characters, say "123456789" + CR (9 numbers + Carriage return). I understand the OnData don't know my string size is 10 neither it has a CR terminator.

However, I need to get the 10 characters value from the device each time; how can I do this on a repetable and secure way of not to mess the chars.. ?

I'm using trial version but if it works for me I will buy for my new project.

Thanks in Advance!!

ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #1 on: April 15, 2013, 03:39:14 PM »
Sorry, I mean wclClientData event.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: OnData event: How to catch back the strings complete..?
« Reply #2 on: April 15, 2013, 04:57:36 PM »
Hello,

You can use wclSyncClient to read exactly amount you need or create internal buffer for incomming data.

ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #3 on: April 15, 2013, 05:07:57 PM »
Thanks Mike,
were can I see a demo about..? I'm using Wcl 6.9.30

Could you give me a clue about internal buffer..?


ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #4 on: April 15, 2013, 05:32:30 PM »
At this moment I solved the issue doing a custom msg build, scanning the returned data.

Code: [Select]
  MyMsg : String   //'Global variable

 //'On FormShow procedure initialize the variable
// MyMsg:='';

  procedure TfmMain.wclClientData(Sender: TObject; Buffer: Pointer;
    Size: Cardinal);
  var
    s: AnsiString;
 
  Begin
   SetLength(s, Size);
   CopyMemory(Pointer(s), Buffer, Size);

   For i:=1 to Size do
   Begin
     If S[I] <> #13 then    //Check if carriage return
     Begin
      If (S[I] in ['0'..'9']) or (S[I] = '-') or (S[I] = '.') then   //filter out non ascii chars..
       MyMsg:=MyMsg + S[i];   //build my msg
     End
     Else
     Begin
      meAns.Lines.Add(MyMsg);  //CR detected so myMsg is complete.
      MyMsg:='';
     End;
   end;

  end;


Is there a more elegant way to do this?   :P

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: OnData event: How to catch back the strings complete..?
« Reply #5 on: April 15, 2013, 06:35:54 PM »
wclSyncClient is available in latest WCL (6.11)

Your code looks OK but I do it other way.

Code: [Select]
TfmMain = class(TForm)
....
private
  FBuffer: AnsiString; // To make it working on any Delphi/CBuilder version
end;

procedure TfmMain.wclClientConnect(Sender: TObject; Error: Integer);
begin
  // Your code processes connect
  ....
  if Error = WCL_E_SUCCESS then FBuffer := '';
end;

procedure TfmMain.wclClientData(Sender: TObject; Buffer: Pointer; Size: Cardinal);
var
  s: AnsiString;
  i: Integer;
begin
   SetLength(s, Size);
   CopyMemory(Pointer(s), Buffer, Size);
   if s <> '' then begin
    FBuffer := FBuffer + s;
    i := Pos(#13, FBuffer);
    if i > 0 then begin
     s := Copy(FBuffer, 1, i - 1);
     FBuffer := Copy(FBuffer, i + 1, Length(FBuffer));
     meAns.Lines.Add(s);
    end;
  end;
end;

Something like that.

ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #6 on: April 15, 2013, 07:20:06 PM »
Thanks!  I will give a Try.

ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #7 on: August 16, 2013, 06:20:49 AM »
Ok. I'm ready to order a developer license   :)

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: OnData event: How to catch back the strings complete..?
« Reply #8 on: August 16, 2013, 06:39:39 AM »
Thank you. I do recomend to use PayPal as it is cheaper way.

ppaing126

  • Guest
Re: OnData event: How to catch back the strings complete..?
« Reply #9 on: August 16, 2013, 04:10:36 PM »
If using Paypal, can I have the invoice at my client Name..?

I need to pay with my expense but invoice must be prapred at client's name & address.
I will email you now.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: OnData event: How to catch back the strings complete..?
« Reply #10 on: August 17, 2013, 11:34:45 AM »
Yes of course. As soon as you send me a details I'll prepare and invoice.

 

Sitemap 1 2 3 4 5 6 7