elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

Pass the whole RemoteDevice object to the BeginRea

Tue Dec 02, 2008 8:31 pm

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.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Pass the whole RemoteDevice object to the BeginRea

Tue Dec 02, 2008 9:30 pm

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

elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

RE: Pass the whole RemoteDevice object to the BeginRea

Tue Dec 02, 2008 9:40 pm

Thank you...

I'm going to try....

Regard.

elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

RE: Pass the whole RemoteDevice object to the BeginRea

Tue Dec 02, 2008 11:50 pm

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.

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Pass the whole RemoteDevice object to the BeginRea

Wed Dec 03, 2008 12:13 am

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

elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

RE: Pass the whole RemoteDevice object to the BeginRea

Wed Dec 03, 2008 12:18 am

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...

Jonas
Posts: 2319
Joined: Mon Jan 09, 2006 2:20 pm
Location: Sweden

RE: Pass the whole RemoteDevice object to the BeginRea

Wed Dec 03, 2008 1:35 am

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

elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

RE: Pass the whole RemoteDevice object to the BeginRea

Wed Dec 03, 2008 2:09 am

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)

...

elhafid
Posts: 10
Joined: Wed Nov 26, 2008 10:41 pm
Location: France

RE: Pass the whole RemoteDevice object to the BeginRea

Wed Dec 03, 2008 7:55 pm

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.

Return to “BlueTools”