//---- private void ConnectRfcomm(BluetoothEndPoint remoteEP, UInt32 hDev, out UInt32 hConn, out byte channel, out int comPort) { Structs.BtSdkAppExtSPPAttrStru sppAttr = new Structs.BtSdkAppExtSPPAttrStru(remoteEP); // Debug.WriteLine("Gonna Btsdk_ConnectAppExtSPPService with: " + sppAttr.ToString()); BtSdkError ret = _factory.Api.Btsdk_ConnectAppExtSPPService(hDev, ref sppAttr, out hConn); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "ret: {0}, hConn: 0x{1:X}, with: {2}", ret, hConn, sppAttr.ToString())); _hDev = hDev; BluesoleilUtils.CheckAndThrow(ret, "Btsdk_ConnectAppExtSPPService"); // var comNumGetClientPort = _factory.Api.Btsdk_GetClientPort(hConn); Debug.WriteLine("comNumGetClientPort: " + comNumGetClientPort); // if (sppAttr.rf_svr_chnl != 0) { Debug.Assert(sppAttr.com_index != 0, "Argghhhh com_index is zero! (When rf_svr_chnl isn't)."); channel = sppAttr.rf_svr_chnl; comPort = sppAttr.com_index; } else { // Some profiles are handled specifically OBEX, etc etc // so they don't create a COM port when that Debug.Assert(sppAttr.com_index == 0, "Don't expect a COM port to be created in this (fail) case."); // // Connecting to SPP 0x1101 also returns no com port in the // struct but a COM port is connected for it. Btsdk_GetClientPort // DOES return the correct port see whether we're in that case. if (comNumGetClientPort != 0) { comPort = comNumGetClientPort; channel = 0; // Unknown! } else { // Highly likely an OPP/etc connection was made, and not a RFCOMM // connection, and thus no COM port we can use. :-( So fail! Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "BlueSoleil seems no RFCOMM connection made, closing. (channel: {0}, COM: {1})", sppAttr.rf_svr_chnl, sppAttr.com_index)); // (Note: Add a dummy record so RemoveLiveConnection works ok). int liveCountB = _factory.AddConnection(hConn, NullBluesoleilConnection.Instance); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "BlueSoleilClient.Connect non-RFCOMM LiveConns count: {0}.", liveCountB)); var retD = _factory.Api.Btsdk_Disconnect(hConn); BluesoleilUtils.Assert(retD, "Close non-RFCOMM connection"); throw BluesoleilUtils.ErrorConnectIsNonRfcomm(); } } //System.Windows.Forms.MessageBox.Show("BlueSoleil created port: '" + comPort + "'."); }
internal BluesoleilRadio(BluesoleilFactory fcty) { _fcty = fcty; _fcty.SdkInit(); BtSdkError retAddr, ret; byte[] bd_addr = new byte[StackConsts.BTSDK_BDADDR_LEN]; ret = retAddr = _fcty.Api.Btsdk_GetLocalDeviceAddress(bd_addr); BluesoleilUtils.Assert(retAddr, "Btsdk_GetLocalDeviceAddress"); if (ret == BtSdkError.OK) { _addr = BluesoleilUtils.ToBluetoothAddress(bd_addr); } else { _addr = BluetoothAddress.None; } // byte[] arr = new byte[500]; UInt16 len = checked ((UInt16)arr.Length); ret = _fcty.Api.Btsdk_GetLocalName(arr, ref len); if (retAddr == BtSdkError.OK) { BluesoleilUtils.Assert(ret, "Btsdk_GetLocalName"); } if (ret == BtSdkError.OK) { _name = BluesoleilUtils.FromNameString(arr, len); } else { _name = string.Empty; } // uint cod; ret = _fcty.Api.Btsdk_GetLocalDeviceClass(out cod); //BluesoleilUtils.CheckAndThrow(ret); if (retAddr == BtSdkError.OK) { Debug.Assert(ret == BtSdkError.OK, "Btsdk_GetLocalDeviceClass ret: " + ret); } _cod = new ClassOfDevice(cod); // _lmp = new Structs.BtSdkLocalLMPInfoStru(HciVersion.Unknown); ret = _fcty.Api.Btsdk_GetLocalLMPInfo(ref _lmp); if (retAddr == BtSdkError.OK) { BluesoleilUtils.Assert(ret, "Btsdk_GetLocalLMPInfo"); } }
internal static void FreeComIndex(BluesoleilFactory factory, int comNum, uint comSerialNum) { Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "BluesoleilClient.FreeComIndex IN: comNum: {0}, comSerialNum: {1}", comNum, comSerialNum)); BtSdkError ret; var comNum8 = checked ((byte)comNum); ret = factory.Api.Btsdk_DeinitCommObj(comNum8); BluesoleilUtils.Assert(ret, "Btsdk_DeinitCommObj"); factory.Api.Btsdk_PlugOutVComm(comSerialNum, StackConsts.COMM_SET.Record); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "BluesoleilClient.FreeComIndex OUT: Btsdk_DeinitCommObj ret: {0}", ret)); }
internal void Dispose(bool disposing) { if (!_needsDispose) { return; } // CloseAnyLiveConnections(); // _needsDispose = false; BtSdkError ret = _api.Btsdk_Done(); BluesoleilUtils.Assert(ret, "Btsdk_Done"); }
public void SetMode(bool?connectable, bool?discoverable) { BtSdkError ret; ret = _fcty.Api.Btsdk_StartBluetooth(); BluesoleilUtils.Assert(ret, "Radio.set_Mode Start"); StackConsts.DiscoveryMode mask; // Always need to get, to get pairable etc. ret = _fcty.Api.Btsdk_GetDiscoveryMode(out mask); BluesoleilUtils.Assert(ret, "Radio.set_Mode Get"); if (ret != BtSdkError.OK) { mask = StackConsts.BTSDK_DISCOVERY_DEFAULT_MODE; } // switch (connectable) { case true: mask |= StackConsts.DiscoveryMode.BTSDK_CONNECTABLE; break; case false: mask &= ~StackConsts.DiscoveryMode.BTSDK_CONNECTABLE; break; // null NOP } switch (discoverable) { case true: mask |= StackConsts.DiscoveryMode.BTSDK_GENERAL_DISCOVERABLE; break; case false: mask &= ~StackConsts.DiscoveryMode.BTSDK_GENERAL_DISCOVERABLE; break; // null NOP } ret = _fcty.Api.Btsdk_SetDiscoveryMode(mask); BluesoleilUtils.Assert(ret, "Radio.set_Mode Set"); }
IList <UInt32> FindConnection(UInt32 hDev, UInt16 classId) { var hConnList = new List <UInt32>(); var hEnum = _factory.Api.Btsdk_StartEnumConnection(); if (hEnum == StackConsts.BTSDK_INVALID_HANDLE) { // BTSDK_INVALID_HANDLE here just means there are zero connections. return(hConnList); } while (true) { var connProp = new Structs.BtSdkConnectionPropertyStru(); var hConn = _factory.Api.Btsdk_EnumConnection(hEnum, ref connProp); if (hConn == StackConsts.BTSDK_INVALID_HANDLE) { break; } if (connProp.device_handle != hDev) { continue; } if (connProp.service_class != classId) { continue; } if (connProp.Role != StackConsts.BTSDK_CONNROLE.Initiator) { continue; } hConnList.Add(hConn); } var ret = _factory.Api.Btsdk_EndEnumConnection(hEnum); BluesoleilUtils.Assert(ret, "Btsdk_EndEnumConnection"); return(hConnList); }