Сценарий Python asyncio получил один TCP-пакет Modbus из трех - PullRequest
0 голосов
/ 25 сентября 2019

Я хочу прочитать данные с какого-то устройства, которого у меня еще нет.Итак, я использую Modbus Poll для тестирования моей программы на Python, и эта программа получает только 1 пакет из 3. Я скопировал скрипт примера, и он также получил только 1 пакет из 3.Что не так, как это исправить, чтобы получить все пакеты?Вот программа:

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.

Halp!: \

upd: я проверил WireShark - отправитель отправляет пакеты x001, x002, x003, x004, x005, x006, x007.

...