GUI to make USB to serial communication.

4 次查看(过去 30 天)
I want to make a gui to make serial communication. I referred examples given here. But i want to make communication in such a way that 1. when i short pin 2 and pin 3 of RS232 cable only that time data will be display and other time it will only sent.
Now i crated a code by which when i press push button data will appear on display, without making short pin no 2 and pin no. 3

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-27
USB does not use RS232.
It is possible that you have an RS232 to USB adapter. Those adapters do not carry the actual RS232 signals. Instead, when polled for data by the USB master device, they respond with a packet of response, the first byte or two of which is a digital representation of the state of the signals ("on" or "off", 1 or 0), and the rest of which is data. The USB master device receives the data, and sets the pin statuses appropriately in a virtual serial status port, and puts the bytes into a buffer to be read. The actual state of the signals at the RS232 end cannot be measured on the host; it can just see the digital status of the pins as of the time the reading was taken.
In RS232, it is not possible to determine whether pin 2 (transmit) and pin 3 (receive) have been shorted. Data goes out on pin 2, data gets received on pin 3, and the device cannot tell that this is the result of a short and not the result of that particular data happening to be received right then.
Therefore the closest you could get would be to display everything you get on the (virtual) serial input, and not have the receive tied to transmit except when you want it to be. However you do need to be careful to tie the receive to ground when you do not have it shorted to transmit: if you leave it floating then because signal presence is determined by difference between receive and ground, a floating receive pin can have phantom input.
The easiest way to do all of this is to look for the existing code in the File Exchange.

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by