当前位置: 首页>>代码示例>>C#>>正文


C# Sockets.BluetoothClient类代码示例

本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient类的具体用法?C# BluetoothClient怎么用?C# BluetoothClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BluetoothClient类属于InTheHand.Net.Sockets命名空间,在下文中一共展示了BluetoothClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: connectToDeviceWithoutPairing

        /// <summary>
        /// Attempt to connect to the BluetoothDevice, without trying to pair first.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static async Task<Boolean> connectToDeviceWithoutPairing(BluetoothDevice device) {
            BluetoothEndPoint endPoint = new BluetoothEndPoint(device.btDeviceInfo.DeviceAddress, BluetoothService.SerialPort);
            BluetoothClient client = new BluetoothClient();
            if (!device.Authenticated) {
                return false;
            }
            else {
                try {
                    client.Connect(endPoint);

                    if (devicesStreams.Keys.Contains(device)) {
                        devicesStreams.Remove(device);
                    }
                    devicesStreams.Add(device, client.GetStream());

                    if (devicesClients.Keys.Contains(device)) {
                        devicesClients.Remove(device);
                    }
                    devicesClients.Add(device, client);
                }
                catch (Exception ex) {
                    //System.Console.Write("Could not connect to device: " + device.DeviceName + " " + device.DeviceAddress);
                    return false;
                }
                return true;
            }
        }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:32,代码来源:Bluetooth.cs

示例2: Arastirma

 public Arastirma(AnaPencere pencere)
 {
     anaPencere = pencere;
     localAygit = new BluetoothClient(); // Local bluetooth aygýtýna eriþiyoruz.
     aramaKanali = new Thread(new ThreadStart(AygitArama)); // Araþtýrma için iþ parçasý oluþtur.
     aramaKanali.Start(); // Ýþ parçasýný baþlat.
 }
开发者ID:ugurcicekfidan,项目名称:VisualStudioWorks,代码行数:7,代码来源:Arastirma.cs

示例3: readInfoClient

        public void readInfoClient()
        {
            bluetoothClient = bluetoothListener.AcceptBluetoothClient();
                    Console.WriteLine("Cliente Conectado!");

            Stream stream = bluetoothClient.GetStream();

            while (bluetoothClient.Connected)
                    {
                        try
                        {
                            byte[] byteReceived = new byte[1024];
                                int read = stream.Read(byteReceived, 0, byteReceived.Length);
                                if (read > 0)
                                {
                                    Console.WriteLine("Messagem Recebida: " + Encoding.ASCII.GetString(byteReceived) + System.Environment.NewLine);
                                }
                                stream.Flush();
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("Erro: " + e.ToString());
                        }
                    }
                    stream.Close();
        }
开发者ID:lucasmlima08,项目名称:ConnectionBluetoothDesktop,代码行数:26,代码来源:Server.cs

示例4: ServerConnectThread

        public void ServerConnectThread()
        {
            updateUI("Server started, waiting for client");
            bluetoothListener = new BluetoothListener(mUUID);
            bluetoothListener.Start();
            conn = bluetoothListener.AcceptBluetoothClient();

            updateUI("Client has connected");
            connected = true;

            //Stream mStream = conn.GetStream();
            mStream = conn.GetStream();

            while (connected)
            {
                try
                {
                    byte[] received = new byte[1024];
                    mStream.Read(received, 0, received.Length);
                    string receivedString = Encoding.ASCII.GetString(received);
                    //updateUI("Received: " + receivedString);
                    handleBluetoothInput(receivedString);
                    //byte[] send = Encoding.ASCII.GetBytes("Hello world");
                    //mStream.Write(send, 0, send.Length);
                }
                catch (IOException e)
                {
                    connected = false;
                    updateUI("Client disconnected");
                    disconnectBluetooth();
                }
            }
        }
开发者ID:CGHill,项目名称:Random-Projects,代码行数:33,代码来源:Form1.cs

示例5: connect

		public override void connect ()
		{
			if (connection == null)
			{
                connection = new BluetoothClient();
			}
			if (connection.Connected)
			{
                throw new Exception("Connection is already opened");
			}
			connection.Connect (new BluetoothAddress(bluetoothAddress), OtherData.upsBluetoothGuid);
            connectedDeviceInfo = new BluetoothDeviceInfo(connection.RemoteEndPoint.Address);
            bluetoothAddress = connection.RemoteEndPoint.Address.ToInt64();

            socket = connection.Client;
            socketReciveOperation = new SocketAsyncEventArgs();
            socketReciveOperation.UserToken = socket;
            socketReciveOperation.RemoteEndPoint = socket.RemoteEndPoint;
            socketReciveOperation.Completed += new EventHandler<SocketAsyncEventArgs>(onReciveComplete);

            socketSendOperation = new SocketAsyncEventArgs();
            socketSendOperation.UserToken = socket;
            socketSendOperation.RemoteEndPoint = socket.RemoteEndPoint;
            socketSendOperation.Completed += new EventHandler<SocketAsyncEventArgs>(onSendComplete);
            
            WinBluetoothFactory.getFactory().addConnectedDevice(this);
		}
开发者ID:Deremius,项目名称:Uraban-Phase-Space,代码行数:27,代码来源:WinBluetoothConnection.cs

示例6: GetImages

        public static void GetImages(BluetoothEndPoint endpoint, Color tagColor)
        {
            InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
            btc.Connect(endpoint);
            var nws = btc.GetStream();
            byte[] emptySize = BitConverter.GetBytes(0); //
            if (BitConverter.IsLittleEndian) Array.Reverse(emptySize); // redundant but usefull in case the number changes later..
            nws.Write(emptySize, 0, emptySize.Length); // write image size
            int imgCount = GetImgSize(nws);
            nws = btc.GetStream();
            for (int i = 0; i < imgCount; i++)
            {
                MemoryStream ms = new MemoryStream();
                int size = GetImgSize(nws);
                if (size == 0) continue;
                byte[] buffer = new byte[size];
                int read = 0;

                while ((read = nws.Read(buffer, 0, buffer.Length)) != 0)
                {
                    ms.Write(buffer, 0, read);
                }
                SurfaceWindow1.AddImage(System.Drawing.Image.FromStream(ms), tagColor);
            }
        }
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:25,代码来源:BluetoothHandler.cs

示例7: GetNearbyRemoteAddresses

 public static List<string> GetNearbyRemoteAddresses(TimeSpan timeout)
 {
     List<string> result = new List<string>();
     try
     {
         BluetoothClient cli = new BluetoothClient();
         if (timeout != TimeSpan.Zero) cli.InquiryLength = timeout;
         BluetoothDeviceInfo[] devs = cli.DiscoverDevices();
         foreach (BluetoothDeviceInfo dev in devs)
         {
             if (dev.DeviceName.ToLower().Contains("bd remote control"))
             {
                 if (RemoteBtState(null, dev) == RemoteBtStates.Awake)
                 {
                     string candidate = FormatBtAddress(null, dev.DeviceAddress, "N");
                     if (!result.Contains(candidate)) result.Add(candidate);
                 }
             }
         }
     }
     catch
     {
         DebugLog.write("BTUtils.GetNearbyRemoteAddresses Failed");
     }
     return result;
 }
开发者ID:ArmyOfPirates,项目名称:PS3BluMote,代码行数:26,代码来源:BTUtils.cs

示例8: findBluetoothTolist

 public void findBluetoothTolist()
 {
     BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
     BluetoothClient bluetoothClient = new BluetoothClient();
     BluetoothDeviceInfo[] bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
     ArrayList deviceCollection = new ArrayList();
     foreach (BluetoothDeviceInfo device_info in bluetoothDeviceInfo)
     {
         string device_name = device_info.DeviceName;
         string device_address = device_info.DeviceAddress.ToString();
         BluetoothDeviceManager manager = new BluetoothDeviceManager(device_name,device_address);
         deviceCollection.Add(manager);
     }
     System.Management.ManagementObjectSearcher Searcher = new System.Management.ManagementObjectSearcher("Select * from WIN32_SerialPort");
     foreach (System.Management.ManagementObject Port in Searcher.Get())
     {
         string PNPDeviceID = Port.GetPropertyValue("PNPDeviceID").ToString();
         string DeviceID = Port.GetPropertyValue("DeviceID").ToString();
         for (int i = 0; i < deviceCollection.Count; i++)
         {
             BluetoothDeviceManager manager = (BluetoothDeviceManager)deviceCollection[i];
             string device_address = manager.getDeviceAddress();
             int index = PNPDeviceID.IndexOf(device_address);
             if (index > 0)
             {
                 manager.addCOM(DeviceID);
                 bluetoothList.Add(manager);
             }
         }
     }
 }
开发者ID:sh932111,项目名称:BrainProject,代码行数:31,代码来源:BlueController.cs

示例9: BluetoothConnection

        /// <summary>
        /// Bluetooth connection constructor
        /// </summary>
        private BluetoothConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, BluetoothClient btClient)
            : base(connectionInfo, defaultSendReceiveOptions)
        {
            if (btClient != null)
                this.btClient = btClient;

            dataBuffer = new byte[NetworkComms.InitialReceiveBufferSizeBytes];
        }
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:11,代码来源:BluetoothConnection.cs

示例10: Disconnect

        public void Disconnect()
        {
            _client.Close();
              _client = new BluetoothClient();

              _readerThread = null;
              _reader = null;
              _writer = null;
        }
开发者ID:Grodien,项目名称:HsluRobot,代码行数:9,代码来源:BluetoothConnector.cs

示例11: WinBluetoothConnection

		public WinBluetoothConnection()
		{
			connectedDeviceInfo = null;
			connection = new BluetoothClient();
			bluetoothAddress = 0;

            socketIsReadyToNewRecive = true;
            socketIsReadyToNewSend = true;
		}
开发者ID:Deremius,项目名称:Uraban-Phase-Space,代码行数:9,代码来源:WinBluetoothConnection.cs

示例12: GetAvailableSpheroNames

        public string[] GetAvailableSpheroNames()
        {
            Reset();

            _client = new BluetoothClient();
            _peers = _client.DiscoverDevices();
            var spheros = _peers.Where(x => x.DeviceName.StartsWith("Sphero")).Select(x => x.DeviceName).ToArray();
            return spheros;
        }
开发者ID:slodge,项目名称:BallControl,代码行数:9,代码来源:Singleton.cs

示例13: Initialize

        private void Initialize()
        {
            client = new BluetoothClient();
            devices = client.DiscoverDevices(10, true, true, false);

            deviceList.Items.Clear();
            foreach (BluetoothDeviceInfo device in devices)
            {
                deviceList.Items.Add(device.DeviceName);
            }
        }
开发者ID:tewarid,项目名称:NetTools,代码行数:11,代码来源:MainForm.cs

示例14: DetectPebbles

        public static IList<Pebble> DetectPebbles()
        {
            var client = new BluetoothClient();

            // A list of all BT devices that are paired, in range, and named "Pebble *" 
            var bluetoothDevices = client.DiscoverDevices( 20, true, false, false ).
                Where( bdi => bdi.DeviceName.StartsWith( "Pebble " ) ).ToList();

            return ( from device in bluetoothDevices
                     select (Pebble)new PebbleNet45( new PebbleBluetoothConnection( device ),
                         device.DeviceName.Substring( 7 ) ) ).ToList();
        }
开发者ID:mubold,项目名称:PebbleSharp,代码行数:12,代码来源:PebbleNet45.cs

示例15: SendBluetooth

 public static void SendBluetooth(BluetoothEndPoint endpoint, BitmapSource bms)
 {
     InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
     btc.Connect(endpoint);
     byte[] img = BmSourceToByteArr(bms);
     var nws = btc.GetStream();
     byte[] imgSize = BitConverter.GetBytes(img.Length);
     if (BitConverter.IsLittleEndian) Array.Reverse(imgSize);
     nws.Write(imgSize, 0, imgSize.Length); // write image size
     nws.Write(img, 0, img.Length); // Write image
     nws.Flush();
 }
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:12,代码来源:BluetoothHandler.cs


注:本文中的InTheHand.Net.Sockets.BluetoothClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。