Esempio n. 1
0
 public bool IsConnected(out BluetoothAddress p_remote_bdaddr)
 {
     byte[] bdaddr = new byte[WidcommStructs.BD_ADDR_LEN];
     WidcommL2CapClient.NativeMethods.L2CapConn_GetRemoteBdAddr(m_pPort, bdaddr, bdaddr.Length);
     p_remote_bdaddr = WidcommUtils.ToBluetoothAddress(bdaddr);
     return(true);
 }
Esempio n. 2
0
        public bool IsConnected(out BluetoothAddress p_remote_bdaddr)
        {
            byte[] bdaddr = new byte[WidcommStructs.BD_ADDR_LEN];
            bool   ret    = NativeMethods.RfcommPort_IsConnected(m_pRfcommPort, bdaddr, bdaddr.Length);

            p_remote_bdaddr = WidcommUtils.ToBluetoothAddress(bdaddr);
            return(ret);
        }
Esempio n. 3
0
        public DISCOVERY_RESULT GetLastDiscoveryResult(out BluetoothAddress address, out UInt16 p_num_recs)
        {
            byte[]           bdaddr = WidcommUtils.FromBluetoothAddress(BluetoothAddress.None);
            DISCOVERY_RESULT ret    = NativeMethods.BtIf_GetLastDiscoveryResult(m_pBtIf, bdaddr, out p_num_recs);

            address = WidcommUtils.ToBluetoothAddress(bdaddr);
            return(ret);
        }
Esempio n. 4
0
        //----

        internal string CreatePort(BluetoothAddress addr)
        {
            if (IsSet(_waitConnect))
            {
                throw new InvalidOperationException("Already used.");
            }
            _addr = addr;
            byte[] bd_addr           = WidcommUtils.FromBluetoothAddress(addr);
            byte[] tcharzServiceName = { 0, 0 };
            var    inUse             = Interlocked.CompareExchange(ref _sfInConnect, 1, 0);

            if (inUse != 0)
            {
                throw new InvalidOperationException("Widcomm only allows one SPP Connect attempt at a time.");
            }
            SPP_CLIENT_RETURN_CODE ret = (SPP_CLIENT_RETURN_CODE)(-1);

            _singleThreader.AddCommand(new WidcommPortSingleThreader.MiscNoReturnCommand(
                                           () => ret = NativeMethods.SppClient_CreateConnection(
                                               _pSppCli, bd_addr, tcharzServiceName)
                                           )).WaitCompletion();
            Debug.WriteLine("SppClient_CreateConnection ret: " + ret);
            int  timeout   = 30000;
            bool signalled = _waitConnect.WaitOne(timeout, false);

            // Eeek want to set this even when we got NO callback........
            // Do for now because Win32 is not working at all......
            Interlocked.Exchange(ref _sfInConnect, 0);
            if (!signalled)
            {
                throw CommonSocketExceptions.Create_NoResultCode(
                          WidcommSppSocketExceptions.SocketError_Misc,
                          "CreatePort failed (time-out).");
            }
            MemoryBarrier();
            if (_statusState != SPP_STATE_CODE.CONNECTED)
            {
                throw WidcommSppSocketExceptions.Create(_statusState, "CreatePort");
            }
            if (_statusComPort == null)
            {
                throw CommonSocketExceptions.Create_NoResultCode(
                          WidcommSppSocketExceptions.SocketError_Misc,
                          "CreatePort did not complete (cpn).");
            }
            //
            // TODO Move these into the native-event handler.
            //string comPort = MakePortName(_statusComPort.Value);
            //_comNum = _statusComPort.Value;
            //_comPortName = comPort;
            Debug.Assert(_comPortName != null, "_comPortName IS null");
            Debug.Assert(WidcommUtils.ToBluetoothAddress(_statusBda) == addr,
                         "addr NOT equal, is: " + WidcommUtils.ToBluetoothAddress(_statusBda));
            return(_comPortName);
        }