public bool LoadFromFile(string fname) { try { string[] lines = File.ReadAllLines(fname); this.SerialEvents.Clear(); foreach (string line in lines) { if (line.Trim() != "") { string[] items = line.Split(','); if (items.Length >= 2) { SerialEvent se = new SerialEvent() { SimEventName = items[0].Trim(), Trigger = items[1].Trim() }; this.SerialEvents.Add(se); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(false); }
/// <summary> /// Check is the serial port changed => check every 2 sec /// </summary> /// <param name="source"></param> /// <param name="e"></param> public void SerialPortPinChanged(object source, ElapsedEventArgs e) { string[] sp = GetSerialPort(); if (!sp.SequenceEqual(_serialPort)) { _serialPort = sp; SerialEvent?.Invoke(this, new EventArgs()); Console.WriteLine("changed"); } }
public Serial() { // Init serial port _serial = new SerialPort(); SerialEvent?.Invoke(this, new EventArgs()); // Init timer to handle serial port change _timerEvent = new Timer(); _serialPort = GetSerialPort(); _timerEvent.Elapsed += new ElapsedEventHandler(SerialPortPinChanged); _timerEvent.Interval = 2000; _timerEvent.Start(); }