gpt4 book ai didi

python通过TCP套接字发送/接收十六进制数据

转载 作者:可可西里 更新时间:2023-11-01 02:55:28 29 4
gpt4 key购买 nike

我有一个以太网访问控制设备,据说可以通过 TCP 进行通信。
我如何通过输入十六进制数据来发送数据包,因为这是我从他们的手册中得到的(每个命令后发送和接收的通信数据包的标准格式)
您能否展示一些示例代码或链接以开始使用....

standard return packet from the terminal                               Size (bytes) BS (0x08) : ASCII Character         1STX (0x02) : ASCII Character        1 LENGTH : length from BS to ETX      4 TID : system unique I.D.            1 RESULT                              1 DATA : returned parameter           N CHECKSUM : byte sum from BS to DATA 1 ETX (0x03) : ASCII Character        1 
Standard command packet to the terminal                                 Size (bytes) ACK (0x06) : ASCII Character         1 STX (0x02) : ASCII Character         1 LENGTH : length from ACK to ETX      4 TID : system unique I.D. (ex: 1)     1 COMMAND                              1 Access Key(Optional)                 6 DATA : command parameter             N CHECKSUM : byte sum from ACK to DATA 1 ETX (0x03) : ASCII Character         1 This packet starts from ACK. In this packet, multiple byte value must be started from MSB. For example, if length was 10, LENGTH is 0x00 0x00 0x00 0x0a. 

最佳答案

只需将十六进制数据编码为字符串:

'\x34\x82\xf6'

关于python通过TCP套接字发送/接收十六进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2442704/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com