private void ComPortBox_Closed(object sender, EventArgs e) { if (ComPortBox.SelectedItem == null) { return; } Settings.Com = ComPortBox.SelectedItem.ToString(); ComPort.InitComPort(Settings.Com, Settings.BaudRate); }
private void MainWindow_Closing(object sender, RoutedEventArgs args) //действия при закрытии приложения через меню { if (MessageBoxResult.No == MessageBox.Show("Вы действительно хотите закрыть программу?", "Закрытие клиента", MessageBoxButton.YesNo, MessageBoxImage.Warning)) { return; } ComPort.Close(); App.Current.Shutdown(); }
private void BaudrateComboBox_DropDownClosed(object sender, EventArgs e) { if (BaudrateComboBox.SelectedItem == null) { return; } Settings.BaudRate = Convert.ToInt32(BaudrateComboBox.SelectedItem); ComPort.InitComPort(Settings.Com, Settings.BaudRate); }
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) //действия при закрытии приложения { if (MessageBoxResult.No == MessageBox.Show("Вы действительно хотите закрыть программу?", "Закрытие клиента", MessageBoxButton.YesNo, MessageBoxImage.Warning)) { e.Cancel = true; return; } ComPort.Close(); App.Current.Shutdown(); }
private void ComPortBox_Opened(object sender, EventArgs e) { ComPortBox.Items.Clear(); ComPortBox.SelectedItem = ComPort.CurrentPort; foreach (string s in ComPort.GetPorts()) { ComPortBox.Items.Add($"{s}"); } }
public MainWindow() { InitializeComponent(); Closing += MainWindow_Closing; #region COM_INIT and COM_EVENTS ComPort.NewDataRecived += rdata => WriteLog(rdata, true); ComPort.NewDataRecived += rdata => Manager(rdata); ComPort.NewDataTransfered += tdata => WriteLog(tdata, false); ComPortBox.Items.Add(Settings.Com); ComPortBox.SelectedIndex = 0; ComPort.InitComPort(Settings.Com, Settings.BaudRate); #endregion #region SendTimerInit System.Windows.Threading.DispatcherTimer interrogatorTimer = new System.Windows.Threading.DispatcherTimer(); interrogatorTimer.Tick += new EventHandler(DataTransferTimer_Tick); interrogatorTimer.Interval = new TimeSpan(0, 0, 0, 0, 250); //инит таймера отправки: дни; часы; минуты; секунды; милсек. interrogatorTimer.Start(); #endregion }
private void SendButton_Click(object sender, RoutedEventArgs e) { //ComPort.Write(WriteBox.Text); byte[] X = { 0xAB, 0x10 }; ComPort.Write(X); }
public static void Trash_off() => ComPort.Write(new byte[] { 0xAB, 0x10 });
public static void State_electrometer() => ComPort.Write(new byte[] { 0xAB, 0x05 });
public static void State_full() => ComPort.Write(new byte[] { 0xAB, 0x07 });
public static void State_pressure() => ComPort.Write(new byte[] { 0xAB, 0x06 });
public static void State_valve() => ComPort.Write(new byte[] { 0xAB, 0x03 });