我想查看我的数据包格式:b'\x00\x01\x00\x00\x00\x06
但我看到的是这样的格式:\x00\x01\x06\x01\x03\
我怎么看这个?在
encoder=struct.pack('5B',int(trnsact,16),int(ident,16),int(length_data,16),int(unitid,16),int(func_code,16))
这就是我的价值观:
^{pr2}$和type(transaction_id)=string
(因此我将字符串值转换为整数)
如果我使用这种类型:
encoder=struct.pack('5B',transaction,ident,unitid,funcode)
我有这个错误:struct.error: required argument is not an integer
我对此很困惑请帮帮我 在
在Modbus TCP中:
transaction
是2Byte==Short==H
identifier
是2Byte==Short==H
length
是2Byte==Short==H
unitid
是1字节==B
fcode
是1字节==B
reg_addr
是2Byte==Short==H
count
是2Byte==Short==H
因此,在您的案例中,格式将是}:
>HHHBB
或{输出:
^{pr2}$[更新]:
不管怎样,如果您想这样(
b'\x00\x01\x00\x00\x00\x06
),请按以下步骤操作:输出:
[注意]:
B
是无符号字节。在H
是无符号短的。在<
是Little-Endian。在>
是Big-Endian。我用Python2.7和Python3.6测试这些代码片段。
struct.error: required argument is not an integer
错误,请使用withint(<hex-str>, 16)
相关问题 更多 >
编程相关推荐