Ejemplo n.º 1
0
        private void SerialPorts_SerialPortRemoved(object sender, SerialPortChangedEventArgs e)
        {
            if (!IsLoaded || isConnecting)
            {
                return;
            }
            if (DevicePort != null && DevicePort.PortName == e.SerialPortID)
            {
                DevicePort.Close();
                DevicePort = null;

                GridConfigOverlay.Visibility = Visibility.Hidden;
            }
        }
Ejemplo n.º 2
0
        private void SerialPorts_SerialPortAdded(object sender, SerialPortChangedEventArgs e)
        {
            if (!IsLoaded || isConnecting || DevicePort != null)
            {
                return;
            }
            isConnecting = true;

            Thread.Sleep(100); // Allow the device to finish starting up
            DevicePort = Helpers.ConnectToDevice(e.SerialPortID);
            Thread.Sleep(100);

            if (DevicePort != null)
            {
                DeviceConfig config = Helpers.ReadDeviceConfig(DevicePort);
                if (config != null)
                {
                    LabelID.Content                     = "Device MAC Address: " + config.MACAddress;
                    TextBoxNetworkName.Text             = config.NetworkName;
                    CheckBoxIsEnterprise.IsChecked      = config.IsEnterpriseNetwork;
                    TextBoxNetworkUsername.Text         = config.NetworkUsername;
                    PasswordBoxNetworkPassword.Password = config.NetworkPassword;
                    TextBoxLoggerAddress.Text           = config.LoggerAddress;
                    TextBoxLoggerPort.Text              = config.LoggerPort.ToString();
                    SliderNetworkTimeout.Value          = config.NetworkTimeout;
                    SliderLoggerTimeout.Value           = config.LoggerTimeout;

                    LoadDeviceTime(false);

                    ButtonSave.IsEnabled         = false;
                    GridConfigOverlay.Visibility = Visibility.Visible;
                    TextBoxNetworkName.Focus();
                }
                else
                {
                    if (DevicePort != null)
                    {
                        DevicePort.Close();
                        DevicePort   = null;
                        isConnecting = false;
                    }

                    MessageBox.Show("Unable to read device configuration.");
                }
            }

            isConnecting = false;
        }