public BufferedSerialConn(SerialConn conn) : base(conn.OutputFilepath, conn.AppendOutputFile) { m_conn = conn; m_buf = new byte[BufBlockSize]; m_port = new SerialPort(m_conn.CommPort, m_conn.BaudRate, m_conn.Parity, m_conn.DataBits, m_conn.StopBits) { Handshake = m_conn.FlowControl, DtrEnable = m_conn.DtrEnable, RtsEnable = m_conn.RtsEnable }; }
public SerialConn(SerialConn rhs) { CommPort = rhs.CommPort; BaudRate = rhs.BaudRate; DataBits = rhs.DataBits; Parity = rhs.Parity; StopBits = rhs.StopBits; FlowControl = rhs.FlowControl; DtrEnable = rhs.DtrEnable; RtsEnable = rhs.RtsEnable; OutputFilepath = rhs.OutputFilepath; AppendOutputFile = rhs.AppendOutputFile; }
/// <summary>Open a serial port connection and log anything read</summary> private void LogSerialConnection(SerialConn conn) { BufferedSerialConn buffered_serialconn = null; try { // Close any currently open file // Strictly, we don't have to close because OpenLogFile closes before opening // however if the user reopens the same connection the existing connection will // hold a lock on the capture file preventing the new connection being created. Src = null; // Set options so that data always shows PrepareForStreamedData(conn.OutputFilepath); // Launch the process with standard output/error redirected to the temporary file buffered_serialconn = new BufferedSerialConn(conn); // Give some UI feedback if the connection drops buffered_serialconn.ConnectionDropped += (s, a) => { this.BeginInvoke(() => SetStaticStatusMessage("Connection dropped", Color.Black, Color.LightSalmon)); }; // Open the capture file created by buffered_process OpenSingleLogFile(buffered_serialconn.Filepath, !buffered_serialconn.TmpFile); buffered_serialconn.Start(); SetStaticStatusMessage("Connected", Color.Black, Color.LightGreen); // Pass over the ref if (m_buffered_serialconn != null) { m_buffered_serialconn.Dispose(); } m_buffered_serialconn = buffered_serialconn; buffered_serialconn = null; } catch (Exception ex) { Log.Write(ELogLevel.Error, ex, $"Failed to connect {conn.CommPort}:{conn.BaudRate} -> {conn.OutputFilepath}"); Misc.ShowMessage(this, $"Failed to connect to {conn.CommPort}:{conn.BaudRate}.", Application.ProductName, MessageBoxIcon.Error, ex); } finally { if (buffered_serialconn != null) { buffered_serialconn.Dispose(); } } }
public Settings() { RecentFiles = string.Empty; RecentPatternSets = string.Empty; Font = new Font("Consolas", 8.25f, GraphicsUnit.Point); RestoreScreenLoc = false; // False so that first runs start in the default window position ScreenPosition = new Point(100, 100); WindowSize = new Size(640, 480); PatternSetDirectory = Util.ResolveUserDocumentsPath(Application.CompanyName, Application.ProductName); ExportFilepath = null; AlternateLineColours = true; LineSelectBackColour = Color.DarkGreen; LineSelectForeColour = Color.White; LineBackColour1 = Color.WhiteSmoke; LineBackColour2 = Color.White; LineForeColour1 = Color.Black; LineForeColour2 = Color.Black; FileScrollWidth = Constants.FileScrollWidthDefault; ScrollBarFileRangeColour = Color.FromArgb(0x80, Color.White); ScrollBarCachedRangeColour = Color.FromArgb(0x40, Color.LightBlue); ScrollBarDisplayRangeColour = Color.FromArgb(0x80, Color.SteelBlue); BookmarkColour = Color.Violet; RowHeight = Constants.RowHeightDefault; LoadLastFile = false; LastLoadedFile = string.Empty; OpenAtEnd = true; FullPathInTitle = true; TabSizeInSpaces = 4; FileChangesAdditive = true; IgnoreBlankLines = false; AlwaysOnTop = false; FirstRun = true; ShowTOTD = true; CheckForUpdates = false; CheckForUpdatesServer = "http://www.rylogic.co.nz/"; UseWebProxy = false; WebProxyHost = string.Empty; WebProxyPort = Constants.PortNumberWebProxyDefault; QuickFilterEnabled = false; HighlightsEnabled = true; FiltersEnabled = false; TransformsEnabled = false; ActionsEnabled = false; TailEnabled = true; WatchEnabled = true; FileBufSize = Constants.FileBufSizeDefault; MaxLineLength = Constants.MaxLineLengthDefault; LineCacheCount = Constants.LineCacheCountDefault; Patterns = PatternSet.Default(); RowDelimiter = string.Empty; // stored in humanised form, empty means auto detect ColDelimiter = string.Empty; // stored in humanised form, empty means auto detect ColumnCount = 2; Encoding = string.Empty; // empty means auto detect OutputFilepathHistory = new string[0]; LogProgramOutputHistory = new LaunchApp[0]; NetworkConnectionHistory = new NetConn[0]; SerialConnectionHistory = new SerialConn[0]; PipeConnectionHistory = new PipeConn[0]; AndroidLogcat = new AndroidLogcat(); AutoSaveOnChanges = true; }
public SerialConnectionUI(Settings settings) { InitializeComponent(); m_settings = settings; m_outp_history = new List <string>(m_settings.OutputFilepathHistory); Conn = m_settings.SerialConnectionHistory.Length != 0 ? new SerialConn(m_settings.SerialConnectionHistory[0]) : new SerialConn(); m_tt = new ToolTip(); // Comm Port string[] portnames = SerialPort.GetPortNames(); m_combo_commport.ToolTip(m_tt, "The serial communications port to connect to"); foreach (var i in portnames) { m_combo_commport.Items.Add(i); } m_combo_commport.TextChanged += (s, a) => { Conn.CommPort = m_combo_commport.Text; UpdateUI(); }; m_combo_commport.SelectedIndexChanged += (s, a) => { Conn.CommPort = m_combo_commport.Text; UpdateUI(); }; // Baud rate var baudrates = new[] { 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1843200 }; m_combo_baudrate.ToolTip(m_tt, "The baud rate for the connection"); foreach (var i in baudrates) { m_combo_baudrate.Items.Add(i); } m_combo_baudrate.KeyPress += (s, a) => a.Handled = !char.IsDigit(a.KeyChar); m_combo_baudrate.TextChanged += (s, a) => { int.TryParse(m_combo_baudrate.Text, out Conn.BaudRate); UpdateUI(); }; m_combo_baudrate.SelectedIndexChanged += (s, a) => { Conn.BaudRate = (int)m_combo_baudrate.SelectedItem; UpdateUI(); }; // Data bits var databits = new[] { 7, 8 }; m_combo_databits.ToolTip(m_tt, "The number of data bits"); foreach (var i in databits) { m_combo_databits.Items.Add(i); } m_combo_databits.KeyPress += (s, a) => a.Handled = !char.IsDigit(a.KeyChar); m_combo_databits.TextChanged += (s, a) => { int.TryParse(m_combo_databits.Text, out Conn.DataBits); UpdateUI(); }; m_combo_databits.SelectedIndexChanged += (s, a) => { Conn.DataBits = (int)m_combo_databits.SelectedItem; UpdateUI(); }; // Parity m_combo_parity.ToolTip(m_tt, "The parity checking protocol to use"); m_combo_parity.DataSource = Enum.GetValues(typeof(Parity)); m_combo_parity.SelectedItem = Conn.Parity; m_combo_parity.SelectedIndexChanged += (s, a) => { Conn.Parity = (Parity)m_combo_parity.SelectedItem; UpdateUI(); }; // Stop bits m_combo_stopbits.ToolTip(m_tt, "The number of stop bits per byte"); m_combo_stopbits.DataSource = Enum.GetValues(typeof(StopBits)); m_combo_stopbits.SelectedItem = Conn.StopBits; m_combo_stopbits.SelectedIndexChanged += (s, a) => { Conn.StopBits = (StopBits)m_combo_stopbits.SelectedItem; UpdateUI(); }; // Flow control m_combo_flow_control.ToolTip(m_tt, "The handshaking protocol for communication"); m_combo_flow_control.DataSource = Enum.GetValues(typeof(Handshake)); m_combo_flow_control.SelectedItem = Conn.FlowControl; m_combo_flow_control.SelectedIndexChanged += (s, a) => { Conn.FlowControl = (Handshake)m_combo_flow_control.SelectedItem; UpdateUI(); }; // DTR enable m_check_dtr_enable.ToolTip(m_tt, "Set the Data Terminal Ready signal during communication"); m_check_dtr_enable.Checked = Conn.DtrEnable; m_check_dtr_enable.Click += (s, a) => { Conn.DtrEnable = m_check_dtr_enable.Checked; UpdateUI(); }; // RTS enable m_check_rts_enable.ToolTip(m_tt, "Set the Request to Send signal during communication"); m_check_rts_enable.Checked = Conn.RtsEnable; m_check_rts_enable.Click += (s, a) => { Conn.RtsEnable = m_check_rts_enable.Checked; UpdateUI(); }; // Output file m_combo_output_filepath.ToolTip(m_tt, "The file to save captured program output in.\r\nLeave blank to not save captured output"); foreach (var i in m_outp_history) { m_combo_output_filepath.Items.Add(i); } m_combo_output_filepath.Text = Conn.OutputFilepath; m_combo_output_filepath.TextChanged += (s, a) => { Conn.OutputFilepath = m_combo_output_filepath.Text; UpdateUI(); }; // Browse output file m_btn_browse_output.Click += (s, a) => { var dg = new SaveFileDialog { Filter = Constants.LogFileFilter, CheckPathExists = true, OverwritePrompt = false }; if (dg.ShowDialog(this) != DialogResult.OK) { return; } Conn.OutputFilepath = dg.FileName; UpdateUI(); }; // Save settings on close FormClosing += (s, a) => { // If launch is selected, add the launch command line to the history if (DialogResult == DialogResult.OK && Conn.CommPort.Length != 0) { m_settings.SerialConnectionHistory = Util.AddToHistoryList(m_settings.SerialConnectionHistory, Conn, true, Constants.MaxSerialConnHistoryLength); } }; Disposed += (s, a) => { m_tt.Dispose(); }; UpdateUI(); }