def open(self, id = -1, serialNumber = None):
        """
        Opens the U12.
        
        The Windows UW driver opens the device every time a function is called.
        The Exodriver, however, works like the UD family of devices and returns
        a handle. On Windows, this method does nothing. On Mac OS X and Linux,
        this method acquires a device handle and saves it to the U12 object.
        """
        if ON_WINDOWS:
            pass
        else:
            if self.debug: print("open called")
            devType = ctypes.c_ulong(1)
            openDev = staticLib.LJUSB_OpenDevice
            openDev.restype = ctypes.c_void_p
            
            
            if serialNumber is not None:
                numDevices = staticLib.LJUSB_GetDevCount(devType)
                
                for i in range(numDevices):
                    handle = openDev(i+1, 0, devType)
                    
                    if handle != 0 and handle is not None:
                        self.handle = ctypes.c_void_p(handle)
                        
                        try:
                            serial = self.rawReadSerial()
                        except Exception:
                            serial = self.rawReadSerial()
                        
                        if serial == int(serialNumber):
                            break
                        else:
                            self.close()
                    
                if self.handle is None:
                    raise U12Exception(serialNumber % "Couldn't find a U12 with a serial number matching %s")
                
            elif id != -1:
                numDevices = staticLib.LJUSB_GetDevCount(devType)
                
                for i in range(numDevices):
                    handle = openDev(i+1, 0, devType)
                    
                    if handle != 0 and handle is not None:
                        self.handle = ctypes.c_void_p(handle)
                        
                        try:
                            unitId = self.rawReadLocalId()
                        except Exception:
                            unitId = self.rawReadLocalId()
                        
                        if unitId == int(id):
                            break
                        else:
                            self.close()
                            
                if self.handle is None:
                    raise U12Exception("Couldn't find a U12 with a local ID matching %s" % id)
            elif id == -1:
                handle = openDev(1, 0, devType)
                
                if handle == 0 or handle is None:
                    raise Exception("Couldn't open a U12. Check that one is connected and try again.")
                else:
                    self.handle = ctypes.c_void_p(handle)
                    
                    # U12 ignores first command, so let's write a command.
                    command = [ 0 ] * 8
                    command[5] = 0x57 # 0b01010111
                    
                    try:
                        self.write(command)
                        self.read()
                    except:
                        pass

                    self.id = self.rawReadLocalId()
                
            else:
                raise Exception("Invalid combination of parameters.")
            
            
            if not self._autoCloseSetup:
                # Only need to register auto-close once per device.
                atexit.register(self.close)
                self._autoCloseSetup = True
dataset/ETHPy150Open LabPy/lantz/lantz/drivers/labjack/_internal/u12.py/U12.open/swapped operands of `%`