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)); }
bool IBluetoothSecurity.PairRequest(BluetoothAddress device, string pin) { //if (pin != null) { // throw new NotImplementedException("Only support pin 'null'/'Nothing' to show the UI dialog."); // BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(device, _factory); BTDEVHDL hDev = bdi.Handle; _factory.RegisterCallbacksOnce(); try { if (pin != null) { SetPin(hDev, pin); } BtSdkError ret = _factory.Api.Btsdk_PairDevice(hDev); // TODO Do we have to wait here for completion??? return(ret == BtSdkError.OK); } finally { if (pin != null) { RevokePin(hDev); } } }
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 }