void doConnect() { killKeyWedge(); Application.DoEvents(); btdev = new BTdevice(ref log); log.WriteLog("Using BT MAC: '" + _sBT + "'"); if (btdev.DoAssociation(_sBT)) { log.WriteLog("Association OK"); } else { log.WriteLog("Association FAILED"); } btdev.Dispose(); btdev = null; if (bAutoClose) { threadCloseApp = new System.Threading.Thread(closethread); threadCloseApp.Start(); } Application.DoEvents(); }
public setBTscanner() { InitializeComponent(); m_deleInfo = new EventHandler(loginfoCallback); log = new logging(ref textBox1, m_deleInfo); log.WriteLog("+++++ START +++++"); }
public setBTscanner(string sBT) { InitializeComponent(); _sBT = sBT; txtBTmacAddress.Text = _sBT; m_deleInfo = new EventHandler(loginfoCallback); //calback delegate for log display log = new logging(ref textBox1, m_deleInfo); log.WriteLog("+++++ START +++++"); bAutoClose = true; threadConnect = new System.Threading.Thread(connectthread); threadConnect.Start(); }
public BTdevice(ref logging lg) { log = lg; try { preparePSWMD0C(); #if USE_SSAPI BTpower btPower = new BTpower(); if (btPower.IsBluetoothOn() == false) { log.WriteLog("BT power is OFF, trying to switch ON..."); btPower.TurnOnBluetooth(); if (btPower.IsBluetoothOn() == false) { log.WriteLog("BT power switch ON failed"); } else { log.WriteLog("BT power is now ON"); } } else { log.WriteLog("BT power was ON, no change"); } //btPower.Dispose(); #endif _deviceUtility = new DeviceUtility(); _deviceUtility.Initialize(xmlFileName); } catch (DeviceUtilityException ex) { log.WriteLog("DeviceUtilityException in BTdevice(): " + ex.Message); _deviceUtility = null; } catch (Exception ex) { log.WriteLog("Exception in BTdevice(): " + ex.Message); _deviceUtility = null; } log.WriteLog("BTdevice() OK"); }
public BTdevice(ref logging lg) { log = lg; try { preparePSWMD0C(); #if USE_SSAPI BTpower btPower = new BTpower(); if (btPower.IsBluetoothOn() == false) { log.WriteLog("BT power is OFF, trying to switch ON..."); btPower.TurnOnBluetooth(); if (btPower.IsBluetoothOn() == false) log.WriteLog("BT power switch ON failed"); else log.WriteLog("BT power is now ON"); } else log.WriteLog("BT power was ON, no change"); //btPower.Dispose(); #endif _deviceUtility = new DeviceUtility(); _deviceUtility.Initialize(xmlFileName); } catch (DeviceUtilityException ex) { log.WriteLog("DeviceUtilityException in BTdevice(): " + ex.Message); _deviceUtility = null; } catch (Exception ex) { log.WriteLog("Exception in BTdevice(): " + ex.Message); _deviceUtility = null; } log.WriteLog("BTdevice() OK"); }
public bool DoAssociation(string btAddr) { if (btAddr == "") { log.WriteLog("Missing BT Address!"); Win32.doBadBeeps(); return(false); } if (_deviceUtility == null) { log.WriteLog("DeviceUtility unavailable!"); Win32.doBadBeeps(); return(false); } string strDeviceName; log.WriteLog("FindDevice '" + btAddr + "'..."); if (!FindDevice(btAddr, out strDeviceName)) { log.WriteLog("Device not found!"); Win32.doBadBeeps(); return(false); } log.WriteLog("... Device was found"); log.WriteLog("Association of '" + strDeviceName + "'..."); foreach (string s in _sPasskeys) { try { log.WriteLog("Bonding..."); if (_deviceUtility.IsBondWithDeviceNeeded(strDeviceName)) { string strPasskey; log.WriteLog("Authentication: trying '" + s + "'..."); //deviceUtility.GetDeviceProperty(strDeviceName, DeviceUtility.PropertyName.Passkey); //if (string.Compare(strPasskey, "") == 0) //{ strPasskey = s; //strPasskey = "1111"; _deviceUtility.SetDeviceProperty(strDeviceName, DeviceUtility.PropertyName.Passkey, strPasskey); //} // Bond the computer and the device. // TODO: Because radio connections can sometimes fail, // you should build in retry logic when BondWithDevice // fails. This sample just tries once. _deviceUtility.BondWithDevice(strDeviceName); log.WriteLog("... Association and bonding finished"); break; } else { log.WriteLog("... no bonding needed"); break; } } catch (DeviceUtilityException ex) { log.WriteLog("Error in Association: " + ex.Message); return(false); } catch (Exception ex) { log.WriteLog("Error in Association: " + ex.Message); return(false); } }//foreach try { log.WriteLog("Registration..."); _deviceUtility.SetDefaultDevice(null, null, strDeviceName); // Set up a port to use the selected device. Refer to // the BtPort element in the XML file. //_deviceUtility.AddDevice(null, null, "BtPort"); //_deviceUtility.SetDeviceProperty("BtPort", DeviceUtility.PropertyName.DeviceAddress, "COM6:"); _deviceUtility.SetActiveDevice(null, null, strDeviceName); log.WriteLog("...Registration OK"); Win32.doGoodBeeps(); return(true); } catch (DeviceUtilityException ex) { log.WriteLog("Error in Registration: " + ex.Message); Win32.doBadBeeps(); return(false); } }