LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i read the data in the interrupt pipe from USB RAW?

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

0 Kudos
Message 1 of 11
(5,873 Views)

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...?

0 Kudos
Message 2 of 11
(5,872 Views)
Than you for your answer,mybe i am not good at english,so it is difficult to let you understand what i mean.I have check all the statuses,everyone is 0 that means right.the error is 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
0 Kudos
Message 3 of 11
(5,860 Views)

Hm, I have no answer... but how do you know that an interrupt actually occured and there is something to read?

0 Kudos
Message 4 of 11
(5,856 Views)

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

0 Kudos
Message 5 of 11
(5,852 Views)

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...

 

0 Kudos
Message 6 of 11
(5,848 Views)

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?

0 Kudos
Message 7 of 11
(5,842 Views)

Hi,

 

in my opinion you should not use the while with STATUS, but instead: while (tipoEvento != VI_EVENT_USB_INTR)  waitonevent 

 

0 Kudos
Message 8 of 11
(5,835 Views)

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;}

 

0 Kudos
Message 9 of 11
(5,830 Views)

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.

0 Kudos
Message 10 of 11
(5,828 Views)