private void btnStartConfiguration_Click(object sender, RoutedEventArgs e)
        {
            string profile = this.cbProfile.Text.Trim();

            SerialPreviousInformation portInformation     = cbCOMPorts.SelectedItem as SerialPreviousInformation;
            SerialConfiguration       serialConfiguration = new SerialConfiguration();

            serialConfiguration.ConfigBitsPerSecond = (int)cbBitsPerSecond.SelectedValue;
            serialConfiguration.ConfigDataBits      = (SerialConfiguration.EDataBits) this.cbDataBits.SelectedItem;
            serialConfiguration.ConfigParity        = (System.IO.Ports.Parity) this.cbParity.SelectedItem;
            serialConfiguration.ConfigStopBits      = (System.IO.Ports.StopBits) this.cbStopBits.SelectedItem;


            if (profile.Length > 0)
            {
                if (!this.settingsManager.CurrentSettings.Configurations.ContainsKey(profile))
                {
                    this.settingsManager.CurrentSettings.Configurations.Add(profile, serialConfiguration);
                }
                else
                {
                    this.settingsManager.CurrentSettings.Configurations[profile] = serialConfiguration;
                }
            }

            this.settingsManager.CurrentSettings.LastUsedPort       = portInformation.Port;
            this.settingsManager.CurrentSettings.DefaultPortSetting = profile;
            this.settingsManager.SaveToFile();

            TotalConfiguration configuration = new TotalConfiguration(portInformation.Port, serialConfiguration);

            ALDSerialPort serial = new ALDSerialPort(configuration);

            try
            {
                serial.OpenPort();

                WinContainer winContainer = new WinContainer(serial);

                this.Hide();
                winContainer.ShowDialog();
                this.Show();
            }
            catch
            {
                MessageBox.Show("Cannot open port.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void UpdatePorts()
        {
            string lastUsedPort = this.settingsManager.CurrentSettings.LastUsedPort;

            var res   = ALDSerialPort.EnumeratePorts();
            var ports = res.ToDictionary(x => x.Port);

            cbCOMPorts.ItemsSource = null;
            cbCOMPorts.ItemsSource = res;

            if (lastUsedPort != null && ports.ContainsKey(lastUsedPort))
            {
                cbCOMPorts.SelectedItem = ports[lastUsedPort];
            }
            else
            {
                if (res.Count > 0)
                {
                    cbCOMPorts.SelectedIndex = 0;
                }
            }
        }
Example #3
0
 public WinContainer(ALDSerialPort serial)
 {
     InitializeComponent();
     this.serial = serial;
     this.usrTabCommands.InitializeControl(serial);
 }
 public void InitializeControl(ALDSerialPort serial)
 {
     this.serial           = serial;
     serial.DataReceived  += new System.IO.Ports.SerialDataReceivedEventHandler(serial_DataReceived);
     serial.ErrorReceived += new System.IO.Ports.SerialErrorReceivedEventHandler(serial_ErrorReceived);
 }