Esempio n. 1
0
        private void Button_ConnectClick(object sender, RoutedEventArgs e)
        {
            if (SerialPort.SelectedItem == null)
            {
                StatusMessage = "Select COM port!";
                return;
            }

            if (SerialSpeed.SelectedItem == null)
            {
                StatusMessage = "Select COM baudrate";
                return;
            }

            if (!_sikInterface.Connect((string)SerialPort.SelectedItem, (int)SerialSpeed.SelectedItem))
            {
                StatusMessage = "Failed to open the COM port.";
                return;
            }

            // We are connected now. Update tab
            var parent = FindParent <TabControl>(sender as Button);

            if (parent != null)
            {
                var tab = parent.Items[0] as TabItem;
                if (tab != null)
                {
                    tab.Header = $"{SerialPort.SelectedItem}({SerialSpeed.SelectedItem})";
                }
            }

            // Are we in the command mode already?
            var in_command = _sikInterface.CheckCommandMode();

            if (!in_command)
            {
                if (!_sikInterface.EnterCommandMode())
                {
                    StatusMessage = "Failed to enter the command mode.";
                    return;
                }
            }

            StatusMessage = "Connected!";
            _sikInterface.ReadIdentificationData();
        }
Esempio n. 2
0
        private void BtnConnect_Click(object sender, EventArgs e)
        {
            var port = _portNameCombo.ActiveText;

            if (port == null || port == "<refresh>")
            {
                StatusMessage = "Select Serial port!";
                return;
            }

            var baud_str = _baudRateCombo.ActiveText;

            if (baud_str == null)
            {
                StatusMessage = "Select Baud rate";
                return;
            }

            int baud;

            if (!int.TryParse(baud_str, out baud))
            {
                StatusMessage = "Failure parsing Baud rate";
                return;
            }

            if (!_sikInterface.Connect(port, baud))
            {
                StatusMessage = "Failed to open the COM port.";
                return;
            }

            // Are we in the command mode already?
            if (!_sikInterface.CheckCommandMode())
            {
                if (!_sikInterface.EnterCommandMode())
                {
                    StatusMessage = "Failed to enter the command mode.";
                    return;
                }
            }

            _pageLabel.Text = $"{port}({baud})";
            StatusMessage   = "Connected!";
            _sikInterface.ReadIdentificationData();
        }