【背景】
对于手上已有的一个USB转HART猫。
其内部是一个USB转串口的芯片:Silicon Labs的CP2102的USB to serial Bridge/Adaptor
现在的问题是:
想要使用该USB转HART猫去连接HART设备,
而对于HART协议来说,参考:
Help – Hart Generic Client Protocol
中的:
The use of Bell202 serial Hart modems implies the mandatory use of hardware handshaking. |
可知:
HART协议本身,就必须要实现对应的,物理上的handshaking
所以:
此处,对于此USB转HART(内部的USB转RS232)来说,需要搞懂
此处,对于USB转串口方面,是否支持握手协议,能否模拟物理上的RTS/CTS和DTS/DTR。
【折腾过程】
1.
(1)对应上面提到的:
pySerial
抽空好好去看看:
http://pyserial.sourceforge.net/
http://pyserial.sourceforge.net/shortintro.html
https://pypi.python.org/pypi/pyserial
(2)以及:
对应上面说的:
python版本的HART通用客户端的:
|
有空也去试试效果。
然后也加到这里:
2.后来看到:
PySerial not talking to Arduino
看到的是:
软件协议去实现模拟硬件握手协议时,是对应的添加timeout去等待物理上的握手的过程的。。。
3.对于很多USb直接转串口的话,之前就听某同事说过:
有些USB转串口,做得不够好,(或者本身是很低端的)
导致:
比如其中的handshaking,就支持的不够好,之类的。
对于这方面,网上也有人提及的:
(去搜,usb serial和真实的RS232 COM串口之间的区别,而找到的)
(1)
Serial to USB adaptors – types and problems
Yes, there are all sorts of pitfalls with serial to USB converters. Many just implement the minimum necessary for simple serial comms (i.e. Rx, Tx, maybe handshaking) and not any of the other pins. |
(2)
Real COM port vs. USB-to-Serial cable
sometimes USB – RS232 converters made by lower-end manufacturers have problems. especially with handshaking. If all else fails try a different manufacturer. |
4.而对于USB的serial,看到这里:
提到的是:
The handshake is done by the usb protokoll. |
所以,才去找:
USB的serial中,是否支持模拟handshaking的。
且,其中也提到了:
The USB endpoint has to be send a ack every time a packet is send. If you don’t read from the USBSerial the PC can’t send data. There are also Isochronous transfers without ack but they are used for audio. |
说是,对于USB转串口中对于handshaking的支持,是每次都要发送一个ACK包的。
5.然后也是后来才想起来,对应的USB串口,是:
USB CDC
这个类。
然后就去搜:
USB CDC support handshaking
看看USB CDC是否支持handshaking:
结果找到很多帖子:
都提到了:
Supports Automatic handshake mode |
对于这个:
Automatic handshake mode
(Automatic handshaking mode)
很不熟悉。
6.然后就去继续找参考资料。
不过,期间,对于:
提到的:
The USB endpoint has to be send a ack every time a packet is send. |
这里:
http://www.silabs.com/Support%20Documents/Software/USB_Overview.pdf
中貌似也的确是有截图证明此点:
即:
其中就有对应的handshake package的。
以及,另外也提到了:
Bulk and interrupt transfers
|
另外还有:
不过:
此刻,突然发现:
此处的USB协议中的handshake,并不是RS232流控制中的RTS/CTS或DTS/DTR(其也被叫做:串口通讯中的handshaking,就是我们前面所说的)
所以:
此处,control,bulk,interrupt中包含对应的handshake
并不能代表:对应的USB CDC,就能够真正的模拟RS232的handshaking,
即,不能代表:对应的USB CDC,就能够真正的模拟RS232的RTS/CTS(和DTS/DTR)
7.再去搜:
USB CDC rts cts
参考:
Using RTS\CTS with the USB CDC Virtual Com Port
提到了:
According to the CDC spec, the set_control_line_state request is used to to transmit RTS. It’s decoded in the |
意思是:
协议上是支持的,对应的实现对应的驱动,即可。
8.然后,看到这个:
更权威的解释:
In the SET_CONTROL_LINE_STATE request (22h), the host tells the device how to set the RS-232 control signals RTS and DTR. The host sends the control-line states in the third byte of the Setup transaction. Bit 0 is the state of DTR, and bit 1 is the state of RTS. Device firmware detects the request, accepts the data, and implements any changes to the bits. The IN transaction is the Status stage. The device indicates success by returning a ZLP. 。。。 The SERIAL_STATE notification provides a way for a device to send the states of the RS-232 status signals RI, DSR, and CD, the Break state, and error states for buffer overrun, parity error, and framing error. The notification consists of an 8-byte header and two notification bytes. The interrupt IN endpoint returns a notification or NAK in response to received IN token packets. The notification doesn’t include the state of RS-232’s CTS status signal. Device firmware can still read CTS on a local asynchronous port and take action as needed. For example, if a virtual COM-port device has data to send to a remote device that hasn’t asserted CTS, the virtual COM-port device can store the data in a buffer and wait to transmit. If the buffer is full, the virtual COM-port device can NAK attempts by the USB host to send more data. When the remote device asserts CTS, the virtual COM-port device can send the buffered data and accept new data from the host. To use CTS in this way, the USB host doesn’t need to know the state of CTS. If you want to use CTS in an unconventional way, such as having a host application read a switch state on a device, you’re out of luck with the CDC driver unless you can define a vendor-specific command that travels on the same bulk pipes that carry application data. |
这才是我所需要的:
的确是USB CDC中,协议上,就支持RTS和CTS的
对应的命令是
SET_CONTROL_LINE_STATE
SERIAL_STATE
具体如何实现,如何使用。
就是接下来需要去搞懂的了。
【总结】
还是,USB大全,的那个作者,在:
中解释的清楚。
需要的话,再去深入研究。
目前已经得知:
的确是USB CDC中,协议上,就支持RTS和CTS的
对应的命令是
SET_CONTROL_LINE_STATE
SERIAL_STATE
具体如何实现,如何使用。
就是接下来需要去搞懂的了。