简体   繁体   English

使用“ GNET”协议与USB设备进行串行通信

[英]serial communication with USB device using 'GNET' protocol

I have a USB device with the following specification . 我有一个具有以下规格的USB设备。 Page 22 describes the GNET protocol that should be used to interact with the device. 第22页描述了应用于与设备交互的GNET protocol

The connection is fine but the device just doesn't give me any response, so I think I am not sending the correct data to it, maybe missing the handshake? 连接很好,但是设备只是没有给我任何响应,所以我认为我没有向其发送正确的数据,也许错过了握手?

From Specification 从规格

Support TTY (TELE TYPE) OPERATION - Use TTY to send commands and messages 支持TTY(电话类型)操作-使用TTY发送命令和消息

Use ASCII value for each field and use Separator "," between two Fields. 对每个字段使用ASCII值,并在两个字段之间使用分隔符“,”。 在此处输入图片说明

connect_and_send.py connect_and_send.py

import serial

port = "COM3"
baud = 9600

ser = serial.Serial(port, baud, timeout=1)

if ser.isOpen():
    print(ser.name + ' is open...')

# STX, N, CR
to_send = b'\x02\x4e\x0d'
print "Sending {}".format(to_send)
ser.write(to_send)
out = ser.read()
print('Receiving...'+out)

COM3 is the correct port: COM3是正确的端口:

在此处输入图片说明

Any help and guidance would be greatly appreciated. 任何帮助和指导将不胜感激。

You have never​ to use \\x4e , this is the Negative Acknowledge from the device. 从来没有使用\\x4e ,这是从设备的否定应答
Try 尝试

to_send = b'\x02F\x0d'

to get Firmware Version 获取固件版本

I contacted the supplier in the end and the issue was setting to wrong baud rate. 最后,我与供应商联系,问题是波特率设置错误。 Changing from 9600 to 19200 resolved the problem. 从9600更改为19200可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM