Modbus problems when console is connected



  • Hello,
    I came across a strange situation while developing modbus client application. I wanted to connect console to my application for debugging purposes, but it seems to somehow mess with modbus module.
    On connection with modbus server I send a read request . When I run the application in Qt Creator without console in .pro file I get following results (in Qt Creator built-in console):

    qt.modbus: (RTU client) Sent Serial PDU: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x310300000026c1e0
    qt.modbus: (RTU client) Send successful: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Response buffer: "31034c55010102000100025c10761009c2988015f25bf4494d204f59535f4d534d36533830000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8"
    qt.modbus: (RTU client) Incomplete ADU received, ignoring
    qt.modbus.lowlevel: (RTU client) Response buffer: "31034c55010102000100025c10761009c2988015f25bf4494d204f59535f4d534d36533830000000000000000000000000000000000000000000000000000000000000000000000000000000000000c842"
    qt.modbus: (RTU client) Received ADU: "31034c55010102000100025c10761009c2988015f25bf4494d204f59535f4d534d36533830000000000000000000000000000000000000000000000000000000000000000000000000000000000000c842" 
    

    After adding console to config in .pro file, the application fails to get a correct response from the server:

    qt.modbus: (RTU client) Sent Serial PDU: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x310300000026c1e0
    qt.modbus: (RTU client) Send failed: 0x0300000026
    qt.modbus: (RTU client) Sent Serial PDU: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x310300000026c1e0
    qt.modbus: (RTU client) Send failed: 0x0300000026
    qt.modbus: (RTU client) Sent Serial PDU: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x310300000026c1e0
    qt.modbus.lowlevel: (RTU client) Response buffer: "42"
    qt.modbus: (RTU client) Modbus ADU not complete
    qt.modbus: (RTU client) Send failed: 0x0300000026
    qt.modbus.lowlevel: (RTU client) Response buffer: "4231034c55010102000100025c10761009c2988015f25bf4494d204f59535f4d534d36533830000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8"
    qt.modbus: (RTU client) Cannot calculate PDU size for function code: 49 , delaying pending frame
    qt.modbus.lowlevel: (RTU client) Response buffer: "4231034c55010102000100025c10761009c2988015f25bf4494d204f59535f4d534d36533830000000000000000000000000000000000000000000000000000000000000000000000000000000000000c842"
    qt.modbus: (RTU client) Cannot calculate PDU size for function code: 49 , delaying pending frame
    

    Is it possible that adding console impacts modbus module somehow? Or am i missing something?
    I'm not changing anything in code apart from CONFIG += console in .pro file.
    I run the application in debug mode, using QT 5.11.2 (Windows 10)

    Thanks in advance for any help.

    Edit: During further investigation I checked the same scenario on Qt modbus master example and the behaviour was similar:

    qt.modbus: (RTU client) Sent Serial PDU: 0x030000000a
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x31030000000ac03d
    qt.modbus: (RTU client) Send failed: 0x030000000a
    qt.modbus: (RTU client) Sent Serial PDU: 0x030000000a
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x31030000000ac03d
    qt.modbus: (RTU client) Send failed: 0x030000000a
    qt.modbus.lowlevel: (RTU client) Response buffer: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Received ADU: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Sent Serial PDU: 0x030000000a
    qt.modbus.lowlevel: (RTU client) Sent Serial ADU: 0x31030000000ac03d
    qt.modbus.lowlevel: (RTU client) Response buffer: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Received ADU: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Send failed: 0x030000000a
    qt.modbus.lowlevel: (RTU client) Response buffer: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Received ADU: "31031455010102000100025c10761009c2988015f25bf4f595"
    qt.modbus: (RTU client) Cannot match response with open request, ignoring
    

    QModbusRtuSerialMaster sends correct data (I used serial port sniffer to check data flow), but incorrectly assumes send was unsuccessful (qt.modbus: (RTU client) Send failed), so even when it gets correct response it cannot associate it with any request and therefore ignores it. That's the result I get maybe 95% times, every once in a while it manages to work correctly. Without console everything works fine. Can anyone replicate this issue on their setup? Thanks