communicating with USB in MATLAB

is it possible to read data from USB port with java or C++ and import the data in MATLAB?in fact I am looking for a solution to read data from USB port and plot it in MATLAB

1 Comment

Hi, I am new to matlab and have same question. I was to transfer data from USB to matlab,
and i can't find the wat anywhere. Some people say thta we have to make a virtual serial port and
then assign this port to usb. But I [don't know how to do that. AlSO, can somwone tell me if matlab' ...
support USB ports or not. If yes how ?]

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 5 Feb 2012
Why do you need to read it with a java or C++ program and import into MATLAB? Why don't you just read the values directly with MATLAB?

3 Comments

I am kind a bit new in MATLAB and I found that MATLAB does not communicate with USB,it only supports Serial port.I am making a Data Acquisition Board with PIC and I need communication to communicate through USB
Did you look up USB in the help? You'll see lots of stuff, such as this:
"If you have devices that present themselves as serial ports on your operating system, you can use them as virtual USB serial ports in MATLAB. Examples of such devices would be Bluetooth® devices and USB Serial Dongles.
MATLAB can communicate with these devices as long as the serial drivers provided by the device vendor are able to emulate the native hardware. Certain software, like HyperTerminal, does not require the device driver to fully implement and support the native hardware. "
Hi, I am new to matlab and have same question. I was to transfer data from USB to matlab,
and i can't find the wat anywhere. Some people say thta we have to make a virtual serial port and
then assign this port to usb. But I [don't know how to do that. AlSO, can somwone tell me if matlab' ...
support USB ports or not. If yes how ?]

Sign in to comment.

Walter Roberson
Walter Roberson on 5 Feb 2012
Suppose that someone told you that they wanted to communicate with a telephone. Not communicate with someone by using a telephone: that they wanted to communicate with the telephone itself.
USB is a hardware specification (voltages, connector types), and a protocol for communications. USB is not a device. Individual devices can use the USB hardware and protocol to communicate, but it is not USB itself that is doing the communication.
You cannot communicate with a USB port. You can communicate with a device that is connected through USB. But to do that you need to know which of the defined USB sub-protocols that the device uses. Is the device communicating like a camera? Like a microphone? Like a hard-disk?

8 Comments

I am going to make a Data Acquisition Board with PIC18F452 and I want to use Matlab for displaying the signal in computer side,I want to connect ,my device to through the USB cable to computer
http://www.mathworks.com/matlabcentral/answers/12305-real-time-emg-data-plot-through-mathlab
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf
http://www.electro-tech-online.com/microcontrollers/36817-serial-communication-pic-18f4550.html
Pulling together the information from the above:
The PIC18F452 does not have a built-in USB interface, so you would have to add an interface to USB if that was important to you. The manner in which the PIC communicated with the USB interface would depend upon your design decisions.
The PIC18F452 does have a USART, and it appears that the USART runs at TTL levels. This could be adjusted to work with RS232 using relatively common RS232 to TTL level convertor chips such as the MAX232. If that was done, then you would connect the device to the computer using a serial port -- and MATLAB *does* handle serial ports.
The main reason one might choose USB over RS232 is that USB can in theory transfer data at 480 Mbit per second (with full packets... if all the data is all ready to go...). On the other hand, USB is not suitable for real-time work: it is inherently not real-time. Unless special steps are taken (that are not directly supported in MATLAB) the minimum serial packet latency for USB is 40 ms, only 125 Hz.
If you are definitely going to use USB to interface the PIC then you are going to have to decide what kind of USB device you are going to present the PIC as... and if you are fortunate it will be one that MATLAB is able to talk to.
Thank you for your advice. my main concern is that the serial port can not support the real time communication,my design should have 3 data inputs.that is the reason to look for a way to support serial port...
USB cannot support real-time communication by its design.
Serial ports can support it to within the overhead and latency of sending and receiving a character.
"real time" may mean different things (have different rates) to different people. Why don't you try it and see? It might be fast enough for your purposes. Don't discount it until you try it.
USB virtual serial ports buffer bytes, by design. (There is a USB-specific way to request early release of the packet but MATLAB does not provide an interface to that mechanism.) Hold time for more output is 40 ms. Usually real-time systems need to go faster than that (the situation is like having to use 1200 baud.)
Thank you Walter, if I am going to use Serial port,it means my device can only support 480HZ and this is very low frequency .
the reason I am looking for solution to use USB is that I need to support higher frequency ,aside from that I have 3 channels so this will be divided by 3,it is very low!! :(
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf
Table 16-5.
Absolutely the only reason to be restricted to 9600 baud on that device is if you are using the slowest oscillator supported by the PIC, 32768 Hz. ANY faster oscillator supports much much greater serial port speeds.
USB will in NO WAY help. There is NO USB interface on that device. You would have to feed the USB from the serial port, so if the serial port is too slow because you wanted to save half a cent on an oscillator, then USB is going to be even slower.
The last time I encountered an oscillator as slow as 32768 Hz was on my off-brand digital watch with a special snooze alarm in the early 1970's.

Sign in to comment.

Categories

Asked:

on 5 Feb 2012

Commented:

on 3 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!