Skip to content

nutdrv_qx (Megatec) errors out after reading UPS data on Windows over USB CDC/COM #3452

@gfechine

Description

@gfechine

When using the nutdrv_qx driver with the megatec protocol on Windows (via a USB CDC/COM serial connection), the driver successfully reads exactly 47 bytes of data sent by the UPS in response to Q1. However, immediately after reading the 47th byte, it hangs for exactly 1 second, resulting in an I/O error (err 0) and a failure to preprocess the answer.

My hypothesis is that the Win32 serial wrapper (w32_serial_read) might be failing to correctly catch the \r terminator to close the read operation early, or there is an issue with the buffer/timeout configurations on Windows compared to Linux.

To Reproduce

Steps to reproduce the behavior:

  1. Run NUT 2.8.5 on Windows.
  2. Connect a UPS using the Megatec protocol over a virtual serial port (USB CDC/COM).
  3. Execute the driver directly with maximum debug level:
    .\nutdrv_qx -a tsshara -DDDD
  4. Observe the log where it reads exactly 47 bytes, waits exactly 1 second, and throws a timeout/I/O error.

Expected behavior

The read operation should complete successfully upon receiving the \r terminator (the 47th byte) and pass the buffer to qx_process without hitting the 1-second timeout.

Logs

   1.435648     [D3:tsshara] send: 'Q1'
   1.435839     [D4:tsshara] w32_serial_read : ulen 511, vmin_ -1, vtime_ 0, hEvent 0000000000000118
[...]
   1.639599     [D4:tsshara] w32_serial_read : total characters read = 46
   1.643466     [D4:tsshara] w32_serial_read : characters are available on input buffer
   1.643553     [D4:tsshara] w32_serial_read : Reading 1 characters
   1.643579     [D4:tsshara] w32_serial_read : total characters read = 47
   2.643838     [D4:tsshara] w32_serial_read : err 0
   2.644013     [D3:tsshara] read: Input/output error (-1)
   2.644143     [D4:tsshara] qx_process: failed to preprocess answer [input.voltage]

Environment / Desktop

  • OS: Windows (x86_64)
  • NUT Version: 2.8.5 (64-bit build for x86_64, built with gcc from MSYS2)
  • Installation method: Windows binaries
  • Device: TS Shara UPS via Serial (USB CDC/COM mapped to \\.\COM3)
  • Driver / Protocol: nutdrv_qx / megatec

Additional context

  • The same problem does not happen on Ubuntu, where I tested with the same configs.
  • By using PuTTY to connect directly to COM3 and sending Q1\r, the UPS responds immediately with:
    (231.0 231.0 116.0 011 60.0 27.2 41.0 00001000. This string length is exactly 46 characters + \r (47 bytes). The driver log clearly shows it successfully reading byte by byte up to that exact 47th byte (at 1.643s), at which point it halts and times out exactly 1.000 second later (at 2.643s).

Disclaimer: I have used AI to help me write this issue, since is my ever first issue and english is not my main language.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AIFor good or bad, machine tools are upon us. Humans are still the responsible ones.Connection stability issuesIssues about driver<->device and/or networked connections (upsd<->upsmon...) going AWOL over timeQx protocol driverDriver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some othersWindowsWindows-not-on-par-with-POSIXAspect of Windows builds known to be dysfunctional compared to POSIX builds; fix needed to be on parimpacts-release-2.8.5Issues reported against NUT release 2.8.5 (maybe vanilla or with minor packaging tweaks)serial port

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions