From fe9a280f574a823c21b9526e73272ccfd464434a Mon Sep 17 00:00:00 2001
From: cschrader <christian.schrader@ptb.de>
Date: Thu, 20 Feb 2025 14:48:21 +0100
Subject: [PATCH] Functions added to lmk.py.

- added exception for license warning
- minor reformatting
---
 README.md      |   2 +-
 pyproject.toml |   2 +-
 ttlmk/lmk.py   | 156 +++++++++++++++++++++++++++++++++----------------
 3 files changed, 109 insertions(+), 51 deletions(-)

diff --git a/README.md b/README.md
index 0881764..d64e1e0 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Import of TechnoTeam LMK images. Supports binary and text formats but actually o
 binary formats are tested.
 
 - camera images (*.pus)
-- luminance images )*.pf)
+- luminance images (*.pf)
 - color images (?)
 
 Format determined by internal file header, not by file name.
diff --git a/pyproject.toml b/pyproject.toml
index e8cd189..9ffeb2e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "ttlmk"
-version = "0.1.1"
+version = "0.1.2"
 authors = [
   { name="Christian Schrader", email="christian.schrader@ptb.de" },
 ]
diff --git a/ttlmk/lmk.py b/ttlmk/lmk.py
index 9451b64..dea1369 100644
--- a/ttlmk/lmk.py
+++ b/ttlmk/lmk.py
@@ -11,15 +11,17 @@ See  /TechnoTeam/LabSoft/doc/activexserver/class_l_m_k_ax_server.html
 import win32com.client
 import numpy as np
 
+
 class LMK_Error(Exception):
     def __init__(self, code, message, function=""):
         self.code = code
         self.message = message
         self.function = function
 
+
 class LMK(object):
     _handle = None
-    
+
     def __init__(self):
         self._handle = win32com.client.Dispatch("lmk4.LMKAxServer.1")
 
@@ -28,21 +30,21 @@ class LMK(object):
         err = None
         err_res = func(*args)
         if type(err_res) == int:
-            res=None
-            err=err_res
+            res = None
+            err = err_res
         else:
-            err=err_res[0]
-            res=err_res[1:]
+            err = err_res[0]
+            res = err_res[1:]
             if len(res) == 1:
-                res=res[0]
-        if err==0 or err==None:
+                res = res[0]
+        if err == 0 or err == None or err == 137363456:
             return res
         else:
-            msg=self._handle.iGetErrorInformation()[1]
+            msg = self._handle.iGetErrorInformation()[1]
             raise LMK_Error(err, msg, function=func_name)
 
     def SetNewCamera2(self, _qNameCamera, _qNameLens):
-        '''
+        """
         Set new camera calibration data.
 
         Parameters
@@ -56,14 +58,14 @@ class LMK(object):
         Returns
         ______
         0=ok, !=0 Error code
-        '''
-        func_name = 'iSetNewCamera2'
+        """
+        func_name = "iSetNewCamera2"
         func = self._handle.iSetNewCamera2
         args = [_qNameCamera, _qNameLens]
         return self._cmd(func_name, func, args)
 
     def Camera_GetParameter(self, _qname):
-        '''
+        """
         Read some additional camera properties.\n
         Parameter
         ________
@@ -79,14 +81,14 @@ class LMK(object):
         the string depends on the parameter itself. For example the gain
         is an integer value, the temperature is a floating point.
 
-        '''
-        func_name = 'iCamera_GetParameter'
+        """
+        func_name = "iCamera_GetParameter"
         func = self._handle.iCamera_GetParameter
         args = [_qname]
         return self._cmd(func_name, func, args)
 
     def GetIntegrationTime(self):
-        '''
+        """
         Return
         ________
         double &_drCurrentTime,
@@ -94,23 +96,23 @@ class LMK(object):
         double &_drNextTime,
         double &_drMinTime,
         double &_drMaxTime
-        '''
-        func_name = 'iGetIntegrationTime'
+        """
+        func_name = "iGetIntegrationTime"
         func = self._handle.iGetIntegrationTime
         args = []
         return self._cmd(func_name, func, args)
 
     def AutoScanTime(self):
-        '''
+        """
         autoset exposure time
-        '''
-        func_name = 'iAutoScanTime'
+        """
+        func_name = "iAutoScanTime"
         func = self._handle.iAutoScanTime
         args = []
         return self._cmd(func_name, func, args)
 
     def SetIntegrationTime(self, _dWishedTime):
-        '''
+        """
         Set new exposure time.
 
         Parameters
@@ -119,15 +121,16 @@ class LMK(object):
         _dWishedTime	Wished integration time
 
         _drRealizedTime	Realized integration time
-        '''
-        func_name = 'iSetIntegrationTime'
+        """
+        func_name = "iSetIntegrationTime"
         func = self._handle.iSetIntegrationTime
         args = [_dWishedTime]
         return self._cmd(func_name, func, args)
 
-    def Camera_GetSaturation(self, _iWholeImage=1, _iTop=0, _iLeft=0,
-                             _iBottom=0, _iRight=0, _drSaturation=0):
-        '''
+    def Camera_GetSaturation(
+        self, _iWholeImage=1, _iTop=0, _iLeft=0, _iBottom=0, _iRight=0, _drSaturation=0
+    ):
+        """
         Parameters
         __________
         _iWholeImage	- 1: Use whole image (_iTop, _iLeft,
@@ -141,36 +144,80 @@ class LMK(object):
         ____
         _drSaturation	Saturation of image or region in percent
         (values between 0.0 and 100.0, 100.0 = overdriven image or region)
-        '''
-        func_name = 'iCamera_GetSaturation'
+        """
+        func_name = "iCamera_GetSaturation"
         func = self._handle.iCamera_GetSaturation
         args = [_iWholeImage, _iTop, _iLeft, _iBottom, _iRight]
         return self._cmd(func_name, func, *args)
 
     def Grab(self):
-        '''
+        """
         Capturing a camera image
-        '''
-        func_name = 'iGrab'
+        """
+        func_name = "iGrab"
         func = self._handle.iGrab
         args = []
         return self._cmd(func_name, func, args)
 
     def SinglePic2(self, _dExposureTime):
-        '''
+        """
         Capturing a luminance image with SinglePic algorithm
 
         Parameters
         ____
         dExposureTime Exposure time to use
-        '''
-        func_name = 'iSinglePic2'
+        """
+        func_name = "iSinglePic2"
         func = self._handle.iSinglePic2
         args = [_dExposureTime]
         return self._cmd(func_name, func, args)
 
+    def MultiPic2(self, _dExposureTime, n):
+        """
+        Capturing a luminance image with SinglePic algorithm
+
+        Parameters
+        ____
+        dExposureTime Exposure time to use
+        """
+        func_name = "iMultiPic2"
+        func = self._handle.iMultiPic2
+        args = [_dExposureTime, int(n)]
+        return self._cmd(func_name, func, args)
+
+    def HighDynPic3(self, _dExposureTime, _dStartRatio=10, _dFactor=3, _iCountPic=1):
+        """
+        Capturing a luminance image with HiDynPic3 algorithm
+
+        Parameters
+
+        double 	_dExposureTime,
+        double 	_dStartRatio,
+        double 	_dFactor,
+        int 	_iCountPic
+        """
+        func_name = "iHighDynPic3"
+        func = self._handle.iHighDynPic3
+        args = [_dExposureTime, _dStartRatio, _dFactor, int(_iCountPic)]
+        return self._cmd(func_name, func, args)
+
+    def HighDynPic2(self, _dMaxTime, _dMinTime, _dFactor=3, _iCountPic=1):
+        """
+        Capturing a luminance image with HiDynPic3 algorithm
+
+        Parameters
+        double 	_dMaxTime,
+        double 	_dMinTime,
+        double 	_dFactor,
+        int 	_iPicCount  --> wird hier wie HighDynPic3 beibehalten
+        """
+        func_name = "iHighDynPic2"
+        func = self._handle.iHighDynPic2
+        args = [_dMaxTime, _dMinTime, _dFactor, int(_iCountPic)]
+        return self._cmd(func_name, func, args)
+
     def SaveImage(self, _iNumber, _qFileName):
-        '''
+        """
         Save Image
 
         Parameters
@@ -182,24 +229,33 @@ class LMK(object):
         -1 Color image
         0 or larger eval image
         _qFileName Destination file name
-        '''
-        func_name = 'iSaveImage'
+        """
+        func_name = "iSaveImage"
         func = self._handle.iSaveImage
         args = [_iNumber, _qFileName]
         return self._cmd(func_name, func, args)
 
     def Open(self):
-        '''
+        """
         öffnet LabSoft
-        '''
-        func_name = 'iOpen'
+        """
+        func_name = "iOpen"
         func = self._handle.iOpen
         args = []
-        print(func_name)
         return self._cmd(func_name, func, args)
 
+    def isOpen(self):
+        """
+        testet, ob Labsoft schon geöffnet ost
+        """
+        func_name = "iIsOpen"
+        func = self._handle.iIsOpen
+        args = []
+        # bricht die API!
+        return bool(self._handle.iIsOpen())
+
     def Close(self, _iQuestion=0):
-        '''
+        """
         Closes the Lmk4 application.
 
         Parameters
@@ -213,26 +269,28 @@ class LMK(object):
         ____
         0=ok, 1=User do not want to close the application, >1 Error code
 
-        '''
-        func_name = 'iClose'
+        """
+        func_name = "iClose"
         func = self._handle.iClose
         args = [_iQuestion]
 
         return self._cmd(func_name, func, args)
 
     def ImageGetDumpToMemory(self, nr, rowstart, rowend, colstart, colend):
-        # very slow! Better use SaveImage() to temporary file and 
+        # very slow! Better use SaveImage() to temporary file and
         # open it with lmk_image
-        func_name = 'iImageGetDumpToMemory'
+        func_name = "iImageGetDumpToMemory"
         func = self._handle.iImageGetDumpToMemory
         args = [nr, rowstart, rowend, colstart, colend]
         # FIXME: color images?
-        buff =  self._cmd(func_name, func, args)
-        img = np.frombuffer(buff, dtype=np.float32).reshape(rowend-rowstart+1,colend-colstart+1)
+        buff = self._cmd(func_name, func, args)
+        img = np.frombuffer(buff, dtype=np.float32).reshape(
+            rowend - rowstart + 1, colend - colstart + 1
+        )
         return img
 
     def SetFilterWheel(self, nr):
-        func_name = 'iSetFilterWheel'
+        func_name = "iSetFilterWheel"
         func = self._handle.iSetFilterWheel
         args = [nr]
         return self._cmd(func_name, func, args)
-- 
GitLab