Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python asyncio脚本从三个服务器接收到一个Modbus TCP数据包_Python_Python Asyncio_Modbus Tcp - Fatal编程技术网

Python asyncio脚本从三个服务器接收到一个Modbus TCP数据包

Python asyncio脚本从三个服务器接收到一个Modbus TCP数据包,python,python-asyncio,modbus-tcp,Python,Python Asyncio,Modbus Tcp,我想从我还没有的设备上读取数据。所以,我使用Modbus Poll来测试我的Python程序,该程序只从3中获得1个数据包。我复制了示例脚本,它也只从3中获得了1个数据包。出了什么问题?如何修复它以获取所有数据包? 以下是节目: import asyncio async def handle_echo(reader, writer): data = await reader.read(100) message = data.decode() addr = writer

我想从我还没有的设备上读取数据。所以,我使用Modbus Poll来测试我的Python程序,该程序只从3中获得1个数据包。我复制了示例脚本,它也只从3中获得了1个数据包。出了什么问题?如何修复它以获取所有数据包? 以下是节目:

import asyncio

async def handle_echo(reader, writer):

    data = await reader.read(100)
    message = data.decode()
    addr = writer.get_extra_info('peername')

    print(f"Received {message!r} from {addr!r}")

    print(f"Send: {message!r}")
    writer.write(data)
    await writer.drain()

    print("Close the connection")
    writer.close()

async def main():
    server = await asyncio.start_server(handle_echo, '127.0.0.1', 5020)
    for i in range(0,len(server.sockets)):
        addr = server.sockets[i].getsockname()
        print(f'Serving on {addr}')

    async with server:
        await server.serve_forever()    

await main()
这里是输出:

Serving on ('127.0.0.1', 5020)
Received '\x001\x00\x00\x00\x06\x01\x03\x00\x00\x00\n' from ('127.0.0.1', 50298)
Send: '\x001\x00\x00\x00\x06\x01\x03\x00\x00\x00\n'
Close the connection
Received '\x004\x00\x00\x00\x06\x01\x03\x00\x00\x00\n' from ('127.0.0.1', 50299)
Send: '\x004\x00\x00\x00\x06\x01\x03\x00\x00\x00\n'
Close the connection
Received '\x007\x00\x00\x00\x06\x01\x03\x00\x00\x00\n' from ('127.0.0.1', 50300)
Send: '\x007\x00\x00\x00\x06\x01\x03\x00\x00\x00\n'
Close the connection
x001、x004、x007-事务标识符,它们必须是x001、x002、x003、x004、x005、x006、x007

哈尔普!:\


upd:我通过WireShark进行了检查-发件人发送x001、x002、x003、x004、x005、x006、x007数据包。

您确定发件人实际使用的是连续的交易ID号吗?据我所知,这是没有要求的,他们只是需要明确。不,我不确定。但发件人在交换过程中指示错误。