Software solutions for a mobile world

I recently worked on a site that acquired some new Motorola MC67's, and also some Motorola RS507 ring scanners. The scanners are Bluetooth attached, and were replacing existing Bluetooth scanners. The existing ones were paired using the excellent 32Feet.Net library, but I encountered problems trying to pair the RS507's this way.

The way the pairing works is quite neat - you display the MAC address as a bar code, scan the bar code, and then pair. Motorola provide an application to do this, MotoBTUI, but this was a non-starter as it gives access to the OS, and the app is in Kiosk mode.

Not a problem - we can simply write our own screen to display the MAC address, and then pair it that way.
Yes a problem - it isn't that easy.

First of all we needed to display a barcode in the .Net CF. There are various libraries (I started with zXing), but none seemed to fit the bill. Probably my misuse, but our problem was we had to display the format as:-

Pairing bar codes are Code 128 or Data Matrix symbologies formatted as follows:
<Fun3>Bxxxxxxxxxxxx
Where xxxxxxxxxxxx represents the 12-character Bluetooth address"

This led to lots of searching to find out what <Fun3> was and how to add it to the barcode. So the need to search for another way to display the bar code. Much searching later, I came across "Barcode Image Generation Library" by Brad Barnhill on CodeProject. Further searching led me to the "Windows CE Programming" site, where there was a port to the compact framework. It also mentioned <FNC3> which gave me some hope.

So hopefully, we now had a library to display our MAC address as a barcode. Next problem - getting the Bluetooth MAC address of our device. As mentioned, we had used 32Feet.Net successfully in the past, but with the RS507, it appears unless everything is 'just so', they don't play nicely together. A 'quick' browse of the registry, told me I could get the MAC address from HKEY_LOCAL_MACHINE\Comm\SS1VNDIS1\Parms\NetworkAddress.

Armed with this information I could now display a bar code to pair the ring scanner. The code to do this is:-

string myBTAddress = String.Format("{0}B{1}", Convert.ToChar(202).ToString(), get_my_bt_mac_address());

where get_my_bt_mac_address reads the registry key described above, and in this case, returned me 34B1F7096DAB

The next stage is to display the barcode in a PictureBox on the form using our BarcodeLib. This is done by:-

Barcode barcode = new Barcode();
barcode.EncodedType = TYPE.CODE128B;
var type = TYPE.CODE128B;
           
picMacBarcode.Image = barcode.Encode(type, myBTAddress, Color.Black, Color.White, picMacBarcode.Width, picMacBarcode.Height);

This gives us a bar code image to scan - great. Run the program, display the barcode, scan it, and the 'standard' Bluetooth pairing interface appears, and asks us for a 4 digit code to pair. This was never a problem with 32Feet.Net as we could prevent this happening in code.

After several email conversations with Motorola support, it was decided that this was because we were using the Microsoft Bluetooth stack, which enforced the pairing prompt for security. However, the MC67 also supports the StoneStreet stack, which doesn't enforce this policy.

We also needed to enable and disable the BT scanner. Motorola provide a 'BTScannerCtlPanel' application which allows you to do this, but again we need to do this programmatically, to maintain our Kiosk mode. Again after several emails with Motorola, we found out we could launch this with a switch, from code, to turn the scanner on and off.

So, it appeared we now had all the pieces of the jigsaw, and the picture on the front of the box. All we needed to do now was put all the pieces together.

Switching to the StoneStreet stack was going to be done in the device build, but we still needed a check for this. The registry key for this is HKEY_LOCAL_MACHINE\Software\SymbolBluetooth\SSStack and should be set to 1 to enable the StoneStreet stack. You can also set HKEY_LOCAL_MACHINE\Software\SymbolBluetooth\SSStackBootState to 1 to keep the StoneStreet stack after booting. The code checks the value of SSStack, and if it isn't 1, then it sets both values to 1, politely informs the user that they need to reboot, and then reboots the device. We also set several other options for the StoneStreet stack as follows.
HKEY_LOCAL_MACHINE\Software\Stonestreet One\BTExplorer\Config\SecureSimplePairingOptions to 3
HKEY_LOCAL_MACHINE\Software\Stonestreet One\BTExplorer\Device Settings\DiscoverabilityMode to 2

 To turn the 'BTScannerCtlPanel' on and off start the process \Windows\BTScannerCtlPanel /a to enable the scanner and /d to disable the scanner.

The final piece of the jigsaw is to check that you can find the scanner, which we can do by enumerating the 'AvailableDevices' collection of the Symbol.Generic.Device collection. The code for this is:-

 Symbol.Generic.Device BTScanner = null;

 for (int i = 0; i < Symbol.Barcode.Device.AvailableDevices.Length; i++)
{
    if (Symbol.Barcode.Device.AvailableDevices[i].DeviceType.TransportType == Symbol.Barcode.TRANSPORT_TYPE
.BLUETOOTH_SSI)
       {
             BTScanner = Symbol.Barcode.Device
.AvailableDevices[i];
             break
;
        }
}

If after this, BTScanner is null, we haven't found a scanner.

Finally we have all the pieces in place, to pair a scanner programmatically. The method is:-

  1. Check that you are using the StoneStreet Stack
  2. Enable the scanner by starting the BTScannerCtlPanel
  3. Display the barcode using the Barcode lib
  4. Scan the barcode with the RS507 Scanner, and listen for the 'pairing' beep
  5. Ensure you can find the device in the collection (it should show up as SCN3:)

The finished screen looks like:

 

Thanks to the guys at Motorola for all the help, especially Riad Benallou. Hopefully this article will help someone to speed through their implementation - the RS507 Ring Scanner is a really nice device.

Originally posted 26/Nov/2013

Contact

M: +44 (0)7860 907493
B:  +44 (0)1204 657497

pete@gui-innovations.com

More

Connections

   

Twitter Feed