コード例 #1
0
        private void OnConnectButtonClick(object sender, EventArgs e)
        {
            try
            {
                var selectedItem = comPortComboBox.SelectedItem;
                if (selectedItem == null)
                {
                    MessageBox.Show(Resources.NoComPortSelected);
                    return;
                }

                ChangeInteractionState(false);
                var configurator = SerialConfigurator.GetInstance(selectedItem.ToString(), 57600, saveLogCheckBox.Checked);
                _controllerBase = new ThinkGearController();
                _controllerBase.DataReceived += OnThinkGearDataReceived;
                if (_controllerBase.Connect(configurator))
                {
                    return;
                }
                MessageBox.Show(Resources.ConnectionFailureMessage);
                ChangeInteractionState(true);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                ChangeInteractionState(true);
            }
        }
コード例 #2
0
 public override bool Connect(SerialConfigurator configurator)
 {
     try
     {
         _serialPort = new SerialPort(configurator.ComPort, configurator.BaudRate, Parity.Even);
         _serialPort.DataReceived += (sender, args) => DataReceived(sender, args);
         _serialPort.Open();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
コード例 #3
0
        private void OnArduinoConnectClick(object sender, EventArgs e)
        {
            var selectedItem = arduinoPortsComboBox.SelectedItem;

            if (selectedItem == null)
            {
                MessageBox.Show(Resources.NoComPortSelected);
                return;
            }

            ChangeInteractionState(false);
            var configurator = SerialConfigurator.GetInstance(selectedItem.ToString(), 9600, saveLogCheckBox.Checked);

            _controllerBase = new ArduinoController();
            _controllerBase.DataReceived += OnThinkGearDataReceived;
            if (_controllerBase.Connect(configurator))
            {
                return;
            }
            MessageBox.Show(Resources.ConnectionFailureMessage);
            ChangeInteractionState(true);
        }
コード例 #4
0
 public override bool Connect(SerialConfigurator configurator)
 {
     return(_gearWrapper.Connect(configurator.ComPort, configurator.BaudRate, true, configurator.SaveLog));
 }
コード例 #5
0
 public abstract bool Connect(SerialConfigurator configurator);