irda between two PPCs

B

Bob Nicholls

I wish to enable my CF application to receive vCards beamed (irda) from irda
enabled devices such as mobile phones, palm pilots, PPC etc. I have managed
to do this for all the devices I have to hand apart from the Pocket PC. Does
anyone have any idea why the following code running on a PPC 2003 device
doesn't work when the client (the device sending the vCard) is another PPC
2003? The code does work when the client is a Palm m515, vX and (all tested)
mobile phones. I believe it also works when the client is a PPC 2002, but I
no longer have access to such a device to confirm this.

When the code is working, the last line ("bytesRead...") returns the OBEX
connect command. When it is not working (i.e. receiving from a PPC 2003) it
returns nothing (0 bytes).


Dim irListen As New IrDAListener("OBEX")
Dim client As IrDAClient = Nothing
Dim stream As System.io.Stream = Nothing
Dim bytesRead As Integer
Dim databuf(1024) As Byte
irListen.Start()
client = irListen.AcceptIrDAClient
stream = client.GetStream
bytesRead = stream.Read(databuf, 0, databuf.Length)

Using the PPC 2003 OS beam command manually it is possible to beam contacts
between PPCs, Palms etc so it must be a fault with the way I am attempting
rather than a limitation with the PPC itself.

Those of you with good memories may remeber I had a similar thread to this
during summer last year. At that time I was using PPC 2002 and trying to
determine the proprietory (?) format that the PPC 2002 was using to send
contact details.

Thanks for any help,

Bob
 
B

Bob Nicholls

Just to confirm that it does work with PPC 2002. So the code below works
with all tested devices apart from PPC 2003!
What makes the latter different?

Bob
 
B

Bob Nicholls

I think I am the only one interested in this, but here is an update.

Changing the last line of the code from my original post (bytesRead = ...)
to the following works:

Try
bytesRead = stream.Read(databuf, 0, databuf.Length) 'this always causes
an exception
Catch ex As Exception
If Not stream Is Nothing Then
stream.Close()
End If
If Not client Is Nothing Then
client.Close()
End If
client = irListen.AcceptIrDAClient
stream = client.GetStream
bytesRead = stream.Read(databuf, 0, databuf.Length)
End Try

After that the clienta nd server interaction is as one would expect. Can
anyone explain why I need that initial stream.Read, which causes an
exception, to things off?

Bob
 
B

Bob Nicholls

This just gets weirder, in fact the exception only occurs single stepping in
debug mode. During normal execution the initial stream.Read always returns
0. So the following is required and does seem to work reliably.

bytesRead = stream.Read(databuf, 0, databuf.Length)
If bytesRead = 0 Then 'this is always the case for the
initial read
If Not stream Is Nothing Then
stream.Close()
End If
If Not client Is Nothing Then
client.Close()
End If
client = irListen.AcceptIrDAClient
stream = client.GetStream
bytesRead = stream.Read(databuf, 0, databuf.Length)
End If

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top