SPP on Widcomm Stack success - now help with SPP on MS Stack

Topics: Bluetooth - Microsoft, Samples
Nov 14, 2012 at 8:20 AM

Well after some months of battling I've finally got to my goal of being able to access an Opticon barcode scanner (OPN2002) via bluetooth and the WIDCOMM STACK.

Now I'd like to be able to do the same on the MS Stack simply because I don't know what the BT Dongle will be that the use will be using.

Below is the code that shows me what I want to see (being proof that I can access the scanner).

Anyone able to help me convert this so it works on the MS stack? (I've battle for MONTHS with no joy  -  and I HOPE this posting will at least help those that follow in some small way).

Dave.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth.Widcomm;
using Opticon;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string id = "";
            

            BluetoothClient bc = new BluetoothClient();
           
            BluetoothDeviceInfo[] devices = bc.DiscoverDevices();
            

            foreach(BluetoothDeviceInfo dev in devices)
            {
                Console.WriteLine(Convert.ToString(dev.DeviceName));
                Console.WriteLine(dev.Connected);

                if (dev.DeviceName.Contains("OPN2002") & dev.Remembered == true)
                {
                    WidcommSerialPort wsp = WidcommSerialPort.CreateClient(dev.DeviceAddress);
                    Console.WriteLine("port number is " + Convert.ToString(wsp));
                    Console.WriteLine("port number is " + Convert.ToString(wsp.PortName));

                    int v = Convert.ToInt32(Convert.ToString(wsp.PortName).Substring(3));
                    
                    Opticon.csp2.WakeUp();
                    Opticon.csp2.Interrogate();

                    int iRet = Opticon.csp2.Init(v);

                    Int32 iCount = Opticon.csp2.ReadData();

                    for (Int32 i = 0; i < iCount; i++)
                    {

                        Opticon.csp2.GetDeviceId(out id);

                        Opticon.csp2.BarCodeDataPacket aPacket;
                        iRet = Opticon.csp2.GetPacket(out aPacket, i);
                       
                        Console.WriteLine("data read in {0}", aPacket.strBarData);
                       
                    }
                }


                if (dev.DeviceName.Contains("OPN2002") & dev.Remembered == false)
                {
                    string pin = dev.DeviceName.Substring(8, dev.DeviceName.Length - 8);

                    BluetoothWin32Authentication mem = new BluetoothWin32Authentication(dev.DeviceAddress, pin);
                    bc.SetPin(pin);
                }
                
                Console.WriteLine(Convert.ToString(bc.GetRemoteMachineName(dev.DeviceAddress)));
                    
            }
        }
    }
}