1
votes

i want to control the on-off operation of a device(say a small usb fan or a usb lamp) connected to my laptop via usb cable through matlab in windows os.I have searched too many websites including matlab blogs and product documentation,but in vain.There is some information in matlab instrument control toolbox box about switches but it caters to industrial switches so not usefull to me.please help.

1

1 Answers

1
votes

Does the driver for your device have C/C++ functions that you could call to control it? If so, write a simple DLL in Visual Studio which uses the standard MEX interface with Matlab, and call those C/C++ functions there. Build the DLL and rename it from .dll to .mexw32 (or .mexw64, if you're using a 64-bit Matlab). Then you should be able to run it by calling the filename as a function from Matlab.

Without knowing more about your device, I can only give examples of controlling other USB devices. For example, you could use the C code from this article to unmount a USB flash drive; just compile the code into a DLL and call it from Matlab.