Example #1
0
        private async void RunTask(TaskName taskName, string arg1, string arg2, Action <ERROR_CODE> callback)
        {
            // 비동기로 Worker Thread에서 도는 task1
            // Task.Run(): .NET Framework 4.5+
            ERROR_CODE result = ERROR_CODE.NONE;

            switch (taskName)
            {
            case TaskName.OPEN_DEVICE:
                result = await ble.OpenDevice(arg1);

                listStatus.Items.Add($"ErrorCode: {result}");
                break;

            case TaskName.SET_SERVICE:
                //task1 = Task.Run(() => bleservice.SetService(deviceName));
                //result = await task1;
                result = await ble.SetService(arg2);

                listStatus.Items.Add($"ErrorCode: {result}");
                break;

            case TaskName.READ_CHARACTERISTIC:
                result = await ble.ReadCharacteristic(arg1, arg2);

                listStatus.Items.Add($"ErrorCode: {result}");
                if (result == ERROR_CODE.NONE)
                {
                    var readstring = ble.getCharacteristic();
                    listStatus.Items.Add($"Result: {readstring}");
                }
                break;
            }
            callback(result);
        }
Example #2
0
        private async void button16_Click_1(object sender, EventArgs e)
        {
            string parameters = textBox3.Text.ToString();

            listDevice.Items.Clear();
            listStatus.Items.Add("Start Scan");

            // var result = ble2.StartScan(parameters, (d) => listStatus.Items.Add(d));
            var result = ble2.StartScan(parameters, (d) => { });

            listStatus.Items.Add(result.ToString());
            if (result.Equals(ERROR_CODE.BLE_FOUND_DEVICE))
            {
                var error_code = await ble2.OpenDevice(parameters);

                listStatus.Items.Add($"Connection Result: {error_code}");
            }
        }