Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def off(self):
""" Turn laser off.
@return LaserState: actual laser state
"""
self.set_laser_state(LaserState.OFF)
return self.get_laser_state()
def get_laser_state(self):
""" Get laser state.
@return LaserState: current laser state
"""
diode = int(self.inst.query('?D'))
state = self.inst.query('?F')
if state in ('SYS ILK', 'KEY ILK'):
return LaserState.LOCKED
elif state == 'SYSTEM OK':
if diode == 1:
return LaserState.ON
elif diode == 0:
return LaserState.OFF
else:
return LaserState.UNKNOWN
else:
return LaserState.UNKNOWN
def get_laser_state(self):
""" Get laser operation state
@return LaserState: laser state
"""
if self.psu == PSUTypes.SMD6000:
state = self.inst.query('STAT?')
else:
state = self.inst.query('STATUS?')
if 'ENABLED' in state:
return LaserState.ON
elif 'DISABLED' in state:
return LaserState.OFF
else:
return LaserState.UNKNOWN
def updateButtonsEnabled(self):
""" Logic told us to update our button states, so set the buttons accordingly. """
self._mw.laserButton.setEnabled(self._laser_logic.laser_can_turn_on)
if self._laser_logic.laser_state == LaserState.ON:
self._mw.laserButton.setText('Laser: ON')
self._mw.laserButton.setChecked(True)
self._mw.laserButton.setStyleSheet('')
elif self._laser_logic.laser_state == LaserState.OFF:
self._mw.laserButton.setText('Laser: OFF')
self._mw.laserButton.setChecked(False)
elif self._laser_logic.laser_state == LaserState.LOCKED:
self._mw.laserButton.setText('INTERLOCK')
else:
self._mw.laserButton.setText('Laser: ?')
self._mw.shutterButton.setEnabled(self._laser_logic.has_shutter)
if self._laser_logic.laser_shutter == ShutterState.OPEN:
self._mw.shutterButton.setText('Shutter: OPEN')
elif self._laser_logic.laser_shutter == ShutterState.CLOSED:
self._mw.shutterButton.setText('Shutter: CLOSED')
elif self._laser_logic.laser_shutter == ShutterState.NOSHUTTER:
self._mw.shutterButton.setText('No shutter.')
else:
self._mw.laserButton.setText('Shutter: ?')
def set_laser_state(self, status):
""" Set desited laser state.
@param LaserState status: desired laser state
@return LaserState: actual laser state
"""
actstat = self.get_laser_state()
if actstat != status:
if status == LaserState.ON:
self.inst.query('ON')
elif status == LaserState.OFF:
self.inst.query('OFF')
return self.get_laser_state()
def get_laser_state(self):
""" Get laser operation state
@return LaserState: laser state
"""
if self.psu == PSUTypes.SMD6000:
state = self.inst.query('STAT?')
else:
state = self.inst.query('STATUS?')
if 'ENABLED' in state:
return LaserState.ON
elif 'DISABLED' in state:
return LaserState.OFF
else:
return LaserState.UNKNOWN
def off(self):
""" Turn laser off.
@return LaserState: actual laser state
"""
return self.set_laser_state(LaserState.OFF)