LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with interrupt USB RAW

Solved!
Go to solution


Hello everybody.


Sorry more translation into English was made by Google.


I need help to get the buffer in the USB interrupt that the code attached.

 

int CVICALLBACK executarPrograma (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViUInt32 contBufferLido; ViUInt32 tamanhoBufferLeitura = 50; ViUInt32 contLeitura; unsigned char bufferLido[50]; ViStatus STATUS; ViSession USB_FIND; ViEvent evento; ViEventType tipoEvento; ViSession USB_INICIO; ViUInt32 numInstrs; ViString identificador_usb = "?*USB?*{VI_ATTR_MANF_ID==0x04D8}"; char instrDescriptor[256]; ViFindList findList; switch (event) { case EVENT_COMMIT: SetCtrlVal(panelHandle,PANEL_NUMERIC, 11111); // abre a conexão padrão para poder encontrar o dispositivo usb STATUS = viOpenDefaultRM (&USB_INICIO); if(STATUS != VI_SUCCESS) { MessagePopup("ATENÇÃO","Não foi possivel abrir a viOpenDefaultRM"); break; } // procura por um dispositivo USB 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 } SetCtrlVal(panelHandle,PANEL_TEXTBOX, instrDescriptor); SetCtrlVal(panelHandle,PANEL_TEXTBOX, "\n\r"); // abra a conexão com o dispositivo usb encontrado 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,61); STATUS = viEnableEvent (USB_FIND, VI_EVENT_USB_INTR, VI_QUEUE, VI_NULL); STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento); SetCtrlVal(panelHandle,PANEL_NUMERIC, VI_ATTR_USB_RECV_INTR_SIZE); STATUS = viRead (USB_FIND, bufferLido, tamanhoBufferLeitura, &contLeitura);<-line 68 STATUS = viClose (USB_FIND); STATUS = viClose (USB_INICIO); break; } return 0; }

 


I connected to my PC a PIC18F4550 which sends a buffer of 40 bytes every 1ms.


In labview using the "VISA Wait on Event Function" and then "Get USB Interrupt Data" over here in LabWindows I am not able to solve this problem.
Another strange thing is when I use the variable tamanhoBufferLeitura = 50 I get this error
ERRO-LABWINDOWS.jpg, and when you put the variable tamanhoBufferLeitura = 0 does not get the error while using the "SetCtrlVal (panelHandle, PANEL_NUMERIC, VI_ATTR_USB_RECV_INTR_SIZE);" to find out the size of the receive buffer read a very large value (1073 .693.104). 

 

 

If anyone can help me or can post an example of code in LabWindows done using USB interrupt, very grateful.


Ivan

 

0 Kudos
Message 1 of 9
(6,359 Views)

Ivan,

 

viRead is not the standard way to retrieve data from interrupt pipe.

 

The better way is to get the data directly from the event (conLeitura). You should be able to use viGetAttribute to get 

VI_ATTR_USB_RECV_INTR_SIZE and VI_ATTR_USB_RECV_INTR_DATA. Take a look at the help for these attributes and VI_EVENT_USB_INTR. That might shed more light on this problem.

Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 2 of 9
(6,322 Views)

Hello Song Du


 I tried this way as you wrote, however, like that described above, when using VI_ATTR_USB_RECV_INTR_SIZE to know the buffer size, I get a size too big (((1,073,693,104))) + that 1Gbyte.

All attributes are default.

0 Kudos
Message 3 of 9
(6,315 Views)

You need to call viGetAttribute to get the actual value. VI_ATTR_USB_RECV_INTR_SIZE is just a #define constant, it's always going to be 1073693104.

 

viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount);

Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 4 of 9
(6,300 Views)

Song Du ,

 

following your suggestion, now I get this error.

 

 

erro-VI_ATTR_USB_RECV_INTR_SIZE.jpg

 

int CVICALLBACK executarPrograma (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViUInt16 RcCount; ViStatus STATUS; ViSession USB_INICIO; ViString identificador_usb = "?*USB?*{VI_ATTR_MANF_ID==0x04D8}"; ViFindList findList; ViUInt32 numInstrs; char instrDescriptor[256]; ViSession USB_FIND; ViEventType tipoEvento; ViEvent evento; unsigned char bufferLido[70]; ViUInt32 tamanhoBufferLeitura = 50; ViUInt32 contLeitura; switch (event) { case EVENT_COMMIT: // apenas para controle visual SetCtrlVal(panelHandle,PANEL_NUMERIC, 11111); // abre a conexão padrão para poder encontrar o dispositivo usb STATUS = viOpenDefaultRM (&USB_INICIO); if(STATUS != VI_SUCCESS) { MessagePopup("ATENÇÃO","Não foi possivel abrir a viOpenDefaultRM"); break; } // procura por um dispositivo USB 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 } // mostra o despositivo encontrado SetCtrlVal(panelHandle,PANEL_TEXTBOX, instrDescriptor); SetCtrlVal(panelHandle,PANEL_TEXTBOX, "\n\r"); // abre a conexão com o dispositivo usb encontrado STATUS = viOpen (USB_INICIO, &instrDescriptor[0], VI_NULL, VI_NULL, &USB_FIND); // habilita o evento interrupção da USB STATUS = viEnableEvent (USB_FIND, VI_EVENT_USB_INTR, VI_QUEUE, VI_NULL); // aguarda o evento interrupção da USB STATUS = viWaitOnEvent (USB_FIND, VI_EVENT_USB_INTR, 50, &tipoEvento, &evento); // descobre o tamanho do buffer STATUS = viGetAttribute (USB_FIND, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount); // mostra a quantidade de bytes recebidos SetCtrlVal(panelHandle,PANEL_NUMERIC, RcCount); // lê os baytes recebidos STATUS = viRead (USB_FIND, bufferLido, tamanhoBufferLeitura, &contLeitura); // aqui acontece o ERRO // fecha as conexões STATUS = viClose (USB_FIND); STATUS = viClose (USB_INICIO); break; } return 0; }

 

 
Message Edited by ivan braga on 12-04-2009 01:25 PM
0 Kudos
Message 5 of 9
(6,295 Views)

Ivan,

 

Again, the interrupt size is an attribute of the event, not the communication session. So you do want to call viGetAttribute on the event, like my earlier example:

 

viGetAttribute (evento, VI_ATTR_USB_RECV_INTR_SIZE, &RcCount); 

Regards,

Song Du
Systems Software
National Instruments R&D
0 Kudos
Message 6 of 9
(6,291 Views)
Solution
Accepted by topic author ivan braga

 Song Du

 

Thank you very much.

 

The biggest problem is to understand a different language, but with your help I finally get the buffer size.

 

Their support was excellent on this issue.

 

Ivan

0 Kudos
Message 7 of 9
(6,287 Views)

hi

i made a simple ni file to read from pic18f4550 using visa and it didnt give me errors and didnt work also so please if any one can help me in what does he mean (byte count)

0 Kudos
Message 8 of 9
(5,569 Views)

Hi soliman,

 

mistakenly you have posted your question in the wrong forum: this one is for LabWindows/CVI.

0 Kudos
Message 9 of 9
(5,562 Views)