Esempio n. 1
0
        bool IBluetoothSecurity.RemoveDevice(BluetoothAddress device)
        {
            BluesoleilDeviceInfo bdi = BluesoleilDeviceInfo.CreateFromGivenAddress(device, _factory);
            // TO-DO We don't need to do Btsdk_UnPairDevice also do we?
            BtSdkError ret = _factory.Api.Btsdk_DeleteRemoteDeviceByHandle(bdi.Handle);

            return(ret == BtSdkError.OK);
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        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
        }
Esempio n. 4
0
        //----

        protected override IBluetoothDeviceInfo GetBluetoothDeviceInfo(BluetoothAddress address)
        {
            return(BluesoleilDeviceInfo.CreateFromGivenAddress(address, this));
        }