Skip to content

Commit

Permalink
final fix, ready to go
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGalluzzi committed Apr 23, 2024
1 parent e8c79b2 commit 108daf5
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 63 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified WindowsAppCanalyzer/.vs/WindowsAppCanalyzer/v17/.suo
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@
"RelativeDocumentMoniker": "WindowsAppCanalyzer\\Form1.cs",
"ToolTip": "C:\\Users\\Eric\\Documents\\GitHub\\ECE4180_CANalyzer\\WindowsAppCanalyzer\\WindowsAppCanalyzer\\Form1.cs",
"RelativeToolTip": "WindowsAppCanalyzer\\Form1.cs",
"ViewState": "AQIAAP8AAAAAAAAAAAAgwBgBAAARAAAA",
"ViewState": "AQIAACEBAAAAAAAAAAAwwDgBAAAjAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-08T16:16:55.63Z",
"IsPinned": true,
"EditorCaption": ""
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}"
},
{
"$type": "Document",
"DocumentIndex": 2,
Expand All @@ -48,11 +52,7 @@
"RelativeToolTip": "WindowsAppCanalyzer\\Form1.cs [Design]",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-08T15:59:57.196Z",
"IsPinned": true
},
{
"$type": "Bookmark",
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}"
"EditorCaption": " [Design]"
},
{
"$type": "Document",
Expand All @@ -62,9 +62,10 @@
"RelativeDocumentMoniker": "WindowsAppCanalyzer\\Form1.Designer.cs",
"ToolTip": "C:\\Users\\Eric\\Documents\\GitHub\\ECE4180_CANalyzer\\WindowsAppCanalyzer\\WindowsAppCanalyzer\\Form1.Designer.cs",
"RelativeToolTip": "WindowsAppCanalyzer\\Form1.Designer.cs",
"ViewState": "AQIAAEgAAAAAAAAAAAAgwGAAAAAMAAAA",
"ViewState": "AQIAAKAAAAAAAAAAAAAAAA4AAAAIAAAA",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2024-04-23T01:39:07.975Z"
"WhenOpened": "2024-04-23T01:39:07.975Z",
"EditorCaption": ""
}
]
}
Expand Down
37 changes: 18 additions & 19 deletions WindowsAppCanalyzer/WindowsAppCanalyzer/Form1.Designer.cs

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

71 changes: 35 additions & 36 deletions WindowsAppCanalyzer/WindowsAppCanalyzer/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO.Ports;
using System.Runtime.Remoting.Messaging;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
Expand All @@ -18,10 +19,12 @@ public partial class Form1 : Form
{
bool comReady = false;
bool fileLoaded = false;

private static Dbc dbc;
private static SerialPort mySerialPort;
private OpenFileDialog openFileDialog;
private int load = 0;
private uint filter = 0xFFF;



Expand Down Expand Up @@ -98,42 +101,26 @@ private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

private void button1_Click(object sender, EventArgs e)
{
if(!comReady)
{
MessageBox.Show("You must initilize COM port first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else
{


string hexPattern = "^[0-9A-Fa-f]{3}$";
if (Regex.IsMatch(textBox2.Text, hexPattern)) // checks to make sure its a 3 digit hex
{
// Display a confirmation dialog
DialogResult result = MessageBox.Show("Are you sure you want to send this message?", "Warning! Sending incorrect messages can be fatal", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
// set filter
filter = Convert.ToUInt32(textBox2.Text,16);

// Check the user's choice
if (result == DialogResult.Yes)
{
// Send the message (you can add your logic here)

MessageBox.Show("Message sent successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("I guess you didn't want to send it afterall", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}


}
else // Incorrect CAN ID
{
MessageBox.Show("Make sure the CAN ID is the right length it should be 3 digits of HEX ex) FFF, 001 ect.", "CAN ID not correct", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}


}

private void textBox2_TextChanged(object sender, EventArgs e)
{
}


private void textBox1_TextChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -191,7 +178,7 @@ private void dbcButton_Click(object sender, EventArgs e)
try {

dbc = Parser.ParseFromPath(filePath);
fileLoaded = true; fileLoaded = true;
fileLoaded = true;
} catch (Exception ex)
{
MessageBox.Show("Error in DBC file Parsing");
Expand Down Expand Up @@ -310,7 +297,8 @@ private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArg
foreach(var message in dbc.Messages)
{
uint id = uint.Parse(dataParts[0], System.Globalization.NumberStyles.HexNumber);
if (id == message.ID)

if ((filter == 0xFFF || id == filter) && id == message.ID)
{
text += ($"Message Name: {message.Name}, Message ID: {dataParts[0]}\n");
ulong txMsg = ulong.Parse(dataParts[1], System.Globalization.NumberStyles.HexNumber);
Expand All @@ -319,13 +307,14 @@ private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArg
double rxMsg = Packer.RxSignalUnpack(txMsg, signal);
text += ($"{signal.Name} : {rxMsg}\n");
}
Invoke((MethodInvoker)delegate
{
DisplayData(text); // Safely update the UI from the UI thread
});
break;
}
}
Invoke((MethodInvoker)delegate
{
DisplayData(text); // Safely update the UI from the UI thread
});

}
} else
{
Expand Down Expand Up @@ -357,27 +346,31 @@ private void button3_Click_1(object sender, EventArgs e)

if (mySerialPort != null && mySerialPort.IsOpen)
{
// Invoke serial port closing operation on the UI thread
Invoke((MethodInvoker)delegate
// Create a new thread to close the serial port
Thread closePortThread = new Thread(() =>
{
try
{
// Close the serial port
mySerialPort.Close();
MessageBox.Show("Serial port closed successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
// Handle any exceptions that may occur during serial port close
MessageBox.Show($"Error closing serial port: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// Dispose of the serial port (optional based on your application needs)
mySerialPort.Dispose();
mySerialPort = null; // Set to null after disposal (optional)
if (mySerialPort != null)
{
mySerialPort.Dispose();
mySerialPort = null;
}
}
});

// Start the thread to close the serial port
closePortThread.Start();
}
else
{
Expand All @@ -386,7 +379,13 @@ private void button3_Click_1(object sender, EventArgs e)
}
}






private void button4_Click(object sender, EventArgs e)
{
filter = 0xFFF;
textBox2.Text = "CAN ID";
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 108daf5

Please sign in to comment.