/// <summary> /// Puts the SD in INQUIRY (discovery) mode for 30 seconds and returns /// up to 10 devices seen during that time. /// </summary> /// <returns> /// A list of up to 10 seen devices, or null if error or no devices seen /// </returns> /// <remarks> /// Power consumption during INQUIRY mode is 48 mA /// </remarks> public override BTDeviceInfo[] Inquiry() { if (!m_devicePresent || !ChangeState(BTDeviceState.STANDBY, BTDeviceState.PENDING)) throw new InvalidOperationException(); try { m_ioCtrl.WriteCmd(false, c_OneSecondTimeout, c_ATC_BTINQ, null); if (c_ATR_OK == m_ioCtrl.WaitForResultResponse(32 * 1000)) { ArrayList devList = new ArrayList(); byte[] info = null; while (null != (info = m_ioCtrl.ReadResponse())) { string[] devInfo = ConvertToString(info, info.Length).Trim().Split(new char[] { ',' }); BTDeviceInfo dev = new BTDeviceInfo(); dev.Address = devInfo[0]; dev.Name = devInfo[1]; devList.Add(dev); } ForceState(BTDeviceState.STANDBY); if (0 == devList.Count) return null; BTDeviceInfo[] devArray = new BTDeviceInfo[devList.Count]; for (int i = 0; i < devList.Count; i++) devArray[i] = (BTDeviceInfo)devList[i]; return devArray; } } finally { ForceState(BTDeviceState.STANDBY); } return null; }
/// <summary> /// Retrieves the device configuration information including address, name, /// authentication on/off, and encryption on/off. Results are stored in /// public member variables. /// </summary> public override void UpdateDeviceStatus() { if (!m_devicePresent || !ChangeState(BTDeviceState.STANDBY, BTDeviceState.PENDING)) throw new InvalidOperationException(); try { DeviceInfo = new BTDeviceInfo(); m_ioCtrl.WriteCmd(false, c_OneSecondTimeout, c_ATC_BTINFO, null); if (c_ATR_OK == m_ioCtrl.WaitForResultResponse(c_OneSecondTimeout)) { byte[] cfg = m_ioCtrl.ReadResponse(); string configStr = ConvertToString(cfg, cfg.Length); string[] configStrs = configStr.Trim().Split(new char[] { ',' }); DeviceInfo.Address = configStrs[0]; DeviceInfo.Name = configStrs[1]; Authentication = ('1' == configStrs[4][0]) ? true : false; Encryption = ('1' == configStrs[5][0]) ? true : false; } } finally { ForceState(BTDeviceState.STANDBY); } }