MATLAB: How to communicate with a USB instrument which is not VISA

MATLABnon-visausb

I need to control a USB stepper motor controller which is not a VISA instrument. How can I use USB without VISA?

Best Answer

USB devices can often be opened as serial ports. If the device does not support VISA, then you will need to research the protocol.
If it is a line-oriented protocol then matters are often not so bad, but even with line oriented protocols, some devices have a fairly complicated command structure.
Some USB devices communicate with fixed length binary packets but still compatible with serial drivers. Sometimes the interfaces for these are fairly simple and sometimes the interface can get fairly complicated.
This approach requires that the device be willing to communicate with RS232 or TTL emulation. This approach does not work if the USB device registers itself as an audio or video device, or as a bulk data device (e.g. like a disk drive.) It is not possible to communicate directly from MATLAB to arbitrary USB devices: to work with such devices you need code that talks to the USB controller, giving USB controller commands and retrieving results, which requires a binary packet structure that cannot be created at the MATLAB level.
MATLAB also does not support any way of sending the USB controller a "push" packet, which effectively limits the number of back and forth serial interactions per second, as the USB drivers will wait for a while assuming that more serial data might arrive, only dispatching the packet when it fills up or a timeout occurs. The serial flush operation supported by MATLAB does not force the data to be sent: the serial flush operation is to remove any pending output from the output buffer.
Related Question