I did just notice that it is failing on the second call to Cleanup().
Timeout issue maybe in the loop ... still should not crash, it should gracefully bitch and quit.
Never quite understood that, the finally block has worked all the time I have been involved in the project, maybe at an earlier point in development it wasn't being triggered and it's a left over, there is a note in the code that says,
Gampy, I'm guessing here, but it looks like it having a problem changing back to 4x mode on the 2nd reset. Something in the FindResponseFromTool function.
I verified that this.ReadDVIPacket on line 164 of OBDXProDevice.cs returns null and line 165 triggers the exception. Line 184 of Vehicle.Kernel.cs sets the device time to a minimum. I assume that the software is not waiting long enough for the response on the 2nd reset request. If so, what should the wait time be. I'll try reseting the wait time at the beginning of ExitKernel() to see if that will avoid the crash. Alternative, should there be null checking in OBDXProDevice.cs after this.ReadDVIPacket to ensure that the device actually responded appropriately?
Stack trace says it failed in FindResponseFromTool(...), FindResponseFromTool(...) is called from SetVpwSpeedInternal(...).
I suspect ReadDVIPacket(...) returns a 'null' when it should return a Response<Message> ... Might have a look at line 331 and 342 in ReadDVIPacket(...).
Intelligence is in the details!
It is easier not to learn bad habits, then it is to break them!
If I was here to win a popularity contest, their would be no point, so I wouldn't be here!
I think the delay between this.Port.Send(Msg) in SetVpwSpeedInternal and the this.ReadDVIPacket in FindResponseFromTool is too short. I moved the await Task.Delay(50) to the start of the for loop in FindResponseFromTool in OBDXProDevice.cs, as well as added null checking. The null checking (without moving the wait to the front of the for loop) did catch the error and prevented the crash, but didn't perform the function. Moving the delay to the front of the for loop made the switch to 4x work. Below is the modified FindResponseFromTool for your consideration for change in the next build.
public async Task<Response<Message>> FindResponseFromTool(byte[] expected)
{
//this.Logger.AddDebugMessage("FindResponse called");
for (int iterations = 0; iterations < 5; iterations++)
{
await Task.Delay(50);
Good debugging there. Are you sure the dvi (xpro) isnt crashing, and it really is not returning a response? Can you exit pcmhammer, start it again, and does the xpro init ok from software or does it need a power cycle?