def _freeRelay(*handles: List[hal.RelayHandle]) -> None: for handle in handles: try: hal.setRelay(handle, False) except: pass if handle: hal.freeRelayPort(handle)
def _freeRelay(*handles): for handle in handles: try: hal.setRelay(handle, False) except: pass if handle: hal.freeRelayPort(handle)
def set(self, value: Value) -> None: """Set the relay state. Valid values depend on which directions of the relay are controlled by the object. When set to kBothDirections, the relay can be set to any of the four states: 0v-0v, 12v-0v, 0v-12v, 12v-12v When set to kForwardOnly or kReverseOnly, you can specify the constant for the direction or you can simply specify kOff and kOn. Using only kOff and kOn is recommended. :param value: The state to set the relay. """ if value == self.Value.kOff: if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward ): hal.setRelay(self.forwardHandle, False) if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse ): hal.setRelay(self.reverseHandle, False) elif value == self.Value.kOn: if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward ): hal.setRelay(self.forwardHandle, True) if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse ): hal.setRelay(self.reverseHandle, True) elif value == self.Value.kForward: if self.direction == self.Direction.kReverse: raise ValueError( "A relay configured for reverse cannot be set to forward" ) if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward ): hal.setRelay(self.forwardHandle, True) if self.direction == self.Direction.kBoth: hal.setRelay(self.reverseHandle, False) elif value == self.Value.kReverse: if self.direction == self.Direction.kForward: raise ValueError( "A relay configured for forward cannot be set to reverse" ) if self.direction == self.Direction.kBoth: hal.setRelay(self.forwardHandle, False) if ( self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse ): hal.setRelay(self.reverseHandle, True) else: raise ValueError("Invalid value argument '%s'" % value)
def set(self, value): """Set the relay state. Valid values depend on which directions of the relay are controlled by the object. When set to kBothDirections, the relay can be set to any of the four states: 0v-0v, 12v-0v, 0v-12v, 12v-12v When set to kForwardOnly or kReverseOnly, you can specify the constant for the direction or you can simply specify kOff and kOn. Using only kOff and kOn is recommended. :param value: The state to set the relay. :type value: :class:`Relay.Value` """ if value == self.Value.kOff: if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward): hal.setRelay(self.forwardHandle, False) if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse): hal.setRelay(self.reverseHandle, False) elif value == self.Value.kOn: if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward): hal.setRelay(self.forwardHandle, True) if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse): hal.setRelay(self.reverseHandle, True) elif value == self.Value.kForward: if self.direction == self.Direction.kReverse: raise ValueError("A relay configured for reverse cannot be set to forward") if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kForward): hal.setRelay(self.forwardHandle, True) if self.direction == self.Direction.kBoth: hal.setRelay(self.reverseHandle, False) elif value == self.Value.kReverse: if self.direction == self.Direction.kForward: raise ValueError("A relay configured for forward cannot be set to reverse") if self.direction == self.Direction.kBoth: hal.setRelay(self.forwardHandle, False) if (self.direction == self.Direction.kBoth or self.direction == self.Direction.kReverse): hal.setRelay(self.reverseHandle, True) else: raise ValueError("Invalid value argument '%s'" % value)