static void Main(string[] args) { com = new SerialInterface("COM4", 9600); com.SerialDataEvent += com_SerialDataEvent; if (com.OpenPort() != 0) { Console.WriteLine("Error: {0}", com.lastError); } if (com.IsOpen) { Console.WriteLine("Port is open."); } Console.ReadKey(); }
static void comInit() { if (comPort != "" && baudRate > 0) { com = new SerialInterface(comPort, baudRate); int res = com.OpenPort(); if (res != 0) Console.WriteLine("SerialInterface Error: #" + res + "\n" + com.lastError); else com.SerialDataEvent += com_SerialDataEvent; } else { Console.WriteLine("COM Port or Baud Rate not valid."); } com.SendByte((byte)StatusByteCode.Enquiry); System.Threading.Thread.Sleep(200); }
public MainWindow() { com = new SerialInterface("COM4 ", 9600); InitializeComponent(); }
private void connectButton_Click(object sender, RoutedEventArgs e) { if (comPortComboBox.SelectedItem != null) { comPort = ((ComboBoxItem)comPortComboBox.SelectedItem).Content.ToString(); if (comPort == String.Empty) { MessageBox.Show("Geen comport geselecteerd."); return; } Serial = new SerialInterface(comPort, 115200); Serial.OpenPort(); if (Serial.IsOpen) { Serial.SerialDataEvent += Serial_SerialDataEvent; controlsFysiologieStackPanel.IsEnabled = true; connectButton.IsEnabled = false; comPortComboBox.IsEnabled = false; } else { controlsFysiologieStackPanel.IsEnabled = false; connectButton.IsEnabled = true; comPortComboBox.IsEnabled = true; } } }