newAM / monitorcontrol

Python monitor controls using DDC-CI.
https://newam.github.io/monitorcontrol/
MIT License
177 stars 27 forks source link

Second successive input source retrieve fails #344

Open rosshardy opened 6 months ago

rosshardy commented 6 months ago

Steps to Reproduce

The following python code errors:

from monitorcontrol import get_monitors

try:
    with get_monitors()[1] as monitor: 
        inputsource = monitor.get_input_source()
        print(inputsource)

        inputsourceagain = monitor.get_input_source()
        print(inputsourceagain)
except Exception as e:
    print(f"An error occurred: {e}")

Output:

InputSource.HDMI2
An error occurred: failed to get VCP feature: An error occurred while transmitting data to the device on the I2C bus.
rosshardy commented 6 months ago

I think this is due to a second query too soon after the first. Adding a time.sleep(1) is a workaround, but it would be nice if maybe the library could handle this or provide better insight.

newAM commented 5 months ago

There are rate limits defined in the DDC-CI specification, on Linux these are adjustable: https://github.com/newAM/monitorcontrol/blob/6674ac35d2221013f4208d21284914b1f46aae78/monitorcontrol/vcp/vcp_linux.py#L35-L37

Those values should be enough as-is, but sometimes monitors need a little bit more time. Sadly in Windows these values are fixed; Microsoft is in the right here, but it does make workarounds like this necessary for some monitors :(