tobof / openhab-addons

The next-generation open Home Automation Bus (openHAB)
Eclipse Public License 2.0
39 stars 30 forks source link

Serial port does not reopen after being closed (exception says port is not found) #46

Closed arstorey closed 7 years ago

arstorey commented 7 years ago

First, thanks so much for creating this binding! Your efforts are truly appreciated!

FYI - This issue is happening on Windows 7 and may not be applicable to a *nix OS.

Removing the System.SetProperty call in the following code block in MySensorsSerialConnection.java fixes the error:

    //
    // Finally overwrite the "gnu.io.rxtx.SerialPorts" System property.
    //
    // Note: calling setProperty() is not threadsafe. All bindings run in
    // the same address space, System.setProperty() is globally visible
    // to all bindings.
    // This means if multiple bindings use the serial port there is a
    // race condition where two bindings could be changing the properties
    // at the same time
    //
    System.setProperty("gnu.io.rxtx.SerialPorts", finalPorts);

Internally, windows may represent the COM port names differently than COM1:COM2:COM3, etc so perhaps re-creating the list is causing the issue?

Thanks!

Alan

andreacioni commented 7 years ago

Hi Alan!

Thank to you for reporting this issue. Actually, on Mac OS and Linux distros I've not encountered your described behaviour. On Windows, personally, I've not tested the binding to much. But if the problem is really related to the System.setProperty call I think the best thing to do is to not calL it when binding runs on Windows machine. System.setProperty was add just to work around a problem on Linux/Mac serial port listing. Let me do a test.

Andrea

andreacioni commented 7 years ago

UPDATE: @arstorey I've not encountered that bug on my PC with Windows 10. Waiting @tobof for his opinion.

tobof commented 7 years ago

@arstorey With the latest change in OH2 according NRSerial (https://github.com/tobof/openhab2-addons/issues/45) I'm not sure if this block of code is needed anymore.

I've introduced updateSerialProperties(String devName) because only one binding was able to connect to serial ports. It was not possible to use RFXCOM & MySensors binding together.

We need someone who is able to test that. :-)