Ejemplo n.º 1
0
 def _send_dm_command(self, cmd, set_values=[]):
     """Send a command to the DigitalMicrograph script."""
     # If output file exists, delete it to ensure old return values are gone.
     # Use try_to_remove() because there may be delays in DM when
     # DM is writing to that file.
     if os.path.isfile(self.OUTPUT_FILE):
         utils.try_to_remove(self.OUTPUT_FILE)
     # Delete .ack and .ac2 files
     if os.path.isfile(self.ACK_FILE):
         os.remove(self.ACK_FILE)
     if os.path.isfile(self.ACK_CUT_FILE):
         os.remove(self.ACK_CUT_FILE)
     # Try to open input file
     success, input_file = utils.try_to_open(self.INPUT_FILE, 'w+')
     if success:
         input_file.write(cmd)
         for item in set_values:
             input_file.write('\n' + str(item))
         input_file.close()
         # Trigger DM script by renaming input file to command file
         try:
             os.rename(self.INPUT_FILE, self.COMMAND_FILE)
         except Exception as e:
             if self.error_state == 0:
                 self.error_state = 102
                 self.error_info = ('microtome._send_dm_command: could not '
                                    'rename input file (' + str(e) + ')')
     elif self.error_state == 0:
         self.error_state = 102
         self.error_info = ('microtome._send_dm_command: could not write '
                            'to input file')
Ejemplo n.º 2
0
 def _read_dm_return_values(self):
     """Try to read return file and, if successful, return values."""
     return_values = []
     success, return_file = utils.try_to_open('..\\dm\\DMcom.out', 'r')
     if success:
         for line in return_file:
             return_values.append(line.rstrip())
         return_file.close()
     elif self.error_state == 0:
         self.error_state = 104
         self.error_cause = ('microtome._read_dm_return_values: could not '
                             'read from return file')
     if return_values == []:
         return_values = [None, None]
     return return_values
Ejemplo n.º 3
0
 def _send_dm_command(self, cmd, set_values=[]):
     """Send a command to the DM script."""
     # First, if output file exists, delete it to ensure old values are gone
     if os.path.isfile('..\\dm\\DMcom.out'):
         os.remove('..\\dm\\DMcom.out')
     # Try to open command file:
     success, cmd_file = utils.try_to_open('..\\dm\\DMcom.in', 'w+')
     if success:
         cmd_file.write(cmd)
         for item in set_values:
             cmd_file.write('\n' + str(item))
         cmd_file.close()
         # Create new trigger file:
         success, trg_file = utils.try_to_open('..\\dm\\DMcom.trg', 'w+')
         if success:
             trg_file.close()
         elif self.error_state == 0:
             self.error_state = 102
             self.error_cause = ('microtome._send_dm_command: could not '
                                 'create trigger file')
     elif self.error_state == 0:
         self.error_state = 102
         self.error_cause = ('microtome._send_dm_command: could not write '
                             'to command file')
Ejemplo n.º 4
0
 def _read_dm_return_values(self):
     """Try to read output file and, if successful, return values."""
     return_values = []
     success, return_file = utils.try_to_open(self.OUTPUT_FILE, 'r')
     if success:
         for line in return_file:
             return_values.append(line.rstrip())
         return_file.close()
     elif self.error_state == 0:
         self.error_state = 104
         self.error_info = ('microtome._read_dm_return_values: could not '
                            'read from output file')
     if return_values == []:
         return_values = [None, None]
     return return_values