Page 1 of 1

CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Mon 12. Mar 2018, 14:13
by F.Albers
Hello,

i use a PCAN USB Dongle with driver version 4.1.3. Initializing a channel works fine until the application is closed during debugging with the 'Stop Debugging' button in Visual Studio. Afterwards, CAN_Initialize always returns PCAN_ERROR_INITIALIZE. The only workaround i found so far is restarting Visual Studio. Probably this is due to the not uninitialized channel of the closed application. Is there some way to uninitialize all open channels at the start of the application? Calling CAN_uninitialize(PCAN_USBBUS1) or CAN_uninitialize(PCAN_NONEBUS) does not help. I used this code from the examples:

Code: Select all

int main()
{
	TPCANStatus result;
	char strMsg[256];

	// Der PCI Kanal wird initialisiert.
	//
	result = CAN_Initialize(PCAN_USBBUS1, PCAN_BAUD_500K);
	if (result != PCAN_ERROR_OK)
	{
		// Ein Fehler ist aufgetreten. Die Rückgabewert wird in Text umgewandelt und angezeigt.
		//
		CAN_GetErrorText(result, 0, strMsg);
		std::cout << strMsg << std::endl;
	}
	else
		std::cout << "OK" << std::endl;

	Sleep(3000);

    return 0;
}

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Mon 12. Mar 2018, 14:45
by K.Wagner
Hello,

normally abandoned connection are cleared automatically. Which operating system are you using?

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Mon 12. Mar 2018, 15:07
by F.Albers
Thanks for the quick reply! I am using Windows 10. Even after a few minutes the abandoned connection seems not to be cleared.

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Mon 12. Mar 2018, 16:05
by K.Wagner
Hello,

with your code and using VS20017 (Windows 10 - 64 bits) seems to work. I start a debug session, stop debugging just after the connection is established, and when I start the program again, no error is shown, i.e. the connection is established again.
F.Albers wrote:The only workaround i found so far is restarting Visual Studio.
This would mean that the dll (PCAN-Basic) is still loaded from within VS. Closing VS unloads all used libraries, so PCAN-Basic mark your connection as "dropped".
F.Albers wrote:Is there some way to uninitialize all open channels at the start of the application?
not directly, since this is targeted to happen automatically. The driver itself will delete an abandoned connection when you terminate another PCAN software. Try the following: When the problem happens, open and close an instance of PCAN-View. This trigger the cleanup procedure in the device driver.

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Tue 13. Mar 2018, 11:38
by F.Albers
After a little bit more research i can confirm that it does work with the 64 Bit version of the PCAN-Basic library.
However, if i use the 32 Bit version of the library, it does not.

I'll try to switch my application to 64 Bits.

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Tue 13. Mar 2018, 11:42
by K.Wagner
Thanks for the feedback. The test we did with your code was also a 32 Bit project on a 64 Bit machine. Nevertheless, we will check if the platform has any influence on this.

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Tue 19. Jun 2018, 08:47
by K.Wagner
Hello,

Solution/Workaround: Disabling the hosting process von Visual Studio (2015 or older) allows abandoned PCAN-Basic connection to be cleared.

As stated several times, this problem is actually a side effect of a "Visual Studio feature" called Visual Studio hosting process. Microsoft is aware that this may cause problems when using DLLs (like PCAN-Basic), and so they have written a document, published by 2016, to help you disabling the hosting process:
How to disable the Hosting Process in Visual Studio
How to disable the Hosting Process in Visual Studio
HostingProccess.PNG (53.06 KiB) Viewed 7278 times
You can read the document here: how-to-disable-the-hosting-process

Re: CAN_initialize failing after 'Stop Debugging' in VS 2015

Posted: Wed 21. Aug 2019, 10:40
by K.Wagner
Hello,

with the last version of our PeakCpl, Windows Control Panel Applet, there is now the possibility to reset abandoned PCAN-Basic connections. You will see a PCAN-Basic tab if there are active PCAN-Basic connections.

Closed