最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】去确定USB转串口中的握手协议handshaking方面的支持

RS232 crifan 5665浏览 0评论

【背景】

对于手上已有的一个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通用客户端的:

  • hartclient.py
  • hartconfig.py
  • hartmsg.py

有空也去试试效果。

然后也加到这里:

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.
Also the timing may be affected since USB adds another layer on top of things, so if the device requires precise timing it may not work properly with a cable.

 

(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,看到这里:

Handshake of 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:

结果找到很多帖子:

pl2303-usb-serial

micropactech usb to serial

都提到了:

Supports Automatic handshake mode

对于这个:

Automatic handshake mode

(Automatic handshaking mode)

很不熟悉。

6.然后就去继续找参考资料。

不过,期间,对于:

Handshake of USB serial

提到的:

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

中貌似也的确是有截图证明此点:

silicon lab usb transfer analysis containing handshaking package

即:

其中就有对应的handshake package的。

以及,另外也提到了:

Bulk and interrupt transfers

  • Contains IN/OUT, Data, and handshake transactions
  • Bulk schedules transfers as bus bandwidth permits
  • Interrupt schedules transfers on regular intervals. Data may be delivered at a faster rate than the endpoint descriptor value.

另外还有:

transfer format for control buld interrput isochronous

不过:

此刻,突然发现:

此处的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
CCS CDC driver to the structure usb_cdc_carrier, check the sources.

意思是:

协议上是支持的,对应的实现对应的驱动,即可。

8.然后,看到这个:

Create a USB Virtual COM Port

更权威的解释:

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大全,的那个作者,在:

Create a USB Virtual COM Port

中解释的清楚。

需要的话,再去深入研究。

目前已经得知:

的确是USB CDC中,协议上,就支持RTS和CTS的

对应的命令是

SET_CONTROL_LINE_STATE

SERIAL_STATE

具体如何实现,如何使用。

就是接下来需要去搞懂的了。

转载请注明:在路上 » 【记录】去确定USB转串口中的握手协议handshaking方面的支持

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.184 seconds, using 22.07MB memory