Пример #1
0
        private async Task <string> BleGetCharacteristic(DeviceList idx, string devName, string characterName)
        {
            string resultString = "";

            try
            {
                var parts = characterName.Split('/');
                switch (idx)
                {
                case DeviceList.BLE1:
                    resultString = await ble1.ReadCharacteristic(devName, characterName);

                    if (resultString.StartsWith("ERROR_CODE.NONE"))
                    {
                        var resultData = ConvertUnit(parts[1], resultString);
                        showmessage(idx, $"{parts[1]}: {resultData}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}: {resultString}");
                    }
                    break;

                case DeviceList.BLE2:
                    resultString = await ble2.ReadCharacteristic(devName, characterName);

                    if (resultString.StartsWith("ERROR_CODE.NONE"))
                    {
                        var resultData = ConvertUnit(parts[1], resultString);
                        showmessage(idx, $"{parts[1]}: {resultData}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}: {resultString}");
                    }
                    break;

                case DeviceList.BLE3:
                    resultString = await ble3.ReadCharacteristic(devName, characterName);

                    if (resultString.StartsWith("ERROR_CODE.NONE"))
                    {
                        var resultData = ConvertUnit(parts[1], resultString);
                        showmessage(idx, $"{parts[1]}: {resultData}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}: {resultString}");
                    }
                    break;

                case DeviceList.BLE4:
                    resultString = await ble4.ReadCharacteristic(devName, characterName);

                    if (resultString.StartsWith("ERROR_CODE.NONE"))
                    {
                        var resultData = ConvertUnit(parts[1], resultString);
                        showmessage(idx, $"{parts[1]}: {resultData}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}: {resultString}");
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                resultString = "ERROR_CODE." + ERROR_CODE.READ_EXCEPTION_1.ToString();
                Console.WriteLine($"Read Exception");
            }
            return(resultString);
        }
Пример #2
0
        private async Task <ERROR_CODE> BleGetCharacteristic(DeviceList idx, string devName, string characterName)
        {
            ERROR_CODE result = ERROR_CODE.NONE;

            try
            {
                var parts = characterName.Split('/');
                switch (idx)
                {
                case DeviceList.BLE1:
                    result = await ble1.ReadCharacteristic(devName, characterName);

                    if (result == ERROR_CODE.NONE)
                    {
                        showmessage(idx, $"{parts[1]}: {ble1.getCharacteristic()}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}:ErrorCode: {result}");
                    }
                    break;

                case DeviceList.BLE2:
                    result = await ble2.ReadCharacteristic(devName, characterName);

                    if (result == ERROR_CODE.NONE)
                    {
                        showmessage(idx, $"{parts[1]}: {ble2.getCharacteristic()}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}:ErrorCode: {result}");
                    }
                    break;

                case DeviceList.BLE3:
                    result = await ble3.ReadCharacteristic(devName, characterName);

                    if (result == ERROR_CODE.NONE)
                    {
                        showmessage(idx, $"{parts[1]}: {ble3.getCharacteristic()}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}:ErrorCode: {result}");
                    }
                    break;

                case DeviceList.BLE4:
                    result = await ble4.ReadCharacteristic(devName, characterName);

                    if (result == ERROR_CODE.NONE)
                    {
                        showmessage(idx, $"{parts[1]}: {ble4.getCharacteristic()}");
                    }
                    else
                    {
                        showmessage(idx, $"{parts[1]}:ErrorCode: {result}");
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                result = ERROR_CODE.READ_EXCEPTION_1;
                Console.WriteLine($"Read Exception");
            }
            return(result);
        }