From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA USB Communication

I'm in trouble trying to communicate a raw USB device trough VISA and CVI. I can easily connect and disconnect the device by using viOpen/viClose, but I don't know how to read/write data. Some functions like viWrite return this error: "Unable to start operation because setup is invalid (usually due to attributes being set to an inconsistent state)". Which are this attributes? Neither can use specific USB functions because USB constants seem to be undefined. So I suppose I'm skipping some steps... Any help??
Thank you.
Image Hosted by ImageShack.us
0 Kudos
Message 1 of 3
(5,664 Views)
Since you are using USB RAW from C, you'll need to #define a macro before using the NI-VISA extensions. Here's an excerpt from visa.h:

"When using NI-VISA extensions, you must link with the VISA library that comes with NI-VISA. ... (NI-VISA includes) support for USB devices that do not conform to a specific class. To use this, you must define the macro NIVISA_USB before including this header. You must also create an INF file with the VISA Driver Development Wizard."

Regarding how you communicate with a RAW resource, you will need to have explicit knowledge about what that USB interface supports. For example, to write to it, it needs at least 1 bulk OUT endpoint; to read from it, it needs at least 1 bulk IN endpoint. NI-VISA should default to the fi
rst available endpoint for each of these types on the given USB interface. You'll want to check the value (via viGetAttribute) of the bulk endpoint attributes. If they're -1, that means NI-VISA could not find an appropriate endpoint on that interface. If they're any other value, then you should be able to call viWrite and viRead. Obviously, the content of the buffers (in other words, the protocol) is totally defined by your device.

Dan Mondrik
National Instruments
0 Kudos
Message 2 of 3
(5,663 Views)
Hi Dan,
Thank you for your reply. Finally I've been able to communicate with my USB device, but I still have some troubles with it.

The device at issue has the following structure:
- 1 Bulk-out pipe (no problem with viWrite)
- 1 Interrupt-in pipe that sends data every 0.3 sec aprox
- 1 Interrupt-in pipe that only sends data when the device gets a signal from an infrared receiver

I need to read the two interrupts simultaneously, and at the same time I need the first to be as fast and accurate as possible. I think the best option would be to use callbacks for both interrupts, so that it would only read when data existed. but I have a pair of impediments on the matter:
- When I try to use viInstallHandler it returns me a general protection run-time
error: Unknown source position, thread id 0x00....
- I cannot set default interrupt-in pipe when USB Interrupt Event is already enabled, so it's impossible to read the two pipes at the same time althought I open a different visa session for each one. In this case if I change it before enabling events the setting is applied to both sessions.

Seen the sight I suppose there isn't another way that to convert one of interrupt pipes into bulk.
According to the properties of each one, which do you think that it would be the most optimal change?

On the other hand I'd like to solve the problem with event handlers. Do you know how?

Thanks a lot for your interest.
Image Hosted by ImageShack.us
0 Kudos
Message 3 of 3
(5,663 Views)