예제 #1
0
        private async Task <ERROR_CODE> BleConnect(DeviceList idx, string devName)
        {
            ERROR_CODE result = ERROR_CODE.NONE;

            switch (idx)
            {
            case DeviceList.BLE1:
                result = ble1.StartScan(devName, (d) => { });
                showmessage1(result.ToString());
                if (result.Equals(ERROR_CODE.BLE_FOUND_DEVICE))
                {
                    result = await ble1.OpenDevice(devName);

                    showmessage1($"Connection Result: {result}");
                }
                ;
                break;

            case DeviceList.BLE2:
                result = ble2.StartScan(devName, (d) => { });
                showmessage2(result.ToString());
                if (result.Equals(ERROR_CODE.BLE_FOUND_DEVICE))
                {
                    result = await ble2.OpenDevice(devName);

                    showmessage2($"Connection Result: {result}");
                }
                ;
                break;

            case DeviceList.BLE3:
                result = ble3.StartScan(devName, (d) => { });
                showmessage3(result.ToString());
                if (result.Equals(ERROR_CODE.BLE_FOUND_DEVICE))
                {
                    result = await ble3.OpenDevice(devName);

                    showmessage3($"Connection Result: {result}");
                }
                ;
                break;

            case DeviceList.BLE4:
                result = ble4.StartScan(devName, (d) => { });
                showmessage4(result.ToString());
                if (result.Equals(ERROR_CODE.BLE_FOUND_DEVICE))
                {
                    result = await ble4.OpenDevice(devName);

                    showmessage4($"Connection Result: {result}");
                }
                ;
                break;
            }
            return(result);
        }
예제 #2
0
        private async void buttonScan_Click(object sender, EventArgs e)
        {
            Bleservice ble0 = new Bleservice();

            listDevice.Items.Clear();
            listDevice.Items.Add("Waitting...");
            ble0.StartScan();
            await Task.Delay(Int32.Parse(textScanTime.Text) * 1000);

            var result = ble0.GetDeviceList();

            listDevice.Items.Clear();
            for (int i = 0; i < result.Count(); i++)
            {
                listDevice.Items.Add($"{result[i]}");
            }
        }