Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NationalInstruments.VisaNS.UsbSession.ControlIn - Actual Count?

Solved!
Go to solution

I'm able to connect and communicate with my USBTMC instrument and retrieve information using UsbSession.ControlIn. The problem is that method doesn't return the actual bytes received like the old NI-VISA viUsbControlIn function did. In other words, the size of the byte array returned by UsbSession.ControlIn is simply the size I specified in the “length” parameter. How can I get the actual size like viUsbControlIn returned in the retCnt parameter?

 

I'm using Measurement Studio 2013 and Visual Studio 2012.

0 Kudos
Message 1 of 4
(5,754 Views)

Hi ray_martin,

 

Can you provide some more information about your problem? What version of NI VISA were you using previously and what version are you using now? Have you updated or changed any of the other software?

 

Regards,

Kelsey Johnson
Applications Engineer
National Instruments
http://www.ni.com/support

0 Kudos
Message 2 of 4
(5,717 Views)

My previous code used NI-VISA 5.2 with VB6. The NI-VISA viUsbControlIn function has several parameters including "buf", "wLength" and "retCnt". I originally thought that wLength indicated the maximum caller allocated size of buf and retCnt was the actual bytes put in buf. But on closer examination, it appears retCnt is always the same as wLength (except if there is an error). Is this true?

 

For VisaNS.UsbSession.ControlIn and VB.NET, it doesn't have a buf or retCnt parameter but simply returns a byte array whose size appears to always be wLength. So in this case, the actual count is buf.count and the result is similar to the old NI-VISA viUsbControlIn response.

 

To rephrase my question, shouldn't the size of the byte array returned by the instrument depend on the instrument (device) and not the caller? I believe the maximum Control endpoint packet size for full and high speed devices is 64 bytes. Does NI-VISA viUsbControlIn (and VisaNS.UsbSession.ControlIn) pad the length of the Control response to match wLength? In other words, it appears I can set wLength to 500 and retCnt is set to 500 after the function completes which is impossible for the instrument and USB Control endpoint.

0 Kudos
Message 3 of 4
(5,703 Views)
Solution
Accepted by ray_martin

wLength actually indicates the number of bytes to be transferred in the optional data stage. You are correct that retCnt will be equal to wLength as long as there was no error.

You are telling the device how many bytes to transfer, so it depends on you to know how much data to read. So, if the maximum packet size is 64 bytes and you set wLength to 500, the device sends multiple packets until it has transferred 500 bytes of data.

 

Regards,

Kelsey Johnson

Applications Engineer

National Instruments

 

 

0 Kudos
Message 4 of 4
(5,672 Views)