Does Matlab support USB communication?

I want to get input for my MATLAB program from a USB source. Maybe? How? I am also a hardware developer that sends audio stream over USB. Is there a way to send such data, making it easier to receive it?

+2


source to share


3 answers


You probably need the Toolbox Toolbox .



+1


source


Can you provide your device with a virtual USB COM port? Then, normal MATLAB COM port calls ( overview ) work well.

s1 = serial(port,'BaudRate',57600,'Parity','none','Stopbits',1, ...
       'Terminator','CR/LF'); % there are more properties to play with
fopen(s1);
fprintf(s1, 'text'); % appends terminator
resp = fscanf(s1);  % waits for terminator
fwrite(s1, [1 2 3 4 5], 'uint8'); % writes binary chars, no terminator
resp = fread(s1, s1.BytesAvailable, 'char'); % reads all available bytes as chars
fclose(s1);

      



These calls don't need the Data Acquisition Toolkit, which is nice, and in my experience I work with both ASCII and binary data.

On some computers, we found that the FOPEN call lasted forever. For some reason this is due to Bluetooth virtual COM ports on some laptops. So we ended up writing a very simple .NET DLL that combined the Microsoft .NET serial port class and then imported it into Matlab as an ActiveX server. But hopefully the above will get you started.

+3


source


Either you have a virtual serial port, or the example above, or you have some kind of API in some language, preferably in C / C ++ (if you want fast data transfer) to the device driver that is installed when the device is connected ...

+2


source







All Articles