diff --git a/Python_script/almemo2490.py b/Python_script/almemo2490.py index 853190bb7b518b9cd31158f0147f91035420855e..2b59526a81895ac461c940484aa12c662827334d 100644 --- a/Python_script/almemo2490.py +++ b/Python_script/almemo2490.py @@ -20,7 +20,6 @@ import re from datetime import datetime import pandas as pd import numpy as np -import socket import traceback from functools import wraps @@ -29,7 +28,8 @@ from functools import wraps class err_hdl(Exception): # function for retry decorate object in case of exception - def do_retry(ExceptionToCheck = Exception, tries=4, delay=3, backoff=2, default_response = None): + def do_retry(ExceptionToCheck = Exception, tries=4, delay=3, backoff=2, \ + default_response = None): """Retry calling the decorated function using an backoff and defaults for return original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry @@ -65,7 +65,6 @@ class err_hdl(Exception): print('maximum number of retries [%d] reached\nfunction: %s\nmodule: %s' \ % (tries, function.__name__,function.__module__)) - return default_response return function_retry # true decorator @@ -89,10 +88,10 @@ class err_hdl(Exception): """ def exception_decorator(function): - def function_handle_exception(self, *args, **kwargs): + def function_handle_exception(*args, **kwargs): try: - return function(self, *args, **kwargs) + return function(*args, **kwargs) except ExceptionToCheck as e: @@ -101,8 +100,9 @@ class err_hdl(Exception): print(traceback.print_tb(e.__traceback__)) return default_response - - return function_handle_exception + + return function_handle_exception + return exception_decorator @@ -150,7 +150,7 @@ class almemo2490: # query function to send a command to almemo 2490 and # return the response to the command - def query(self, cmd_str, wait_time = 0.5): + def query(self, cmd_str, wait_time = 1): # send request to ALMEMO 2490 encode UTF8 with CR self.tn.write(bytes(cmd_str, encoding = 'utf8') + b'\r') @@ -204,7 +204,7 @@ class almemo2490: # method to get actual date from ALMEMO 2490 - @err_hdl.do_handle_exceptions(default_response = "01.01.1970") + @err_hdl.do_handle_exceptions(default_response = "01.01.70") def get_date(self): # request date from ALMEMO 2490 @@ -235,8 +235,7 @@ class almemo2490: # method to set channel name of selected channel at ALMEMO 2490 # channel name can be at max 10 characters # not allowed characters in name are white space charcters and semicolon - # channel numbers <= 9: string, format 'x.x' where x has to be within [0-9] - # channel numbers > 9: string, format 'x.xx' where x has to be within [0-9] + # numbmer format: 'xy' where x has to be [0-9] and y has be [0-1] @err_hdl.do_handle_exceptions() def set_channel_name(self, channel, channel_name): @@ -259,8 +258,7 @@ class almemo2490: # method to get channel name from selected channel at ALMEMO 2490 - # channel numbers <= 9: string, format 'x.x' where x has to be within [0-9] - # channel numbers > 9: string, format 'x.xx' where x has to be within [0-9] + # numbmer format: 'xy' where x has to be [0-9] and y has be [0-1] @err_hdl.do_handle_exceptions(default_response = "N/A") def get_channel_name(self, channel): @@ -299,9 +297,7 @@ class almemo2490: # to get fixed parameter (channel number, measurment name, measurment unit), # of a channel entry out of the read buffer search patterns are needed to identify them - # pattern for sens_channel: M\x.x or M\x.xx where x within [0-9] - # pattern for channel_unit: 1$\xx where x can be every character - # pattern for channel_name: 2$\xx where x can be every character without semicolon + search_patterns = {'sens_channel': r'([0-9]{2})', \ 'channel_unit': r'( [^ ]{2})', 'channel_name': r'([^ ]+ +\r)'} @@ -472,9 +468,9 @@ class almemo2490: def __exit__(self): self.close() - # # destructor of class - # def __del__(self): - # # self.close() + # destructor of class + def __del__(self): + self.close() diff --git a/Python_script/almemo710.py b/Python_script/almemo710.py index 8a7e00d35bc037a42badc43edb28aa75d9a36f06..70a7ccb36e25a2d0383ee540e5dc4ad590b0e5e1 100644 --- a/Python_script/almemo710.py +++ b/Python_script/almemo710.py @@ -20,7 +20,6 @@ import re from datetime import datetime import pandas as pd import numpy as np -import socket import traceback from functools import wraps @@ -29,7 +28,8 @@ from functools import wraps class err_hdl(Exception): # function for retry decorate object in case of exception - def do_retry(ExceptionToCheck = Exception, tries=4, delay=3, backoff=2, default_response = None): + def do_retry(ExceptionToCheck = Exception, tries=4, delay=3, backoff=2, \ + default_response = None): """Retry calling the decorated function using an backoff and defaults for return original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry @@ -65,7 +65,6 @@ class err_hdl(Exception): print('maximum number of retries [%d] reached\nfunction: %s\nmodule: %s' \ % (tries, function.__name__,function.__module__)) - return default_response return function_retry # true decorator @@ -89,10 +88,10 @@ class err_hdl(Exception): """ def exception_decorator(function): - def function_handle_exception(self, *args, **kwargs): + def function_handle_exception(*args, **kwargs): try: - return function(self, *args, **kwargs) + return function(*args, **kwargs) except ExceptionToCheck as e: @@ -101,8 +100,9 @@ class err_hdl(Exception): print(traceback.print_tb(e.__traceback__)) return default_response - - return function_handle_exception + + return function_handle_exception + return exception_decorator @@ -145,12 +145,12 @@ class almemo710: @err_hdl.do_retry(tries=5, delay=1, backoff=3) def open_connection(self): - return Telnet(self.ip_adress, 10001, self.timeout) # query function to send a command to almemo 710 and # return the response to the command - def query(self, cmd_str, wait_time = 0.5): + + def query(self, cmd_str, wait_time = 1): # send request to ALMEMO 710 encode UTF8 with CR self.tn.write(bytes(cmd_str, encoding = 'utf8') + b'\r') @@ -165,7 +165,6 @@ class almemo710: # decode receivved data with CP437 format decoded_read_buffer = read_buffer.decode('cp437') - # return received data return decoded_read_buffer @@ -236,8 +235,7 @@ class almemo710: # method to set channel name of selected channel at ALMEMO 710 # channel name can be at max 10 characters # not allowed characters in name are white space charcters and semicolon - # channel numbers <= 9: string, format 'x.x' where x has to be within [0-9] - # channel numbers > 9: string, format 'x.xx' where x has to be within [0-9] + # channel numbers: string, format 'x.x' where x has to be within [0-9] @err_hdl.do_handle_exceptions() def set_channel_name(self, channel, channel_name): @@ -260,8 +258,7 @@ class almemo710: # method to get channel name from selected channel at ALMEMO 710 - # channel numbers <= 9: string, format 'x.x' where x has to be within [0-9] - # channel numbers > 9: string, format 'x.xx' where x has to be within [0-9] + # channel numbers: string, format 'x.x' where x has to be within [0-9] @err_hdl.do_handle_exceptions(default_response = "N/A") def get_channel_name(self, channel): @@ -299,7 +296,7 @@ class almemo710: # to get fixed parameter (channel number, measurment name, measurment unit), # of a channel entry out of the read buffer search patterns are needed to identify them - # pattern for sens_channel: M\x.x or M\x.xx where x within [0-9] + # pattern for sens_channel: M\x.x where x within [0-9] # pattern for channel_unit: 1$\xx where x can be every character # pattern for channel_name: 2$\xx where x can be every character without semicolon search_patterns = {'sens_channel': r'(M\\[0-9]+\.{1}[0-9]+)', \ diff --git a/Python_script/play_with_almemo2490.py b/Python_script/play_with_almemo2490.py index 89a54c114da161dd2ac12608da1e7bb6bec72525..fecf80911ac46a7a56d696eebf6807bc6df218d4 100644 --- a/Python_script/play_with_almemo2490.py +++ b/Python_script/play_with_almemo2490.py @@ -9,6 +9,8 @@ Created on Mon Jan 2 16:55:57 2023 import almemo2490 # variables for selection in used methods +# numbmer format: 'xy' where x has to be [0-9] and y has be [0-1] +# x is the measurement channel and y is the sensor port sel_channel_no = '10' sel_channel_name = 'T,t' item = 0 @@ -50,7 +52,7 @@ try: # fetch parameter of selected measurement channel from meas_buffer of class object # input of channel name or channel number is possible - # numbmer format: 'x.x' or x.xx when number > 10 where is has to be [0-9] + # numbmer format: 'xy' where x has to be [0-9] and y has be [0-1] meas_channel_data, num_matches = almemo2490_obj. \ fetch_channel_param_from_meas_buffer(pattern = sel_channel_name, index = item) diff --git a/Python_script/play_with_almemo710.py b/Python_script/play_with_almemo710.py index ce3c0af626eca5f1023f808799793fe8fa4af465..79c88760e86aecfe312adc66d682e804c5aa79f5 100644 --- a/Python_script/play_with_almemo710.py +++ b/Python_script/play_with_almemo710.py @@ -9,7 +9,9 @@ Created on Mon Jan 2 16:55:57 2023 import almemo710 # variables for selection in used methods -sel_channel_no = '0.0' +# numbmer format: 'x.y' where x has to be [0-9] and y has be [0-9] +# x is the sensor port and y is the measurement channel +sel_channel_no = '0.1' sel_channel_name = 'T,t' item = 0 @@ -33,8 +35,8 @@ try: # set name of measurment channel 0.1 from almemo 710 almemo710_obj.set_channel_name(sel_channel_no,sel_channel_name) - # # request name of measurement channel from almemo 710 - # channel_name = almemo710_obj.get_channel_name(sel_channel_no) + # request name of measurement channel from almemo 710 + channel_name = almemo710_obj.get_channel_name(sel_channel_no) # request list of all sensors channels that are currently active # store this data in data frame of class_object @@ -50,7 +52,7 @@ try: # fetch parameter of selected measurement channel from meas_buffer of class object # input of channel name or channel number is possible - # numbmer format: 'x.x' or x.xx when number > 10 where is has to be [0-9] + # numbmer format: 'x.x' where is has to be [0-9] meas_channel_data, num_matches = almemo710_obj. \ fetch_channel_param_from_meas_buffer(pattern = sel_channel_name, index = item)