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 IAsyncResult BeginInquiry(int maxDevices, TimeSpan inquiryLength, AsyncCallback callback, object state, BluetoothClient.LiveDiscoveryCallback liveDiscoHandler, object liveDiscoState, DiscoDevsParams args) { _fcty.SdkInit(); _fcty.RegisterCallbacksOnce(); // byte maxDurations; byte maxNum; CommonDiscoveryBluetoothClient.ConvertBthInquiryParams(maxDevices, inquiryLength, out maxNum, out maxDurations); return(BeginInquiry(maxDevices, inquiryLength, callback, state, liveDiscoHandler, liveDiscoState, delegate() { BtSdkError ret = _fcty.Api.Btsdk_StartDeviceDiscovery( AnyClass, maxNum, maxDurations); BluesoleilUtils.CheckAndThrow(ret, "Btsdk_StartDeviceDiscovery"); }, args)); }
public override void Connect(BluetoothEndPoint remoteEP) { if (remoteEP.Port != 0 && remoteEP.Port != -1) { throw new NotSupportedException("Don't support connect to particular port. Please can someone tell me how."); } // _factory.SdkInit(); _factory.RegisterCallbacksOnce(); // Need to use event DISC_IND to close the Stream/SerialPort. // BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(remoteEP.Address, _factory); UInt32 hDev = bdi.Handle; UInt32 hConn; byte channel; int comPort; ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); //if (_HasPort(remoteEP)) { // ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); //} else { // UInt16? svcClass16; // if (!ServiceRecordUtilities.IsUuid16Value(remoteEP.Service)) { // svcClass16 = null; // } else { // svcClass16 = (UInt16)ServiceRecordUtilities.GetAsUuid16Value(remoteEP.Service); // } // UInt16[] specialClasses = { }; // if (svcClass16.HasValue && IsIn(svcClass16.Value, specialClasses)) { // throw new NotImplementedException("Internal Error: Should not use this code."); //// The original method we used for connecting did not work for //// profiles that BlueSoleil has support for -- returning no COM //// port but enabling per-profile support //// We have a second way, which seems to work in those cases //// but it is more complex -- we manually allocate the port etc //// (also it doesn't give us the remote RFCOMM channel). //// Use the first method for now except in special cases... // //UInt32 comSerialNum; // //UInt32? comSerialNum; // //ConnectRfcommPreAllocateComPort(svcClass16.Value, hDev, // // out hConn, out channel, out comPort // // //, out comSerialNum // // ); // } else { // ConnectRfcomm(remoteEP, hDev, out hConn, out channel, out comPort); // } //} _remoteEp = new BluetoothEndPoint(remoteEP.Address, BluetoothService.Empty, channel); // var serialPort = CreateSerialPort(); if (BufferSize.HasValue) { serialPort.ReadBufferSize = BufferSize.Value; serialPort.WriteBufferSize = BufferSize.Value; } serialPort.PortName = "COM" + comPort; serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); //((System.ComponentModel.IComponent)serialPort).Disposed // += delegate { System.Windows.Forms.MessageBox.Show("BlueSoleil's SerialPort disposed"); }; // // We pass '_hConn' as the Stream handles calling // Btsdk_Disconnect to close the RFCOMM connection. var strm = new BlueSoleilSerialPortNetworkStream(serialPort, hConn, this, _factory); _stream = strm; int liveCount = _factory.AddConnection(hConn, strm); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "BlueSoleilClient.Connect LiveConns count: {0}.", liveCount)); // TODO who handles closing the connection if opening the port fails }