From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I get an invalid handle error when debugging, on a call to ncReset?

I am working with the example program obj2obj.c
I have a PCI-CAN/2 card installed.
I must call ncReset for *both* ports (CAN0 and CAN1), prior to any other commands or I will get a driver error (NC_ERR_DRIVER, Bxxx0002).
This happens even if the program terminates properly, closing all handles, and I then remove the ncReset commands.

Fine, I can live with the ncResets.
However, if I then try and debug the program using Microsoft Visual C++, it immediately chokes on the second call to ncReset( "CAN1", 0 ) and complains about an invalid handle.

If I add a status check to both of the ncResets and run the program from the DOS command line, I don't get any errors printed out
so the calls are working fine just running the program.

The driver updates listed do not appear to address this problem (1.4.1 uses LabView which I do not have and 1.4.2 is for Windows 2000)

Why are the ncResets required in the first place?

And why can't I single step through the second call to ncReset?

Thanks in advance for your help.

System details:

PC running Windows NT 4.00.1381
PCI-CAN/2 w/driver 1.4
Microsoft Visual C++ 6.0 Professional
0 Kudos
Message 1 of 6
(8,116 Views)
It is pretty strange that without the " ncreset" commands at the beginning of your application, driver errors are seen. The ncReset function is only required if the application was aborted midway through its execution previously which left unclosed CAN handles and results in errors in the subsequent reruns of the CAN application again.
ALso a single ncReset function completely resets the CAN card and wipes out the firmware on the card. The next ncConfig function call then reloads the firmware on the card. So,a single ncREset is sufficient even if you are using a 2-port CAN card as any port configuration information is wiped out immediately with that call itself. Please do try eliminating the second ncReset call and see if that worked.
In the mean time I will also tes
t the ncReset function in Visual C++ 6.0 and Win NT and see if there may be any other issues responsible for the behaviour you reported.
0 Kudos
Message 2 of 6
(8,116 Views)
bsat, thank you for helping out!

I had tried using only one ncReset previously and was experiencing driver errors. I removed the second ncReset as you suggested and now it seems to work with only one. I cannot get it to fail like it was doing.

However, at least one ncReset must be used or I get the following error:

ERROR ncConfig CAN1: Driver error (qual=000b000)
Press any key to continue

I get this error even when the program terminates normally. For example:

1) Build obj2obj with the ncReset command.
2) Execute and allow to terminate normally.
3) Edit obj2obj and remove ncReset command.
4) Execute and the error message is displayed.

Amazingly, I was also able to single step through most of the program this morning. I got the first three messages (of 10 total) before ge
tting the error:

Microsoft Visual C++
First-chance exception in cctool.exe (NTDLL.DLL): 0xC0000008: Invalid Handle

It seems to be more random than first appeared and perhaps more related to MSVC than to the NI-CAN card. Any insight?

Also, having to include an ncReset is undesireable since I'd like to develop a CAN driver that could be called from multiple threads. I'd be very interested in your opinion on why I'm having trouble getting it to work without one.

Thanks again for your help, it is greatly appreciated!
0 Kudos
Message 3 of 6
(8,116 Views)
Darn, forgot to mention-

I went ahead and installed the latest (1.4.2) NICAN driver.

I also upgraded MSVC to Service pack 3.

Neither had any effect on the problems.
0 Kudos
Message 4 of 6
(8,116 Views)
bsat-

Well, I figured out the debugging problem that was generating the "invalid handle" messages.

Rookie error- the transmitter is set up to automatically transmit a message every second. If you try stepping through the program, the receiver buffer can get overrun. You may not see the error message indicating overflow unless you are in the right place at the right time. I assume the card is closing the channel when the error occurs and that is why I get the "invalid handle" message. I bumped the times up and was able to single step without errors.

I still cannot figure out why the ncReset is required....
0 Kudos
Message 5 of 6
(8,116 Views)
I was able to replicate the problems with the ncReset function during debugging in the VC++ environment. Corrective Action Requests have been filed with the Developers and asoon there are any suggestions, fixes etc I will post it up on the Developer Exchange.
The requirement of the ncReset function at the beginning of the VC++ CAN application seems to be OS dependent. I saw the problem only on a Win NT system and not Win 2000/98.
0 Kudos
Message 6 of 6
(8,116 Views)