Why does PyQt5 block write access to another program ("server-based")?

2 weeks ago 11
ARTICLE AD BOX

I have been working to integrate a PyQt5 GUI with a third-party software from HighFinesse (makes wavemeters). I am using the minimal Python library here on Python 3.9 on a Windows 11 computer.

In terms of the "server-based" claim, "HighFinesse employs a fairly unique control system. First, one needs to install the control software, which is uniquely tied to a particular wavemeter and is supplied with it. In theory, software from another wavemeter might still work, but the results are not guaranteed. Second, this control software runs an application server which processes all requests from third-party software. This means, that the main application needs to be running to perform any device communication from the code. The code has an option of automatically starting it, but on some occasions it might fail, in which case it is necessary to either manually start it, or supply the location of the executable file.", as stated on the pyliblabs website.

When I run the following code in a .ipynb with the control software running locally (which is only shipped with the device), the code functions perfectly and switches the exposures as desired.

from wlm import WavelengthMeter wlm = WavelengthMeter(dllpath="C:\\Users\\mydllPath\\wlmData.dll") print(f"Exposure mode set: {wlm.SetExposureMode(0)}") # Returning false = manual mode print(f"Exposure 1 acquired: {wlm.GetExposure(array_index=1)} ") print(f"Exposure 2 acquired: {wlm.GetExposure(array_index=2)}") print(f"Exposure 1 set: {wlm.SetExposure(11, array_index=1)}") print(f"Exposure 2 set: {wlm.SetExposure(22, array_index=2)}") print(f"New exposure 1 acquired: {wlm.GetExposure(array_index=1)}") print(f"New exposure 2 acquired: {wlm.GetExposure(array_index=2)}")

It returns:

Exposure 1 acquired: 12 #preset Exposure 2 acquired: 18 #preset Exposure 1 set: 0 #success Exposure 2 set: 0 #success New exposure 1 acquired: 11 New exposure 2 acquired: 22

When I instead run this in the most bare-bones PyQt5 setting (I have stripped the GUI away; just running the code inside a QMainWindow):

from wlm import WavelengthMeter from PyQt5 import QtWidgets import sys class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() wlm = WavelengthMeter(dllpath="C:\\mydllPath\\wlmData.dll") print("Secondary exposure loop beginning now...") print(f"Exposure 1 acquired: {wlm.GetExposure(array_index=1)} ") print(f"Exposure 2 acquired: {wlm.GetExposure(array_index=2)}") print(f"Exposure 1 set: {wlm.SetExposure(10, array_index=1)}") print(f"Exposure 2 set: {wlm.SetExposure(20, array_index=2)}") print(f"New exposure 1 acquired: {wlm.GetExposure(array_index=1)}") print(f"New exposure 2 acquired: {wlm.GetExposure(array_index=2)}") if __name__ == "__main__": # print("Attempting initial exposure set") # print(f"Exposure 1 acquired: {wlm.GetExposure(array_index=1)} ") # print(f"Exposure 2 acquired: {wlm.GetExposure(array_index=2)}") # print(f"Exposure 1 set: {wlm.SetExposure(10, array_index=1)}") # print(f"Exposure 2 set: {wlm.SetExposure(20, array_index=2)}") # print(f"New exposure 1 acquired: {wlm.GetExposure(array_index=1)}") # print(f"New exposure 2 acquired: {wlm.GetExposure(array_index=2)}") app = QtWidgets.QApplication(sys.argv) MainWindow_object = MainWindow() MainWindow_object.show() sys.exit(app.exec_())

I instead get:

Exposure 1 acquired: 12 #preset Exposure 2 acquired: 18 #preset Exposure 1 set: -3 #unknown Exposure 2 set: -3 #unknown New exposure 1 acquired: 12 #did not change New exposure 2 acquired: 28 #did not change

More confusing is that if I run the commented out lines, they work perfectly like in the .ipynb. Thus, the final question is: does anyone know if PyQt5 has a tendency to block "send" commands to local servers? I find it bizarre that the QMainWindow has the ability to read the exposures perfectly but is unable to change the exposures. Thank you all in advance!

Read Entire Article