i need to send a signal from one computer using matlab to another computer also running matlab through usb cable
7 次查看(过去 30 天)
显示 更早的评论
i need to send a signal from one computer using matlab to another computer also running matlab through usb cable
1 个评论
回答(2 个)
Gouri Chennuru
2020-8-13
Hi Esmail,
You can make use of the Data Acquisition toolbox available in MATLAB in order transfer the data using USB cable.
You can refer to these links for more information on how to acquire data from USB.
Hope this Helps!
0 个评论
Walter Roberson
2020-8-13
In the general case, this is going to be a problem.
USB is strictly a host / device ("master/slave") system. One of the two sides must be an active controller and the other must wait for commands. But you are trying to put PCs on both ends, and most PCs are not designed to be devices, only hosts.
There are specially designed devices such as smart phones that have hardware that can detect their role and automatically switch to device mode, but PCs seldom do that. There is part of the USB specification to permit negotiation of role; see https://stackoverflow.com/questions/11338076/how-usb-otg-worksmaster-slave
USB is not like RS232 or ethernet that is Peer-To-Peer.
If you are not connecting to hardware designed to automatically switch to device mode (like a smartphone) then you need to add a device that acts as a relay.
Such a relay would probably be implemented as Virtual COM port.
To use Virtual COM Ports, you need one of:
- R2019b or later, use serialport() and related commands from basic MATLAB; https://www.mathworks.com/help/matlab/serial-port-devices.html
- earlier versions, use serial() and related commands from basic MATLAB; https://www.mathworks.com/help/matlab/ref/serial.html
- use serial() from Instrument Control Toolbox; https://www.mathworks.com/products/instrument/supported/serial.html
At the moment I do not know the major differences between serial() from basic MATLAB and serial() from Instrument Control Toolbox.
Note that USB 1.x and USB 2.x are limited to 1000 USB transactions per second; each transaction can transfer at most 1022 (I think it was) bytes of payload. I do not know if USB 3.x always has the same limitations.
Also, Virtual COM protocol is designed so that packets are not to be transmitted until one of:
- packet is full; or
- accumulation timeout; the timeout corresponds to about 40 Hz; or
- the software requests that the driver "pushes" the packet. However, MATLAB does not provide any user-accessible way to request a push.
... Basically, if you need short latency or, response after sending less than about 1000 bytes, then USB is not an appropriate protocol.
By way of contrast, gigabit ethernet should in theory be able to handle about a million minimum-size packets per second, if I have estimated correctly. On a smal local LAN, gigabit ethernet should be able to reach more than 100 megabytes per second throughput for bulk transfers.
USB can be pretty convenient, but the covenience does lead to limitations that might or might not be of importance to you.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Input and Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!