Пример #1
0
        private async void EnumerateSerialDevices()
        {
            _cdDeviceId = null;
            _crDeviceId = null;
            _tsDeviceId = null;

            DeviceInformationCollection deviceinfos = await DeviceInformation.FindAllAsync(SerialDevice.GetDeviceSelector());

            foreach (DeviceInformation deviceinfo in deviceinfos)
            {
                Log($"Serial device ID={deviceinfo.Id}");

                if (await _cdDevice.IsDeviceOnPort(deviceinfo.Id))
                {
                    _cdDeviceId = deviceinfo.Id;
                    _logger.Log("cdDevice TRUE", LoggingLevel.Information);
                }
                else
                {
                    _logger.Log("cdDevice FALSE", LoggingLevel.Information);
                }

                if (await _crDevice.IsDeviceOnPort(deviceinfo.Id))
                {
                    _crDeviceId = deviceinfo.Id;
                    _logger.Log("crDevice TRUE", LoggingLevel.Information);
                }
                else
                {
                    _logger.Log("crDevice FALSE", LoggingLevel.Information);
                }

                if (await _tsDevice.IsDeviceOnPort(deviceinfo.Id))
                {
                    _tsDeviceId = deviceinfo.Id;
                    _logger.Log("tsDevice TRUE", LoggingLevel.Information);
                }
                else
                {
                    _logger.Log("tsDevice FALSE", LoggingLevel.Information);
                }
            }

            _ = Dispatcher.RunAsync(CoreDispatcherPriority.Low, ConnectSerialDevices);
        }