Wireless Communication Library Support Forum
Frameworks => Bluetooth Framework => Topic started by: ppaing126 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!!
-
Sorry, I mean wclClientData event.
-
Hello,
You can use wclSyncClient to read exactly amount you need or create internal buffer for incomming data.
-
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..?
-
At this moment I solved the issue doing a custom msg build, scanning the returned data.
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
-
wclSyncClient is available in latest WCL (6.11)
Your code looks OK but I do it other way.
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.
-
Thanks! I will give a Try.
-
Ok. I'm ready to order a developer license :)
-
Thank you. I do recomend to use PayPal as it is cheaper way.
-
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.
-
Yes of course. As soon as you send me a details I'll prepare and invoice.