Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

System halts after viEnableEvent()

Solved!
Go to solution
Hello,
after I'm calling the function viEnableEvent my System (x86 Realtime target) halts and no connection via Labview, Web, FTP is possible.
Here is my code in CVI:
#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <visa.h>

int  __stdcall InitLibrary(void);

ViStatus _VI_FUNCH IntrHandler(ViSession vi, ViEventType eventType, ViEvent context, ViAddr userhandle)
{
	printf("An event was received.\n");
	return VI_SUCCESS;
}

int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	switch (fdwReason)
	{
		case DLL_PROCESS_ATTACH:
			if (InitCVIRTE (hinstDLL, 0, 0) == 0)
				return 0;	  /* out of memory */
			InitLibrary();
			break;
		case DLL_PROCESS_DETACH:
			CloseCVIRTE ();
			break;
	}
	return 1;
}

ViSession defaultRM;
ViSession session;

int __stdcall InitLibrary(void)
{
	ViStatus status; 

	status = viOpenDefaultRM (&defaultRM);
	if (status < VI_SUCCESS) {
		printf("Could not open a session to the VISA Resource Manager!\n");
		return 0;
	}  
 
	status = viFindRsrc(defaultRM, "PXI?*INSTR{VI_ATTR_MANF_ID==0x1234 && VI_ATTR_MODEL_CODE==0x1234}", &findList, &numInstrs, instrDescriptor);
	if (status < VI_SUCCESS){
		printf ("An error occurred while finding resources.\n");
		return status;
	}

	status = viOpen(defaultRM, instrDescriptor, VI_NULL, VI_NULL, &session);
	if (status < VI_SUCCESS) {
		printf ("An error occurred opening a session to %s\n",instrDescriptor);
		return status;
	}

	status = viInstallHandler(session, VI_EVENT_PXI_INTR, IntrHandler, VI_NULL);
	if (status < VI_SUCCESS) {
		printf("Could not install the interrupt handler.\n");
		viClose (defaultRM);
		return -1;          
	}
	printf("Installed the interrupt handler.\n");

	status = viEnableEvent(session, VI_EVENT_PXI_INTR, VI_HNDLR, VI_NULL); 
/// MY SYSTEM STOPPED HERE!
	if (status < VI_SUCCESS) {
		printf("Could not enable the interrupt event (0x%x).\n", status);
		viClose (defaultRM);
		return -1;          
	}
	printf("Enabled the interrupt event.\n");

 return 1; }

 

If I replace VI_HNDLR to VI_QUEUE, the program continues.
With the Driver Wizard I already generated an inf File for my hardware. I also communicated correcly with my card.
Does anyone know what condition(s) can cause this error or know what the problem may be?
Thanks,
Hauke
0 Kudos
Message 1 of 3
(3,488 Views)

I already wrote that when I call the function viEnableEvent with the parameter VI_QUEUE, the event is attached.


If I activate VI_QUEUE and VI_HNDLR like:

 

viEnableEvent(session, VI_EVENT_PXI_INTR, VI_QUEUE|VI_HNDLR, VI_NULL);

 

I get an error code BFFF00A4h (VI_ERROR_NSUP_MECH, The specified mechanism is not supported by the given event type.) and the RT target restarts automatically after 2 seconds.

 

Maybe this information will help...

 

Thanks

Hauke Webermann

0 Kudos
Message 2 of 3
(3,472 Views)
Solution
Accepted by topic author hauke webermann

When the DLLMain thread call viEnableEvent, I think it is created a special thread with the event handler function and the DLLMain thread suspends on a condition or semaphore. So the main thread waits for the new thread is started. The new thread sends an event or a signal to the DLLMain thread and wakes it up. But I called the viEnableEvent in my initialization in the DLLMain during DLL_PROCESS_ATTACH. During this time no other threads can run and so the main thread waits for a thread which can’t start.

As a solution I have now created a thread that’s starts even after the initialization process and initialize the interrupt event.

0 Kudos
Message 3 of 3
(3,406 Views)