Page 1 of 1

Pass the whole RemoteDevice object to the BeginRea

Posted: Tue Dec 02, 2008 8:31 pm
by elhafid
Hello

Sorry about the email.

Please i need the application to store which device belongs to which Stream.

How is it possible to pass the whole RemoteDevice object to the BeginRead.

Where can i find example...
Could you give me an example of code making this please.

Thank you again and sorry.

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Tue Dec 02, 2008 9:30 pm
by Jonas
Instead of passing m_stream like it does in the sample, pass the RemoteDevice object. I think it's stated in the sample even, that it can be any object.
There is no sample of this however, you have to create this yourself.

Regards,
Jonas

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Tue Dec 02, 2008 9:40 pm
by elhafid
Thank you...

I'm going to try....

Regard.

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Tue Dec 02, 2008 11:50 pm
by elhafid
Hi Jonas...

You said me that i could pass the whole RemoteDevice object to the BeginRead.

How the link is made between stream en device ??

There is somethink that is not clear for me.

Thank you.

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Wed Dec 03, 2008 12:13 am
by Jonas
Well, it doesn't have to be the actual device. But as I wrote above, you can pass any object to BeginRead.

Code: Select all

m_stream.BeginRead(m_buffer, 0, m_buffer.Length, New AsyncCallback(AddressOf ReadCallback), device)
Then you can retrieve this object in the callback

Code: Select all

device = blueAsyncResult.AsyncState
Regards,
Jonas

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Wed Dec 03, 2008 12:18 am
by elhafid
Thanks again...

Yes i understand this, but after, in callback sub, how to access to the data that this device send...??

it is that was not clear for me...

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Wed Dec 03, 2008 1:35 am
by Jonas
Pass an object that contains the device and the Stream. Or pass the service itself, it contains the Address which will be unique for the device.
Since you can cast back and forth here, I don't see the problem?

Regards,
Jonas

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Wed Dec 03, 2008 2:09 am
by elhafid
Thanks...
So in callback sub, it seems to be as simple as : ??


Dim blueAsyncResult As BlueToolsAsyncResult = result
Dim device = blueAsyncResult.AsyncState

buffer = blueAsyncResult.buffer

Try
len = m_stream.EndRead(result)
m_stream.BeginRead(m_buffer, 0, m_buffer.Length, New AsyncCallback(AddressOf
ReadCallback), device)

...

RE: Pass the whole RemoteDevice object to the BeginRea

Posted: Wed Dec 03, 2008 7:55 pm
by elhafid
Hi Jonas

After reading many classes, for my need i have to :

- have a remotedevice list of all discovered remote device
- have a remoteservice list for each remote device discovered
- For each current remote service of the remoteservice list
call m_stream.beginread method whith call the readcallback method
- loop allways in this remoteservice list.

Is this algorithm possible ?

Thank you again.