05-25-2010 01:30 AM
hello everybody
there is one project using labwindows/cvi,
I want to know the transport data from USB RAW in the interrupt pipe,but there is some problems,the cod is below:
int CVICALLBACK Cofig(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
ViUInt16 RcCount;
ViUInt8 RcCounteel;
ViStatus STATUS;
ViSession USB_INICIO;
ViString identificador_usb = "USB0::0x10C4::0x0000::NI-VISA-0::RAW";
ViFindList findList;
ViUInt32 numInstrs;
char instrDescriptor[256];
ViSession USB_FIND;
ViEventType tipoEvento;
ViEvent evento;
unsigned char bufferLido[50];
ViUInt16 tamanhoBufferLeitura=5;
ViUInt32 contLei;switch (event)
{
case EVENT_COMMIT:
STATUS = viOpenDefaultRM (&USB_INICIO);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viOpenDefaultRM");
break;
}
STATUS = viFindRsrc (USB_INICIO, identificador_usb, &findList, &numInstrs, instrDescriptor);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viFindRsrc");
QuitUserInterface (0); // for?a o fechamento do programa
}
STATUS = viOpen (USB_INICIO, &instrDescriptor[0], VI_NULL, VI_NULL, &USB_FIND);
viSetAttribute(USB_FIND,VI_ATTR_MAX_QUEUE_LENGTH,100);
viSetAttribute(USB_FIND,VI_ATTR_USB_MAX_INTR_SIZE,64);
STATUS = viEnableEvent (USB_FIND, VI_EVENT_USB_INTR, VI_QUEUE, VI_NULL);
STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento);
STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_DATA, &RcCounteel);
SetCtrlVal(panelHandle,PANEL_Outdata,RcCounteel);
STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount);
SetCtrlVal(panelHandle,PANEL_NUMERIC,RcCount);
STATUS = viRead (USB_FIND, bufferLido, tamanhoBufferLeitura,&contLei);
STATUS = viClose (USB_FIND);
STATUS = viClose (USB_INICIO);
break;
}
return 0;}
and i want to know what is wrong with the code.that is good if someone can give me one example.
thank you
05-25-2010 01:40 AM
Hi daxue1234,
what are the problems with your code? Do you receive error messages? What are these error messages, at which function calls do they occur?
Did you check all the status values? You are calling functions such as viSetAttribute without checking the return status.
Moreover it appears that you open USB_INICIO, but then you want to close USB_FIND...?
05-25-2010 02:57 AM
the error message is NON-FATAL RUN-TIME ERROR: "USB.c", line 92, col 22, thread id 0x00000AB4: Function viRead: (return value == -1073807302 [0xbfff003a]). Unable to start operation because setup is invalid (due to attributes being set to an inconsistent state). how can i read the data from the USB RAW ? Thank you again
05-25-2010 03:37 AM
Hm, I have no answer... but how do you know that an interrupt actually occured and there is something to read?
05-25-2010 04:08 AM
if an interrupt actually not occured ,the timeout would be appeared,is right?
and acctruly i dont know there is some data be read,can you help me? i have not enought time
05-25-2010 05:23 AM
well, you would need soemthing like an if ... then... else or while construct to check if an interrupt occured. Only if an interrupt is detected, you will need to read the data, otherwise there are no data and you might get an error...
05-25-2010 06:44 AM
int CVICALLBACK Cofig(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
ViUInt16 RcCount;
ViUInt8 RcCounteel;
ViStatus STATUS;
ViSession USB_INICIO;
ViString identificador_usb = "USB0::0x10C4::0x0000::NI-VISA-0::RAW";
ViFindList findList;
ViUInt32 numInstrs;
char instrDescriptor[256];
ViSession USB_FIND;
ViEventType tipoEvento;
ViEvent evento;
unsigned char bufferLido[50];
ViUInt16 tamanhoBufferLeitura=5;
ViUInt32 contLei;
switch (event)
{
case EVENT_COMMIT:
STATUS = viOpenDefaultRM (&USB_INICIO);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viOpenDefaultRM");
break;
}
STATUS = viFindRsrc (USB_INICIO, identificador_usb, &findList, &numInstrs, instrDescriptor);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viFindRsrc");
QuitUserInterface (0); // for?a o fechamento do programa
};
STATUS = viOpen (USB_INICIO, &instrDescriptor[0], VI_NULL, VI_NULL, &USB_FIND);
viSetAttribute(USB_FIND,VI_ATTR_MAX_QUEUE_LENGTH,100);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a VI_ATTR_MAX_QUEUE_LENGTH ");
QuitUserInterface (0); // for?a o fechamento do programa
};
viSetAttribute(USB_FIND,VI_ATTR_USB_MAX_INTR_SIZE,64);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a VI_ATTR_USB_MAX_INTR_SIZE ");
QuitUserInterface (0); // for?a o fechamento do programa
} ;
STATUS = viEnableEvent (USB_FIND, VI_EVENT_USB_INTR, VI_QUEUE, VI_NULL);
STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento);
while(STATUS == VI_SUCCESS)
{STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_DATA,&RcCounteel);
SetCtrlVal(panelHandle,PANEL_Outdata,RcCounteel);
STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount);
SetCtrlVal(panelHandle,PANEL_NUMERIC,RcCount);
STATUS = viRead (USB_FIND, bufferLido, tamanhoBufferLeitura,&contLei);
SetCtrlVal(panelHandle,PANEL_TEXTBOX,bufferLido);
SetActiveCtrl(panelHandle,PANEL_TEXTBOX );
STATUS = viClose (USB_FIND);
STATUS = viClose (USB_INICIO);
break;
}
break;
}
return 0;}
I use the while struct,but there is same error too.
should I set some attrbutes before the transport?
05-25-2010 08:09 AM
Hi,
in my opinion you should not use the while with STATUS, but instead: while (tipoEvento != VI_EVENT_USB_INTR) waitonevent
05-25-2010 09:11 AM
thank you for your help,but there is error too.
int CVICALLBACK Cofig(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
ViUInt16 RcCount;
ViUInt8 RcCounteel;
ViStatus STATUS;
ViSession USB_INICIO;
ViString identificador_usb = "USB0::0x10C4::0x0000::NI-VISA-0::RAW";
ViFindList findList;
ViUInt32 numInstrs;
char instrDescriptor[256];
ViSession USB_FIND;
ViEventType tipoEvento;
ViEvent evento;
unsigned char bufferLido[50];
ViUInt16 tamanhoBufferLeitura=5;
ViUInt32 contLei;
switch (event)
{
case EVENT_COMMIT:
STATUS = viOpenDefaultRM (&USB_INICIO);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viOpenDefaultRM");
break;
}
STATUS = viFindRsrc (USB_INICIO, identificador_usb, &findList, &numInstrs, instrDescriptor);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viFindRsrc");
QuitUserInterface (0); // for?a o fechamento do programa
};
STATUS = viOpen (USB_INICIO, &instrDescriptor[0], VI_NULL, VI_NULL, &USB_FIND);
viSetAttribute(USB_FIND,VI_ATTR_MAX_QUEUE_LENGTH,100);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a VI_ATTR_MAX_QUEUE_LENGTH ");
QuitUserInterface (0); // for?a o fechamento do programa
};
viSetAttribute(USB_FIND,VI_ATTR_USB_MAX_INTR_SIZE,64);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a VI_ATTR_USB_MAX_INTR_SIZE ");
QuitUserInterface (0); // for?a o fechamento do programa
} ;
STATUS = viEnableEvent (USB_FIND, VI_EVENT_USB_INTR, VI_QUEUE, VI_NULL);
STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento);
while (tipoEvento != VI_EVENT_USB_INTR)
{STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_DATA,&RcCounteel);
SetCtrlVal(panelHandle,PANEL_Outdata,RcCounteel);
STATUS = viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount);
SetCtrlVal(panelHandle,PANEL_NUMERIC,RcCount);
STATUS = viRead (USB_FIND, bufferLido, tamanhoBufferLeitura,&contLei);
SetCtrlVal(panelHandle,PANEL_TEXTBOX,bufferLido);
SetActiveCtrl(panelHandle,PANEL_TEXTBOX );
STATUS = viClose (USB_FIND);
STATUS = viClose (USB_INICIO);
break;
}
break;
}
return 0;}
05-25-2010 09:18 AM
what I meant was to wait until you receive the desired interrupt:
tipoEvento = -5;
while (tipoEvento!=VI_EVENT_USB_INTR)
{
STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento);
}
this is not the recommended solution because it will lock your program if no interrupt occurs, but it should be fine to test the interrupt detection.