Change the return type for the delegate to System.Int32.
Make sure that your event handler is declared static.
Should work fine now.
uint defRM = 0, vi = 0;
int stat = 0;
VISA.viOpenDefaultRM(ref defRM);
VISA.viOpen(defRM, "GPIB0::23::INSTR", 0, 2000, ref vi);
viEventHandler SRQ = new viEventHandler(Form1.fSRQ);
VISA.viInstallHandler(vi, VISA.VI_EVENT_SERVICE_REQ, SRQ, 0);
stat = VISA.viEnableEvent(vi, VISA.VI_EVENT_SERVICE_REQ, VISA.VI_HNDLR, 0);
switch(stat) {
case VISA.VI_ERROR_INV_OBJECT:
listBox1.Items.Add("INV_OBJECT");
break;
case VISA.VI_ERROR_INV_EVENT:
listBox1.Items.Add("INV_EVENT");
break;
case VISA.VI_ERROR_INV_MECH:
listBox1.Items.Add("
INV_MECH");
break;
case VISA.VI_ERROR_INV_CONTEXT:
listBox1.Items.Add("INV_CONTEXT");
break;
case VISA.VI_ERROR_HNDLR_NINSTALLED:
listBox1.Items.Add("HNDLR_NINSTALLED");
break;
case VISA.VI_ERROR_NSUP_MECH:
listBox1.Items.Add("NSUP_MECH");
break;
case VISA.VI_SUCCESS:
listBox1.Items.Add("SUCCESS");
break;
default:
listBox1.Items.Add("UNK");
break;
}
VISA.viClose(vi);
VISA.viClose(defRM);
}
public static System.Int32 fSRQ(System.UInt32 vi, System.UInt32 eventType, System.UInt32 viEvent, System.UInt32 userHandle) {
return VISA.VI_SUCCESS;
}
this returns VI_SUCCESS on viEnableEvent.
don't know if it really gets the event or not.
Thanks for your help with the debugging.