コード例 #1
0
        public void RefreshActiveSerialNexstarDevices()
        {
            _logger.LogInformation("Clearing old devices.");
            ActiveNexStarDevicePortNames.Clear();

            _logger.LogInformation("Starting probe for NexStar devices.");

            string[] portNames = SerialPort.GetPortNames();
            foreach (string portName in portNames)
            {
                SerialPortController testController        = new SerialPortController(portName);
                VersionCommand       versionCommandCommand = new VersionCommand();
                try
                {
                    testController.RunCommand(versionCommandCommand);

                    if (versionCommandCommand.RawResultBytes != null)
                    {
                        ActiveNexStarDevicePortNames.Add(portName);
                        _logger.LogInformation($"NexStar device found on port '{portName}'.");
                    }
                }
                catch (TimeoutException)
                {
                    _logger.LogInformation($"Probe timeout for port '{portName}'.");
                    //ignore timeouts here, we are expecting some devices to not respond.
                }
                finally
                {
                    testController.CloseSerialConnection();
                }
            }

            _logger.LogInformation($"Probe finished found {ActiveNexStarDevicePortNames.Count} devices.");
        }
コード例 #2
0
        public Guid CreateConnectionForAddress(string serialComAddress)
        {
            if (!ActiveNexStarDevicePortNames.Contains(serialComAddress))
            {
                throw new ArgumentException("The port address identified is not a nexstar device. Ensure that you have run RefreshActiveSerialNexstarDevices() before starting a connection.");
            }

            var identifier = Guid.NewGuid();

            Connections.Add(identifier, new NexStarConnection(serialComAddress));
            return(identifier);
        }