Bluetooth Serial Port Question

Topics: Bluetooth - Microsoft
Jun 4, 2013 at 4:40 PM
I have been trying to get the In The Hand tools to work, to help me with a Bluetooth connection from a Windows Mobile 6 device to a printer, and a passport scanner. I think the printer is now working correctly as I can stream data to it, but I cannot get the passport scanner to work. The passport scanner has its own SDK, which requires the COM port. The passport scanner SDK then fires an event to interrupt the application every time a passport is scanned.

I think I am very close to getting my code working, but could really use some advice. Can anyone help me, please? Here's what I've done, and what I'm seeing:

I create a new BluetoothClient, and use it to DiscoverDevices. This works successfully, and I can then loop through the discovered devices to find the passport scanner.

I then set the BluetoothClient's PIN (using SetPin), and set Authenticate and Encrypt to TRUE

I then create a new BlutoothEndPoint, passing in the device's address and the GUID for a BluetoothSerialPort. This is also successful

I can then use the BluetoothClient's Connect method to initiate the connection, and at this point the passport scanner screen changes to "Connecting", so something is definitely working!

I then create a new serial port, using BluetoothSerialPort.CreateClient, and this is also successful, passing back COM9 as the port to use.

I don't know whether I need this next step or not, but I have found that by calling the device.SetServiceState, a new key is written to the registry key HKLM\SOFTWARE\Microsoft\Bluetooth\Serial\Ports, although the Port key is blank. I have tried moving this line of code around in my program to see if it needs to be done earlier, or later, but it dosn't seem to make any difference

At this stage, when I call the passport scanner's SDK with COM9 as the serial port, it fails to connect.

Summary, I've read lots of web pages talking about problems with Bluetooth serial ports, and ways to avoid using them, but my passport scanner's SDK requires a serial port, so I need to find a solution. I seem so close now, that I'm hoping I am just misunderstanding something, or need to add a line or two more of code.

Can anyone help me?

Jun 5, 2013 at 3:37 PM
I have continued to work on this, and believe the issue may be that I need to call RegisterDevice. Unfortunately I'm struggling with this as I can only find C# examples, and I'm not a C# developer. Can anybody provide an example of RegisterDevice working in VB.Net? Thanks
Jun 5, 2013 at 4:48 PM
Sorry, my fault. I finally realised that I was using both a BluetoothClient AND a BluetoothSerialPort at the same time, and they are mutually exclusive. I have removed the BluetoothClient, and the BluetoothSerialPort is now working fine!

So, it turned out to be nothing to do with RegisterDevice!