# Get available interfaces ret = llt.get_device_interfaces(available_interfaces_p, len(available_interfaces)) if ret < 1: raise ValueError("Error getting interfaces : " + str(ret)) ret = llt.set_device_interface(hLLT, available_interfaces[0]) if ret < 1: raise ValueError("Error setting device interface: " + str(ret)) # Connect ret = llt.connect(hLLT) if ret < 1: raise ConnectionError("Error connect: " + str(ret)) # Get available resolutions ret = llt.get_resolutions(hLLT, available_resolutions, len(available_resolutions)) if ret < 1: raise ValueError("Error getting resolutions : " + str(ret)) if resolution not in available_resolutions: raise AttributeError("Wrong resolution") # Scanner type ret = llt.get_llt_type(hLLT, ct.byref(scanner_type)) if ret < 1: raise ValueError("Error scanner type: " + str(ret)) # Scanner type ret = llt.set_resolution(hLLT, resolution) if ret < 1: raise ValueError("Error setting resolution: " + str(ret))
def connect(self, test=False): """Connect to the scanner and setup for measurement Raises: ValueError -- Getting interfaces failed ValueError -- Setting interface failed Exception -- Cant connect to interface ValueError -- Getting resolutions failed AttributeError -- Wrong resolutuion ValueError -- Error setting scanner type ValueError -- Error setting resolutin ValueError -- Error setting profile type ValueError -- Error setting transfer type """ # Parametrize transmission --- Important: make sure this is compliant # to sensor self.scanner_type = ct.c_int(0) # Init profile buffer and timestamp info available_resolutions = (ct.c_uint * 4)() available_interfaces = [ct.create_string_buffer(8) for i in range(6)] available_interfaces_p = (ct.c_char_p * 6)(*map(ct.addressof, available_interfaces)) self.hLLT = llt.create_llt_device() ret = llt.get_device_interfaces(available_interfaces_p, len(available_interfaces)) if ret < 1: raise ValueError("Error getting interfaces : " + str(ret)) if_index = 0 if_found = False for i, available_interface in enumerate(available_interfaces_p): if self.serial in available_interface: if_found = True if_index = i if not if_found: status( self.name, "Serial is not defined or not available, connecting to the first one", STATE.INFO) else: status(self.name, "Connecting to %s" % (self.serial)) ret = llt.set_device_interface(self.hLLT, available_interfaces[if_index]) if ret < 1: raise ValueError("Error setting device interface: " + str(ret)) # Connect ret = llt.connect(self.hLLT) if ret < 1: raise Exception("Error connect: " + str(ret)) if test: return # Get available resolutions ret = llt.get_resolutions(self.hLLT, available_resolutions, len(available_resolutions)) if ret < 1: raise ValueError("Error getting resolutions : " + str(ret)) if self.resolution not in available_resolutions: raise AttributeError("Wrong resolution") # Scanner type ret = llt.get_llt_type(self.hLLT, ct.byref(self.scanner_type)) if ret < 1: raise ValueError("Error scanner type: " + str(ret)) # Scanner type ret = llt.set_resolution(self.hLLT, self.resolution) if ret < 1: raise ValueError("Error setting resolution: " + str(ret)) # Set profile config ret = llt.set_profile_config(self.hLLT, llt.TProfileConfig.PROFILE) if ret < 1: raise ValueError("Error setting profile config: " + str(ret)) p = ct.c_void_p() # Register new packet callback ret = llt.register_buffer_callback( self.hLLT, llt.buffer_cb_func(new_packet_callback_wrapper), p) if ret < 1: raise ValueError("Error registering new packet callback: " + str(ret)) # Warm-up time time.sleep(0.2)