diff --git a/config/diffcalc/.nfs000000000035182b00000814 b/config/diffcalc/.nfs000000000035182b00000814 deleted file mode 100644 index e69de29..0000000 diff --git a/config/settings.properties b/config/settings.properties index 5ee9c13..16cc0f2 100644 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,4 +1,4 @@ -#Tue Feb 26 14:29:34 CET 2019 +#Tue Feb 26 14:32:52 CET 2019 count_time=1.0 geometry=fourcv roi=190 45 290 125 diff --git a/script/device/Image.py b/script/device/Image.py index 9d7a6b5..0a7e171 100644 --- a/script/device/Image.py +++ b/script/device/Image.py @@ -71,6 +71,11 @@ class Image(DeviceBase, Readable): def get_int(self, filename = None): if filename is None: filename = self.pixel.get_image_filename() + + print "Waiting image file: " + filename + wait_for_files([filename]) + + threshold1 = self.pixel.threshold1 threshold2 = self.pixel.threshold2 threshold3 = self.pixel.threshold3 diff --git a/script/local.py b/script/local.py index 18d3d2e..cec5993 100644 --- a/script/local.py +++ b/script/local.py @@ -1,8 +1,10 @@ ################################################################################################### # Deployment specific global definitions - executed after startup.py ################################################################################################### +import os import os.path + ################################################################################################### # Interlocks ################################################################################################### @@ -263,9 +265,66 @@ def append_diag_datasets(parent = None): log("Error sampling " + str(get_diag_name(f)) + ": " + str(sys.exc_info()[1])) - + ################################################################################################### # Configuration ################################################################################################### -set_geometry(get_geometry(),True) +def is_locked(filepath): + """Checks if a file is locked by opening it in append mode. + If no exception thrown, then the file is not locked. + """ + locked = None + file_object = None + if os.path.exists(filepath): + try: + print "Trying to open %s." % filepath + buffer_size = 8 + # Opening file in append mode and read the first 8 characters. + file_object = open(filepath, 'a', buffer_size) + if file_object: + print "%s is not locked." % filepath + locked = False + except IOError, message: + print "File is locked (unable to open in append mode). %s." % \ + message + locked = True + finally: + if file_object: + file_object.close() + print "%s closed." % filepath + else: + print "%s not found." % filepath + return locked + +def wait_for_files(filepaths): + """Checks if the files are ready. + + For a file to be ready it must exist and can be opened in append + mode. + """ + wait_time = 5 + for filepath in filepaths: + # If the file doesn't exist, wait wait_time seconds and try again + # until it's found. + while not os.path.exists(filepath): + print "%s hasn't arrived. Waiting %s seconds." % \ + (filepath, wait_time) + time.sleep(wait_time) + # If the file exists but locked, wait wait_time seconds and check + # again until it's no longer locked by another process. + while is_locked(filepath): + print "%s is currently in use. Waiting %s seconds." % \ + (filepath, wait_time) + time.sleep(wait_time) + + + +################################################################################################### +# Configuration +################################################################################################### + +set_geometry(get_geometry(),True) + + +