private void OnPinChanged(object sender, SerialPinChangedEventArgs e) { if (null == e) { return; } try { switch (e.EventType) { case SerialPinChange.CtsChanged: _loggingAction.Fire(); break; case SerialPinChange.CDChanged: if (!_serialPort.CDHolding) { ClosePort(); } break; default: break; } } catch (UnauthorizedAccessException ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Warning, Message = string.Format("{0}: Device disconnected: {1}", DateTime.Now, ex.Message) }); ClosePort(); } }
private void GetMonths() { if (File.Exists(FullPath)) { string[] lines; lock (_fileLock) { lines = File.ReadAllLines(FullPath); } List <string> monthLines = new List <string>(); foreach (string line in lines) { monthLines.Add(line); if (line == "</TimeLog>") { try { Months.Add(MonthData.FromLines(monthLines)); } catch (Exception ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Error, Message = ex.Message }); } monthLines.Clear(); } } int monthcount = Months.Count; } }
internal void PollCTS() { if (_serialPort.IsOpen) { try { CTSSwitch?.Invoke(this, new CTSSwitchEventArgs() { CTSHolding = _serialPort.CtsHolding }); } catch (UnauthorizedAccessException ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Warning, Message = string.Format("{0}: Device disconnected: {1}", DateTime.Now, ex.Message) }); ClosePort(); } } else { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Warning, Message = string.Format("{0}: Poll: Serial Port not open.", DateTime.Now) }); } }
private void OnError(object sender, SerialErrorReceivedEventArgs e) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Error, Message = string.Format("Serial error: {0}", e.EventType.ToString()) }); ClosePort(); }
private void ClosePort() { _serialPort.Close(); LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Info, Message = string.Format("{0} closed.", SelectedPort) }); SelectedPort = EmptyPort; }
internal void OnCtsSwitch(object sender, CTSSwitchEventArgs args) { if (false == args.CTSHolding) { try { AddStamp(args.Time); } catch (Exception ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Error, Message = ex.Message }); } } }
private void OpenPort() { try { _serialPort.Open(); LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Info, Message = string.Format("{0} open for listening.", SelectedPort) }); } catch (Exception ex) { LogMessageAvailable?.Invoke(this, new LogMessage() { MessageSeverity = LogMessage.Severity.Info, Message = string.Format("Unable to open {0} for listening: {1}", SelectedPort, ex.Message) }); } }
internal void OnLogMessageAvailable(string message) { LogMessageAvailable?.Invoke(this, new StringEventArgs(message)); }
private void OnLogMessageAvailable(object sender, StringEventArgs e) { LogMessageAvailable?.Invoke(this, new StringEventArgs(e.EventText)); }