Skip to content

Commit

Permalink
Added Save Log feature
Browse files Browse the repository at this point in the history
  • Loading branch information
graham22 committed Feb 28, 2023
1 parent 536b23a commit 8cdddb7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
24 changes: 23 additions & 1 deletion CommonControls/BaseForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.LinkLabel;

namespace Modbus.Common
{
Expand Down Expand Up @@ -597,6 +599,25 @@ private void buttonPauseLog_Click(object sender, EventArgs e)
buttonPauseLog.Text = _logPaused ? "Resume" : "Pause";
}

private async void buttonSaveLog_ClickAsync(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "ModbusLog";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog.DefaultExt = "txt";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
using (StreamWriter writer = new StreamWriter(saveFileDialog.FileName, append: true))
{
foreach (string line in listBoxCommLog.Items)
{
await writer.WriteLineAsync(line);
}
}
}
}

protected void DriverIncommingData(byte[] data, int len)
{
if (_logPaused)
Expand Down Expand Up @@ -632,7 +653,7 @@ protected void AppendLog(String log)
var tmpStr = ">" + now.ToLongTimeString() + ": " + log;
listBoxCommLog.Items.Add(tmpStr);
listBoxCommLog.SelectedIndex = listBoxCommLog.Items.Count - 1;
listBoxCommLog.SelectedIndex = -1;
//listBoxCommLog.SelectedIndex = -1;
}

#endregion
Expand Down Expand Up @@ -737,5 +758,6 @@ private void donate_Click(object sender, EventArgs e)
string url = "https://www.buymeacoffee.com/r4K2HIB";
System.Diagnostics.Process.Start(url);
}

}
}
16 changes: 14 additions & 2 deletions CommonControls/BaseForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cdddb7

Please sign in to comment.