private bool OpenPort() { if (comboPortName.SelectedIndex == -1 || string.IsNullOrEmpty(comboPortName.Items[comboPortName.SelectedIndex].ToString())) { comboPortName.Focus(); comboPortName.IsDropDownOpen = true; return(false); } try { port = new SerialPort(comboPortName.Items[comboPortName.SelectedIndex].ToString(), 115200); control = new UARTController(port); motion = new Motions(control); port.NewLine = "\r\n"; port.Open(); Application.Current.Dispatcher.BeginInvoke((Action) delegate() { motion.BaseBody(); }); return(true); } catch (Exception e) { return(false); } }
public MainWindow() { InitializeComponent(); model = MainViewModel.GetInstance(); //------- plz remove it if real sutiation --------// control = new UARTController(new SerialPort(), true); motion = new Motions(control); //------------------------------------------------// joy = new JoystickController(JoyEventFireMode.Toggle); joy.OnKey += Joy_OnKey; joy.StartPulling(); IsConnected = false; btConnect.Content = "Connect"; }