tags:

views:

1208

answers:

3

I would like to receive the input for my MATLAB program from an USB source. It is possible? How? I am also the developer of the hardware that sends an audio stream through the USB. There is any way to send this kind of data it making easier to receive it?

+3  A: 

Can you have your device present a USB virtual COM port? Then the 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 toolbox, which is nice, and in my experience work ok with both ASCII and binary data.

On some computers, though, we found that the FOPEN call took forever. This had something to do with Bluetooth virtual COM ports on some laptops for some reason. So we ended up writing a really simple .NET DLL that wrapped the Microsoft .NET serial port class, then imported it into Matlab as an ActiveX server. But hopefully the above will let you get started.

mtrw
I am using .NET currently, but in a different way. My .NET class calls MATLAB passing the data from the USB. But as my application is MATLAB-centric I think that your solution is nicer.
Jader Dias
+1  A: 

You are likely to want the Instrument Control Toolbox.

MatlabDoug
+1  A: 

Either you have virtual serial port and use example above, or you have some API in some language preferably C/C++ (if you want fast data transfers) to the device driver that is installed shown when you plug in the device.

CrazyChris

related questions