We use the demo (trial) version of the wcl library (.net 4.0) in a proof of concept scenario.
A 3rd party library we use communicates with a Bluetooth device through a serial port. This means the device has to be connected, paired and SPP enabled. We want to use wcl for automatic discovery, pairing and serial port creation.
Our application runs for only a few seconds, communicates with the device, and exits. What we want is, at the first time the application executes, to discover the device, pair it and create a virtual COM port for this device. Then the flow continues with the 3rd part library communicating with the device through the vCOM port. At subsequent executions of the application, we don't want to go through the discovery-pairing-vCOM creation part again, since the device should already be in windows' "Bluetooth Devices" list, paired and with SPP enabled.
We don't know if this is a limitation in the demo assemblies, or actually a bug in the wcl library, but whenever we open a virtual port on the device (we have successfully discovered it and paired it in the previous step) then
when the wclVirtualComPort object is disposed (or the api.Unload() method is called),
the COM port in Windows is destroyed too (it's not listed in windows device manager)
even if we haven't called .Close() method. Moreover, when the virtual com port is destroyed,
the Bluetooth device get's removed from windows' "Bluetooth devices" list, which forces the application to go through the discovery-pairing-port creation step each time it executes.
What we want is
- 1st application execution
- Discover the Bluetooth device
- Pair the Bluetooth device
- Enable SPP on the Bluetooth device (create vCOM port)
- Communicate with the Bluetooth device through the vCOM port
- Subsequent application executions
- Scan COM ports to communicate with device.
- If none of the COM ports communicates with the device go through the steps of first application execution
- Otherwise communicate with the Bluetooth device through the COM port we discovered in step 1
In the above scenario, we successfully do device discovery, pairing and port creation, but when the application exits, everything is wiped out of the system. The virtual COM port is destroyed and the device is removed from Bluetooth devices list.