【问题标题】:How do I send a packet in AutoIt?如何在 AutoIt 中发送数据包?
【发布时间】:2011-04-12 09:31:33
【问题描述】:

我想向 modbus/tcp 设备发送一些数据包来控制它。 我在 python 中的成功如下:

sdata = struct.pack('BBBBBBBBBBBBBBB',0x00,0x00,0x00,0x00,0x00,0x09,0x01,0x10,0x00,0x08,0x00,0x01,0x02,0x00,0x01)
sock.send(sdata)

而且效果很好;

但现在我不知道如何在 Autoit 中这样做。

我尝试这样做:

$szData = Binary("0x00,0x00,0x00,0x00,0x00,0x09,0x01,0x10,0x00,0x08,0x00,0x01,0x02,0x00,0x01");
TCPSend($ConnectedSocket, $szData)

但这不像上面的 python 源代码那样工作。

【问题讨论】:

标签: autoit


【解决方案1】:

AutoIt 不是 Python。 AutoIt Binary 函数的工作方式与 Python 中的 struct.pack 不同。 AutoIt 需要这样的输入:

$szData = Binary("0x000000000009011000080001020001")

如果您仍想像这样输入数据:“0x00,0x00,0x00,0x00”,那么您将不得不发明自己的二进制函数。一个简单的“hack”是:

Func _Binary($s)
   $b = StringReplace($s, ",0x", "") ; Replaces ,0x with empty string
   Return Binary($b)
EndFunc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-09
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多