Sending String via Bluetooth

Login to reply to this topic.
Wed, 2003-12-03 10:39
Joined: 2003-10-02
Forum posts: 73
Hi !!

So, another question for you Symbian Guru !!
Let's Start !!

I've done the follow:

_LIT(KFormat,"[%c]");

TBuf<2> first;
first.Format(KFormat,65); // I Get 'A'

TBuf<2> second;
second.Format(KFormat,66); // I Get 'B'

It work. NOW I've to send them via Bluetooth both at the same time, so I need to send AB, right ??

But If I do this:

RSocket iSendingSocket;
iSendingSocket.Write(first && second, iStatus);

It's wrong, that for sure.. How is it possible to send first and second in a string by using BT Huh

Any ideas Huh

Screener_it


Wed, 2003-12-03 11:31
Joined: 2003-07-22
Forum posts: 70
Sending String via Bluetooth
Hey
It is very Simple
_LIT(KFormat,"[%c,%c]");

first.Format(KFormat,65,66); // I Get 'A' and 'B'

To learn Symbian U have to try it yourself !!. Asking continues questions always will not help !

MeenuJ
Wed, 2003-12-03 16:27
Joined: 2003-11-26
Forum posts: 11
Sending String via Bluetooth
Quote from: meenuj
Hey
It is very Simple
_LIT(KFormat,"[%c,%c]");

first.Format(KFormat,65,66); // I Get 'A' and 'B'

To learn Symbian U have to try it yourself !!. Asking continues questions always will not help !

MeenuJ
Very nice. But as i understand it RSocket::write will take a TDesC8, and that should be able to contain a string. The Question is how to get from a Hbuf to a TDesC8 ? conversions from a TReal to a TDesC8 or TInt to Tdesc8? - are there any easy ways of doing these conversions back and forth?
As i see the KFormat example above, it's a bit much for a relatively simple conversion of two characters. - Is there anywhere somone has written something about this?

Regards
Thu, 2003-12-04 09:45
Joined: 2003-10-22
Forum posts: 100
Sending String via Bluetooth
Hey,

You can use a Lexer object to convert from TReal to TDesC8. To convert HBuf into a TDesC8 assign the output of its Des method to a new TDesC8.


                                                Regards, Aljaz
Thu, 2003-12-04 10:08
Joined: 2003-10-02
Forum posts: 73
Sending String via Bluetooth
I've done in this way.

void CMessageClient::Create()
{
TBuf<256> tgt;
TBuf8<256> iMessagge;

_LIT(KFormat,"%c%c%c");
tgt.Format(KFormat,65,66,65^66);
Convert(tgt);
}

void CMessageClient::Convert(TDesC16& aUnicode)
{
CnvUtfConverter::ConvertFromUnicodeToUtf8(iMessagge, aUnicode);
}

So, when I want to send the string I just call

void CMessageClient::Send()
{
iSendingSocket.Write(iMessagge, iStatus);
SetActive();
}

And it works good. I'm sorry menuji if I post too many question in the forum... I'm a newbie and I try to do by myself but it's quite hard.
When I was able to do I answer I have done it, when I need help I have always say "Please" and never post it multiple times...

That's all.

Sorry for the bad english, hope you understand.

Screener_it

Fri, 2003-12-05 22:54
Joined: 2003-11-26
Forum posts: 11
Re: Sending String via Bluetooth
Quote from: aljaz25
Hey,

You can use a Lexer object to convert from TReal to TDesC8. To convert HBuf into a TDesC8 assign the output of its Des method to a new TDesC8.

                                                 Regards, Aljaz

Hi, now i might sound silly, but here goes.
I need to get from a TReal to a TDesC8 (via. bt) and from a TDesC8 to a TReal again.
This is causing me quite some problems. I never thourght would be this complicated. I've written a almost complete application sending and reveiving messages via BlueTooth, but can I get from a TDesc8 to a TReal and back? ...
It's only a matter of taking 4 (or Cool bytes of memory reading them into a TDesC8 and then back into a TReal. I've been reading in the UIQ Api about TLex8 and TDesC8, but I still can't see a simple way thrugh. Sorry to bother you folks.
Mon, 2003-12-08 19:02
Joined: 2003-11-26
Forum posts: 11
Conversions...
Ok, now i got the conversions rolling...

Solution was:
go from TDesC8 to TReal32
aBuffer is a TDesC8 returned from the BTEngine.

TPtrC8 TempPtrC8 = aBuffer.Mid(2,3); //Picks out the right characters
TLex8 TempLex = TLex8(TempPtrC8); //Create TLex8 from it.
TReal32 TempReal32; //Real for the result.
if (TempLex.Val(TempReal32)!=KErrNone) {  // do the conversion.
        _LIT(KERROR,"Error converting from LEX to REAL");
        iEnv->InfoMsg(KERROR);
}

And the other way from TReal32 to TDesC8 :
TPtr8 buf = iOutBuffer->Des();
buf.Zero();  //empty buf
... put some other two bytes into buf.
TBuf<8> TempReal;  //new temp TBuf
TempReal.Num(aRating,TRealFormat(3,1)); //Put aRating (TReal32) into TempReal
for (TInt i=0;i<TempReal.Length();i++) //append it the the original buf.
{
   buf.Append(TempReal[i]);
}
  • Login to reply to this topic.