예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("You can use this program to test the BleWinrtDll.dll. Make sure your Computer has Bluetooth enabled.");

            BLE    ble      = new BLE();
            string deviceId = null;

            BLE.BLEScan scan = BLE.ScanDevices();
            scan.Found = (_deviceId, deviceName) =>
            {
                Console.WriteLine("found device with name: " + deviceName);
                if (deviceId == null && deviceName == "CynteractGlove")
                {
                    deviceId = _deviceId;
                }
            };
            scan.Finished = () =>
            {
                Console.WriteLine("scan finished");
                if (deviceId == null)
                {
                    deviceId = "-1";
                }
            };
            while (deviceId == null)
            {
                Thread.Sleep(500);
            }

            scan.Cancel();
            if (deviceId == "-1")
            {
                Console.WriteLine("no device found!");
                return;
            }

            ble.Connect(deviceId,
                        "{f6f04ffa-9a61-11e9-a2a3-2a2ae2dbcce4}",
                        new string[] { "{f6f07c3c-9a61-11e9-a2a3-2a2ae2dbcce4}",
                                       "{f6f07da4-9a61-11e9-a2a3-2a2ae2dbcce4}",
                                       "{f6f07ed0-9a61-11e9-a2a3-2a2ae2dbcce4}" });

            for (int guard = 0; guard < 2000; guard++)
            {
                BLE.ReadPackage();
                BLE.WritePackage(deviceId,
                                 "{f6f04ffa-9a61-11e9-a2a3-2a2ae2dbcce4}",
                                 "{f6f07ffc-9a61-11e9-a2a3-2a2ae2dbcce4}",
                                 new byte[] { 0, 1, 2 });
                Console.WriteLine(BLE.GetError());
                Thread.Sleep(5);
            }

            Console.WriteLine("Press enter to exit the program...");
            Console.ReadLine();
        }
예제 #2
0
    void ScanBleDevices()
    {
        scan = BLE.ScanDevices();
        Debug.Log("BLE.ScanDevices() started.");
        scan.Found = (_deviceId, deviceName) =>
        {
            Debug.Log("found device with name: " + deviceName);
            discoveredDevices.Add(_deviceId, deviceName);

            if (deviceId == null && deviceName == targetDeviceName)
            {
                deviceId = _deviceId;
            }
        };

        scan.Finished = () =>
        {
            isScanning = false;
            Debug.Log("scan finished");
            if (deviceId == null)
            {
                deviceId = "-1";
            }
        };
        while (deviceId == null)
        {
            Thread.Sleep(500);
        }
        scan.Cancel();
        scanningThread = null;
        isScanning     = false;

        if (deviceId == "-1")
        {
            Debug.Log("no device found!");
            return;
        }
    }