INNO-MAKER / USB2CAN-X2

innomaker USB2CAN two channels device
7 stars 5 forks source link

C++ DLL Opening and Closing CAN X2 Device Bug #3

Open ntrambitas12 opened 2 weeks ago

ntrambitas12 commented 2 weeks ago

Hi,

I am working on developing a Windows C++ application and interfacing it with the CAN X2 device. I have used the Windows C++ DLL provided in the GitHub repository and I was able to get the program to communicate and discover the device and then get the device to RX/TX data on the CANBUS. However, I have noticed that the CANX2 device only lets me RX/TX data on the bus the first time that it is plugged into the PC and the program is opened up. If I close the program and reopen it, I see that it successfully opens the InnoMaker device (The LEDs on the outside of the unit light up for the correct Channel), but there’s no CAN communication on the bus. I am not able to TX/RX data. I must close the program, unplug the USB, plug it back in, then reopen the program to get the device to be able to RX/TX CAN data again.

Currently, my program initializes the CAN X2 Device in this order: 1) setup() // Load DLL 2) scanInnoMakerDevice() // Find devices 3) getInnoMakerDeviceCount() // Get device count 4) urbSetupDevice() // Open device 5) // Immediately initialize context can = new InnoMakerUsb2CanLib::innomaker_can();

/// Init tx context, required as part of startup sequence for (int i = 0; i < usbCANLib->innomaker_MAX_TX_URBS; i++) { can->tx_context[i].echo_id = usbCANLib->innomaker_MAX_TX_URBS; }

If I do the following in that order, after I first plug in the USB on the computer, I can see that as soon as I execute the above lines of code, the LEDs turn on outside of the unit for the port I selected, and everything works. I followed the guide and the example C++ code for allocating and freeing the context when I Send or Receive data. Everything works normally.

Here is my shutdown procedure that I follow to disconnect the device: 1) urbResetDevice() // Reset device, LEDs turn off on the outside of the device 2) closeInnoMakerDevice(); 3) setdown() // Unload DLL on program close

After executing the above code, I see that the activity lights turn off on the outside of the device. However, if I try to reopen the device, it seems like it wants to work, as the activity lights come on, but no data can be sent or received on CAN. Only way to get it to work again is by physically unplugging the USB.

I am wondering, am I missing anything in my shutdown procedure where I am not closing or resetting the device properly? It almost feels like I am missing an instruction in resetting the device. Is there a way to see the error codes on why the device does not want to go on the bus on the next start up? Is there a flowchart out there with the exact start up and shutdown steps that need to be followed to properly start up and shutdown the device?

Thank you and I appreciate any help