From 39d9678f35642a46ee9fe94cb72cfa2bc384f527 Mon Sep 17 00:00:00 2001 From: EricPei20 Date: Thu, 19 Feb 2026 16:11:28 -0800 Subject: [PATCH 1/5] Update client.py --- deapi/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deapi/client.py b/deapi/client.py index 7e74a4e..da5e24e 100644 --- a/deapi/client.py +++ b/deapi/client.py @@ -175,7 +175,7 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, tcp_no_delay) self.socket.setblocking(False) self.socket.settimeout(2) - + print('hello,world') self.cameras = self.__getStrings(self.LIST_CAMERAS) if logLevel == logging.DEBUG: log.debug("Available cameras: %s", self.cameras) From 902894e1167d56e734d733b100c40cf3c3d0e849 Mon Sep 17 00:00:00 2001 From: EricPei20 Date: Mon, 23 Feb 2026 17:56:56 -0800 Subject: [PATCH 2/5] #3384: Removed unnecessary code for camera selection from deapi. Also fixed some issues with 10_imageStatistics.py --- deapi/client.py | 106 ++++++------------ deapi/tests/original_tests/01_fps.py | 3 - deapi/tests/original_tests/02_hwRoisize.py | 3 - deapi/tests/original_tests/03_hwBinning.py | 3 - deapi/tests/original_tests/04_swBinning.py | 3 - deapi/tests/original_tests/05_swhwBinning.py | 3 - deapi/tests/original_tests/06_patternPixel.py | 3 - deapi/tests/original_tests/07_reference.py | 3 - deapi/tests/original_tests/08_virtmask.py | 3 - deapi/tests/original_tests/09_scanRoi.py | 3 - .../original_tests/10_imageStatistics.py | 31 ++--- deapi/tests/original_tests/func.py | 2 + deapi/tests/test_client.py | 9 -- 13 files changed, 55 insertions(+), 120 deletions(-) diff --git a/deapi/client.py b/deapi/client.py index da5e24e..3eec573 100644 --- a/deapi/client.py +++ b/deapi/client.py @@ -80,7 +80,7 @@ def set_log_level(self, level): return def __str__(self): - return f"Client(host={self.host}, port={self.port}, camera={self.get_current_camera()})" + return f"Client(host={self.host}, port={self.port}, camera={self.camera})" def _ipython_key_completions_(self): return self.list_properties() @@ -91,12 +91,12 @@ def _repr_html_(self): Host Port - Current Camera + Camera {self.host} {self.port} - {self.currCamera} + {self.camera}
@@ -175,13 +175,14 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False): self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, tcp_no_delay) self.socket.setblocking(False) self.socket.settimeout(2) - print('hello,world') - self.cameras = self.__getStrings(self.LIST_CAMERAS) - if logLevel == logging.DEBUG: - log.debug("Available cameras: %s", self.cameras) - self.currCamera = self.cameras[0] + + command = self._addSingleCommand(self.LIST_CAMERAS, None) + response = self._sendCommand(command) + if response != False: + self.camera = self.__getParameters(response.acknowledge[0])[0] + if logLevel == logging.DEBUG: - log.debug("Current camera: %s", self.currCamera) + log.debug("Camera: %s", self.camera) self.connected = True self.host = host @@ -257,11 +258,11 @@ def disconnect(self): self.connected = False log.info("Disconnected.") - def list_cameras(self) -> List[str]: + def get_camera(self): """ - List the available cameras on the server. + Get the camera on the server. """ - return self.cameras + return self.camera def get_virtual_mask(self, index): mask_name = f"virtual_mask{index}" @@ -276,34 +277,9 @@ def get_virtual_mask(self, index): ) = self.get_result(mask_name, DataType.DE8u, attributes=a) return res - def get_current_camera(self) -> str: - """ - Get the current camera on the server. - """ - if self.currCamera is None: - return "No current camera" - else: - return self.currCamera - - @write_only - def set_current_camera(self, camera_name: str = None): - """ - Set the current camera on the server. - """ - if camera_name is None: - return False - - self.currCamera = camera_name - - if logLevel == logging.DEBUG: - log.debug("current camera: %s", camera_name) - - self.refreshProperties = True - return True - def list_properties(self, options=None, search=None): """ - Get a list of property names from the current camera on DE-Server + Get a list of property names from the camera on DE-Server Parameters ---------- @@ -322,7 +298,7 @@ def list_properties(self, options=None, search=None): def list_registers(self, options=None, search=None): """ - Get a list of register names from the current camera on DE-Server + Get a list of register names from the camera on DE-Server for each register, it contains attributes: name of the register, address, Read only, value of the register Parameters @@ -345,7 +321,7 @@ def list_registers(self, options=None, search=None): ) def get_property_spec(self, property_name: str): """ - Get a list of allowed values for a property of the current camera on DE-Server + Get a list of allowed values for a property of the camera on DE-Server Deprecated since DE-MC 2.7.4 Parameters @@ -410,7 +386,7 @@ def get_property_spec(self, property_name: str): ) def get_property_specifications(self, property_name): """ - Get a list of allowed values for a property of the current camera on DE-Server + Get a list of allowed values for a property of the camera on DE-Server Only works for DE-MC version greater or equal to 2.7.4 Parameters @@ -477,7 +453,7 @@ def get_property_specifications(self, property_name): ) def get_property(self, property_name: str): """ - Get the value of a property of the current camera on DE-Server + Get the value of a property of the camera on DE-Server Parameters ---------- @@ -510,7 +486,7 @@ def get_property(self, property_name: str): def get_register(self, register_name: str): """ - Get the value of a register of the current camera on DE-Server + Get the value of a register of the camera on DE-Server Parameters ---------- @@ -565,7 +541,7 @@ def acquiring(self): @write_only def set_property(self, name: str, value): """ - Set the value of a property of the current camera on DE-Server + Set the value of a property of the camera on DE-Server Parameters ---------- @@ -601,7 +577,7 @@ def set_property(self, name: str, value): ) def set_property_and_get_changed_properties(self, name, value, changed_properties): """ - Set the value of a property of the current camera on DE-Server and get all + Set the value of a property of the camera on DE-Server and get all the changed properties. This is useful for testing and determining how certain properties affect others. @@ -643,7 +619,7 @@ def set_property_and_get_changed_properties(self, name, value, changed_propertie @write_only def set_register(self, name: str, value): """ - Set the value of a register of the current camera on DE-Server + Set the value of a register of the camera on DE-Server Parameters ---------- @@ -677,7 +653,7 @@ def set_register(self, name: str, value): @write_only def set_engineering_mode(self, enable, password): """ - Set the engineering mode of the current camera on DE-Server. Mostly for internal testing. + Set the engineering mode of the camera on DE-Server. Mostly for internal testing. Parameters ---------- @@ -720,7 +696,7 @@ def setEngModeAndGetChangedProperties(self, enable, password, changedProperties) @deprecated_argument(name="sizeY", since="5.2.0", alternative="size_y") def set_hw_roi(self, offset_x: int, offset_y: int, size_x: int, size_y: int): """ - Set the hardware region of interest (ROI) of the current camera on DE-Server. + Set the hardware region of interest (ROI) of the camera on DE-Server. Parameters ---------- @@ -762,7 +738,7 @@ def set_hw_roi(self, offset_x: int, offset_y: int, size_x: int, size_y: int): @deprecated_argument(name="sizeY", since="5.2.0", alternative="size_y") def SetScanSize(self, size_x, size_y): """ - Set the scan size of the current camera on DE-Server. + Set the scan size of the camera on DE-Server. """ t0 = self.GetTime() @@ -878,7 +854,7 @@ def set_hw_roi_and_get_changed_properties( self, offsetX: int, offsetY: int, sizeX: int, sizeY: int, changedProperties ): """ - Set the hardware region of interest (ROI) of the current camera on DE-Server and get all + Set the hardware region of interest (ROI) of the camera on DE-Server and get all the changed properties. This is useful for testing and determining how certain properties affect others. @@ -927,7 +903,7 @@ def set_hw_roi_and_get_changed_properties( @write_only def set_sw_roi(self, offsetX: int, offsetY: int, sizeX: int, sizeY: int): """ - Set the software region of interest (ROI) of the current camera on DE-Server. + Set the software region of interest (ROI) of the camera on DE-Server. Parameters ---------- @@ -970,7 +946,7 @@ def set_sw_roi(self, offsetX: int, offsetY: int, sizeX: int, sizeY: int): @deprecated_argument(name="useHW", since="5.2.0", alternative="use_hw") def set_binning(self, bin_x, bin_y, use_hw=True): """ - Set the binning of the current camera on DE-Server. If useHW is True, the binning will + Set the binning of the camera on DE-Server. If useHW is True, the binning will use hardware binning. If useHW is False, the binning will use software binning only. Note @@ -1034,7 +1010,7 @@ def set_sw_roi_and_get_changed_properties( self, offsetX, offsetY, sizeX, sizeY, changedProperties ): """ - Set the software region of interest (ROI) of the current camera on DE-Server and get all of + Set the software region of interest (ROI) of the camera on DE-Server and get all of the changed properties. This is useful for testing and determining how certain properties affect others. @@ -1085,7 +1061,7 @@ def set_adaptive_roi( self, size_x: int, size_y: int, offset_x: int = None, offset_y: int = None ): """ - Automatically choose the proper HW ROI and set SW ROI of the current camera on DE-Server. + Automatically choose the proper HW ROI and set SW ROI of the camera on DE-Server. If offset_x and offset_y are not provided, they will be centered on the camera. @@ -1133,7 +1109,7 @@ def set_adaptive_roi_and_get_changed_properties( self, offsetX, offsetY, sizeX, sizeY, changedProperties, timeoutMsec=5000 ): """ - Automatically choose the proper HW ROI and set SW ROI of the current camera on DE-Server and get all of + Automatically choose the proper HW ROI and set SW ROI of the camera on DE-Server and get all of the changed properties. This is useful for testing and determining how certain properties affect others. @@ -1742,7 +1718,7 @@ def get_result( @write_only def set_virtual_mask(self, id, w, h, mask): """ - Set the virtual mask of the current camera on DE-Server. + Set the virtual mask of the camera on DE-Server. Parameters ---------- @@ -1783,7 +1759,7 @@ def set_virtual_mask(self, id, w, h, mask): @write_only def setROI(self, offsetX, offsetY, sizeX, sizeY, useHWROI=False): """ - Set the region of interest (ROI) of the current camera on DE-Server. + Set the region of interest (ROI) of the camera on DE-Server. Parameters ---------- @@ -1838,7 +1814,7 @@ def setROI(self, offsetX, offsetY, sizeX, sizeY, useHWROI=False): def get_movie_buffer_info(self, movieBufferInfo=None, timeoutMsec=5000): """ - Get the movie buffer information of the current camera on DE-Server. + Get the movie buffer information of the camera on DE-Server. Parameters ---------- @@ -1873,7 +1849,7 @@ def get_movie_buffer( self, movieBuffer, movieBufferSize, numFrames, timeoutMsec=5000 ): """ - Get the movie buffer of the current camera on DE-Server. The movie buffer + Get the movie buffer of the camera on DE-Server. The movie buffer is a series of frames that are stored in memory and can be retrieved as a single buffer for faster processing. @@ -2565,11 +2541,6 @@ def _sendCommand(self, command: pb.DEPacket = None): if command is None: return False - if len(command.camera_name) == 0: - command.camera_name = ( - self.currCamera - ) # append the current camera name if necessary - try: packet = struct.pack("I", command.ByteSize()) + command.SerializeToString() res = self.socket.send(packet) @@ -2762,9 +2733,7 @@ def ParseChangedProperties(self, changedProperties, response): GetServerVersion = get_server_version Connect = connect Disconnect = disconnect - ListCameras = list_cameras - GetCurrentCamera = get_current_camera - SetCurrentCamera = set_current_camera + GetCamera = get_camera ListProperties = list_properties GetPropertySpec = get_property_spec # PropertyValidValues = property_valid_values @@ -2806,8 +2775,7 @@ def ParseChangedProperties(self, changedProperties, response): usingMmf = True debugImagesFolder = "D:\\DebugImages\\" connected = False - cameras = None - currCamera = "" + camera = "" refreshProperties = True exposureTime = 1 host = 0 diff --git a/deapi/tests/original_tests/01_fps.py b/deapi/tests/original_tests/01_fps.py index 5592903..d08337e 100644 --- a/deapi/tests/original_tests/01_fps.py +++ b/deapi/tests/original_tests/01_fps.py @@ -9,9 +9,6 @@ deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/02_hwRoisize.py b/deapi/tests/original_tests/02_hwRoisize.py index 20fa984..333c0ca 100644 --- a/deapi/tests/original_tests/02_hwRoisize.py +++ b/deapi/tests/original_tests/02_hwRoisize.py @@ -7,9 +7,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/03_hwBinning.py b/deapi/tests/original_tests/03_hwBinning.py index b773d0f..5cf241f 100644 --- a/deapi/tests/original_tests/03_hwBinning.py +++ b/deapi/tests/original_tests/03_hwBinning.py @@ -8,9 +8,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/04_swBinning.py b/deapi/tests/original_tests/04_swBinning.py index 7e45bd0..02dcc32 100644 --- a/deapi/tests/original_tests/04_swBinning.py +++ b/deapi/tests/original_tests/04_swBinning.py @@ -9,9 +9,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/05_swhwBinning.py b/deapi/tests/original_tests/05_swhwBinning.py index 9497be1..199298e 100644 --- a/deapi/tests/original_tests/05_swhwBinning.py +++ b/deapi/tests/original_tests/05_swhwBinning.py @@ -9,9 +9,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/06_patternPixel.py b/deapi/tests/original_tests/06_patternPixel.py index 33dd62f..d87c76a 100644 --- a/deapi/tests/original_tests/06_patternPixel.py +++ b/deapi/tests/original_tests/06_patternPixel.py @@ -11,9 +11,6 @@ deClient = DEAPI.Client() # Connect to the Server deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/07_reference.py b/deapi/tests/original_tests/07_reference.py index 8df5866..b5cfc35 100644 --- a/deapi/tests/original_tests/07_reference.py +++ b/deapi/tests/original_tests/07_reference.py @@ -9,9 +9,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/08_virtmask.py b/deapi/tests/original_tests/08_virtmask.py index 213fda3..2fa9320 100644 --- a/deapi/tests/original_tests/08_virtmask.py +++ b/deapi/tests/original_tests/08_virtmask.py @@ -10,9 +10,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version is: {serverVersion}") diff --git a/deapi/tests/original_tests/09_scanRoi.py b/deapi/tests/original_tests/09_scanRoi.py index d06bfa6..bcd4024 100644 --- a/deapi/tests/original_tests/09_scanRoi.py +++ b/deapi/tests/original_tests/09_scanRoi.py @@ -8,9 +8,6 @@ # Connect to the server deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] -deClient.SetCurrentCamera(camera) serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) print(f"Camera Name: {cameraName}, Server Software Version: {serverVersion}") diff --git a/deapi/tests/original_tests/10_imageStatistics.py b/deapi/tests/original_tests/10_imageStatistics.py index d91e487..53dca2e 100644 --- a/deapi/tests/original_tests/10_imageStatistics.py +++ b/deapi/tests/original_tests/10_imageStatistics.py @@ -1,3 +1,4 @@ +import math import sys import unittest import deapi as DEAPI @@ -22,8 +23,6 @@ deClient = DEAPI.Client() deClient.Connect() -cameras = deClient.ListCameras() -camera = cameras[0] serverVersion = deClient.GetProperty(propertyName.PROP_SERVER_SOFTWARE_VERSION) cameraName = deClient.GetProperty(propertyName.PROP_CAMERA_NAME) @@ -75,8 +74,7 @@ numPrecision = 6 frameCount = 1 -deClient.SetCurrentCamera(camera) -# deClient.SetProperty("Test Pattern", testPattern) +deClient.SetProperty("Test Pattern", testPattern) deClient.SetProperty(propertyName.PROP_INSTRUMENT_CLIENT_ADDRESS, "Manual") deClient.SetProperty( propertyName.PROP_INSTRUMENT_PROJECT_MAGNIFICATION, instrumentProjectMagnification @@ -139,6 +137,7 @@ def UpdateStats( def statisticsValueCheck(imageProcessingMode, correctionMode): + ret = True deClient.SetProperty(propertyName.PROP_IMAGE_PROCESSING_MODE, imageProcessingMode) deClient.SetProperty( propertyName.PROP_IMAGE_PROCESSING_FLATFIELD_CORRECTION, correctionMode @@ -163,14 +162,17 @@ def statisticsValueCheck(imageProcessingMode, correctionMode): print(f"imagemean: {attributes.imageMean}") print(stats.eppix) print(stats.epa2) - # Sometimes the float number are not equal due to the - func.compare2FloatValue(stats.eppix, attributes.eppix, numPrecision, "e-/pix") - func.compare2FloatValue(stats.eppixps, attributes.eppixps, numPrecision, "e-/pix/s") - func.compare2FloatValue(stats.eps, attributes.eps, numPrecision, "e-/s") - func.compare2FloatValue(stats.epa2, attributes.epa2, numPrecision, "e-/a^2") + # precision issue, we will compare the float number with a tolerance value. The tolerance value is set to 10**-numPrecision * frameCount for e-/pix, 10**-numPrecision * fps for e-/pix/s and 10**-numPrecision * fps * numPhysicalPixels for e-/s. + ret &= math.isclose(stats.eppix, attributes.eppix, rel_tol=0, abs_tol=10**-numPrecision * frameCount) + ret &= math.isclose(stats.eppixps, attributes.eppixps, rel_tol=0, abs_tol=10**-numPrecision * fps) + ret &= math.isclose(stats.eps, attributes.eps, rel_tol=0, abs_tol=10**-numPrecision * fps * numPhysicalPixels) + + ret &= func.compare2FloatValue(stats.epa2, attributes.epa2, numPrecision, "e-/a^2") + return ret def compareBin1Bin2(imageProcessingMode, correctionMode, swBinningFactor): + ret = True deClient.SetProperty(propertyName.PROP_IMAGE_PROCESSING_MODE, imageProcessingMode) deClient.SetProperty( propertyName.PROP_IMAGE_PROCESSING_FLATFIELD_CORRECTION, correctionMode @@ -210,12 +212,11 @@ def compareBin1Bin2(imageProcessingMode, correctionMode, swBinningFactor): swBinY, ) - func.compare2FloatValue(statsBin1.eppix, statsBin2.eppix, numPrecision, "e-/pix") - func.compare2FloatValue( - statsBin1.eppixps, statsBin2.eppixps, numPrecision, "e-/pix/s" - ) - func.compare2FloatValue(statsBin1.eps, statsBin2.eps, numPrecision, "e-/s") - func.compare2FloatValue(statsBin1.epa2, statsBin2.epa2, numPrecision, "e-/a^2") + ret &= func.compare2FloatValue(statsBin1.eppix, statsBin2.eppix, numPrecision, "e-/pix") + ret &= func.compare2FloatValue(statsBin1.eppixps, statsBin2.eppixps, numPrecision, "e-/pix/s") + ret &= func.compare2FloatValue(statsBin1.eps, statsBin2.eps, numPrecision, "e-/s") + ret &= func.compare2FloatValue(statsBin1.epa2, statsBin2.epa2, numPrecision, "e-/a^2") + return ret class TestPatternPixelValues(unittest.TestCase): diff --git a/deapi/tests/original_tests/func.py b/deapi/tests/original_tests/func.py index 0d3e48f..3c4ab7b 100644 --- a/deapi/tests/original_tests/func.py +++ b/deapi/tests/original_tests/func.py @@ -18,6 +18,8 @@ def compare2FloatValue(expectVal, actualVal, numPrecision, name): f"{name}: expect {round(expectVal, numPrecision)} actual {round(actualVal, numPrecision)}" ) return False + else: + return True def writeLogFile(caseName, scriptName): diff --git a/deapi/tests/test_client.py b/deapi/tests/test_client.py index 91bada1..b120744 100644 --- a/deapi/tests/test_client.py +++ b/deapi/tests/test_client.py @@ -34,15 +34,6 @@ def teardown(self): def test_client_connection(self, client): assert client.connected - def test_list_cameras(self, client): - cameras = client.list_cameras() - assert isinstance(cameras, list) - - def test_set_current_camera(self, client): - cameras = client.list_cameras() - client.set_current_camera(cameras[0]) - assert client.get_current_camera() == cameras[0] - def test_list_properties(self, client): properties = client.list_properties() assert isinstance(properties, list) From 96f454620d54a55156e700ae67097b8b19893513 Mon Sep 17 00:00:00 2001 From: EricPei20 Date: Tue, 24 Feb 2026 14:34:38 -0800 Subject: [PATCH 3/5] Added deprecated functions related to camera selection back to client.py --- deapi/client.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/deapi/client.py b/deapi/client.py index 3eec573..5de6026 100644 --- a/deapi/client.py +++ b/deapi/client.py @@ -258,11 +258,15 @@ def disconnect(self): self.connected = False log.info("Disconnected.") - def get_camera(self): + def list_cameras(self) -> List[str]: """ - Get the camera on the server. + Deprecated function. + List the available cameras on the server. """ - return self.camera + if logLevel == logging.DEBUG: + log.debug("list_cameras is deprecated.") + + return [self.camera] def get_virtual_mask(self, index): mask_name = f"virtual_mask{index}" @@ -276,6 +280,27 @@ def get_virtual_mask(self, index): _, ) = self.get_result(mask_name, DataType.DE8u, attributes=a) return res + + def get_current_camera(self) -> str: + """ + Get the current camera on the server. + """ + if self.camera == "": + return "No current camera" + else: + return self.camera + + @write_only + def set_current_camera(self, camera_name: str = None): + """ + Deprecated function. + Set the current camera on the server. + """ + + if logLevel == logging.DEBUG: + log.debug("set_current_camera is deprecated.") + + return True def list_properties(self, options=None, search=None): """ @@ -2733,7 +2758,9 @@ def ParseChangedProperties(self, changedProperties, response): GetServerVersion = get_server_version Connect = connect Disconnect = disconnect - GetCamera = get_camera + ListCameras = list_cameras + GetCurrentCamera = get_current_camera + SetCurrentCamera = set_current_camera ListProperties = list_properties GetPropertySpec = get_property_spec # PropertyValidValues = property_valid_values From 605fb623848e870d0338b27fc1e5d5db12faa88a Mon Sep 17 00:00:00 2001 From: EricPei20 Date: Tue, 24 Feb 2026 15:03:26 -0800 Subject: [PATCH 4/5] Changed logs in deprecated functions to log.error --- deapi/client.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/deapi/client.py b/deapi/client.py index 5de6026..1f4901f 100644 --- a/deapi/client.py +++ b/deapi/client.py @@ -263,8 +263,7 @@ def list_cameras(self) -> List[str]: Deprecated function. List the available cameras on the server. """ - if logLevel == logging.DEBUG: - log.debug("list_cameras is deprecated.") + log.error("list_cameras is deprecated.") return [self.camera] @@ -296,9 +295,7 @@ def set_current_camera(self, camera_name: str = None): Deprecated function. Set the current camera on the server. """ - - if logLevel == logging.DEBUG: - log.debug("set_current_camera is deprecated.") + log.error("set_current_camera is deprecated.") return True From d8f65259e8d10ae066548e24bb695b2c1f137805 Mon Sep 17 00:00:00 2001 From: EricPei20 Date: Wed, 25 Feb 2026 11:36:23 -0800 Subject: [PATCH 5/5] Ensure _sendCommand is backwards compatible with older server versions. Fixed some typos. --- deapi/client.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/deapi/client.py b/deapi/client.py index 1f4901f..44f9357 100644 --- a/deapi/client.py +++ b/deapi/client.py @@ -263,7 +263,7 @@ def list_cameras(self) -> List[str]: Deprecated function. List the available cameras on the server. """ - log.error("list_cameras is deprecated.") + log.warning("list_cameras is deprecated.") return [self.camera] @@ -295,7 +295,7 @@ def set_current_camera(self, camera_name: str = None): Deprecated function. Set the current camera on the server. """ - log.error("set_current_camera is deprecated.") + log.warning("set_current_camera is deprecated.") return True @@ -418,10 +418,10 @@ def get_property_specifications(self, property_name): """ t0 = self.GetTime() values = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.GET_PROPERTY_SPECIFICATIONS, property_name ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response == False: return None @@ -698,10 +698,10 @@ def setEngModeAndGetChangedProperties(self, enable, password, changedProperties) ret = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.SET_ENG_MODE_GET_CHANGED_PROPERTIES, None, [enable, password] ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -766,8 +766,8 @@ def SetScanSize(self, size_x, size_y): t0 = self.GetTime() ret = False - command = self.__addSingleCommand(self.SET_SCAN_SIZE, None, [size_x, size_y]) - response = self.__sendCommand(command) + command = self._addSingleCommand(self.SET_SCAN_SIZE, None, [size_x, size_y]) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -792,10 +792,10 @@ def SetScanSizeAndGetChangedProperties(self, size_x, size_y, changed_properties) t0 = self.GetTime() ret = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.SET_SCAN_SIZE_AND_GET_CHANGED_PROPERTIES, None, [size_x, size_y] ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -818,10 +818,10 @@ def SetScanROI(self, enable, offsetX, offsetY, sizeX, sizeY): t0 = self.GetTime() ret = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.SET_SCAN_ROI, None, [enable, offsetX, offsetY, sizeX, sizeY] ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -846,12 +846,12 @@ def SetScanROIAndGetChangedProperties( t0 = self.GetTime() ret = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.SET_SCAN_ROI__AND_GET_CHANGED_PROPERTIES, None, [enable, offsetX, offsetY, sizeX, sizeY], ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -1152,12 +1152,12 @@ def set_adaptive_roi_and_get_changed_properties( t0 = self.GetTime() ret = False - command = self.__addSingleCommand( + command = self._addSingleCommand( self.SET_ADAPTIVE_ROI_AND_GET_CHANGED_PROPERTIES, None, [offsetX, offsetY, sizeX, sizeY], ) - response = self.__sendCommand(command) + response = self._sendCommand(command) if response != False: ret = response.acknowledge[0].error != True self.refreshProperties = True @@ -2562,6 +2562,11 @@ def _sendCommand(self, command: pb.DEPacket = None): if command is None: return False + + if len(command.camera_name) == 0: + command.camera_name = ( + self.camera + ) # append the current camera name if necessary try: packet = struct.pack("I", command.ByteSize()) + command.SerializeToString()