Skip to content

Commit

Permalink
Automatic COM port selection; COM port reconnection support
Browse files Browse the repository at this point in the history
  • Loading branch information
burma69 committed Sep 12, 2018
1 parent 81d5166 commit c50e6b8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
34 changes: 28 additions & 6 deletions PM3UniversalGUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,29 @@ public MainForm()

public void OnDataReceivedEventHandler(object sender, DataReceivedEventArgs e)
{
int i = e.Data.IndexOf("proxmark3>");
if (i < 0) i = e.Data.IndexOf("pm3 -->");
string[] Lines = e.Data.Split(new string[] { "\r\n" }, StringSplitOptions.None);

if (i < 0)
AppendText(ConsoleTextBox, ConsoleTextBox.ForeColor, e.Data + "\r\n");
else AppendText(ConsoleTextBox, Color.Goldenrod, e.Data + "\r\n", true);
foreach (string s in Lines)
{
int i = s.IndexOf("proxmark3>");
if (i < 0) i = s.IndexOf("pm3 -->");

if (i < 0)
AppendText(ConsoleTextBox, ConsoleTextBox.ForeColor, s + "\r\n");
else AppendText(ConsoleTextBox, Color.Goldenrod, s + "\r\n", true);
}
}


private void COMPortBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (Program.PM3.PortName == COMPortBox.SelectedItem.ToString()) return;

if (Program.PM3.IsRunning())
{
Program.PM3.StopClient();
}

Program.PM3.InitClient(COMPortBox.SelectedItem.ToString());
Program.PM3.ClientProcess.OutputDataReceived += OnDataReceivedEventHandler;
Program.PM3.StartClient();
Expand Down Expand Up @@ -324,7 +336,17 @@ private void btnRun_Click(object sender, EventArgs e)
if (!Program.PM3.IsRunning())
{
COMPortBox.Focus();
return;

if (COMPortBox.Items.Count == 0)
{
COMPortBox_DropDown(null, null);
}

if (COMPortBox.Items.Count == 1)
{
COMPortBox.SelectedIndex = 0;
}
if (!Program.PM3.IsRunning()) return;
}

Program.PM3.ClientProcess.StandardInput.WriteLine(commandComboBox.Text);
Expand Down
11 changes: 11 additions & 0 deletions PM3UniversalGUI/PM3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class PM3Client
public Process ClientProcess = new Process();
public List<PM3Command> Commands = new List<PM3Command>();
public string PM3FileName;
public string PortName;

public PM3Client(string PM3FileName)
{
Expand All @@ -379,6 +380,7 @@ public bool IsRunning()

public void InitClient(string PortName)
{
this.PortName = PortName;
ClientProcess.StartInfo.FileName = PM3FileName; // Specify exe name.
ClientProcess.StartInfo.Arguments = PortName +" -f";
ClientProcess.StartInfo.UseShellExecute = false;
Expand All @@ -394,6 +396,15 @@ public void StartClient()
ClientProcess.BeginOutputReadLine();
}

public void StopClient()
{
ClientProcess.CancelOutputRead();
ClientProcess.Kill();
ClientProcess.Dispose();

ClientProcess = new Process();
}

//try to parse detailed help output of specific command
public void ExtractCommandParams(PM3Command cmd)
{
Expand Down
4 changes: 2 additions & 2 deletions PM3UniversalGUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]
Binary file modified PM3UniversalGUI/bin/Release/PM3UniversalGUI.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion PM3UniversalGUI/bin/Release/PM3UniversalGUI.exe.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<add key="PM3ClientFilename" value="proxmark3.exe" />
<add key="ConsoleDumpTimeout" value="1000" />
</appSettings>
</configuration>
</configuration>

0 comments on commit c50e6b8

Please sign in to comment.