def free(self): """Mark the solenoid as freed.""" LiveWindow.removeComponent(self) self.allocated.free(self.forwardChannel) self.allocated.free(self.reverseChannel) hal.freeSolenoidPort(self.forwardHandle) hal.freeSolenoidPort(self.reverseHandle) super().free()
def free(self): """Mark the solenoid as freed.""" LiveWindow.removeComponent(self) self.allocated.free(self.forwardChannel) self.allocated.free(self.reverseChannel) hal.freeSolenoidPort(self.forwardHandle) hal.freeSolenoidPort(self.reverseHandle) super().free()
def __init__(self, *args, **kwargs): """Constructor. Arguments can be supplied as positional or keyword. Acceptable positional argument combinations are: - forwardChannel, reverseChannel - moduleNumber, forwardChannel, reverseChannel Alternatively, the above names can be used as keyword arguments. :param moduleNumber: The module number of the solenoid module to use. :param forwardChannel: The forward channel number on the module to control (0..7) :param reverseChannel: The reverse channel number on the module to control (0..7) """ # keyword arguments forwardChannel = kwargs.pop("forwardChannel", None) reverseChannel = kwargs.pop("reverseChannel", None) moduleNumber = kwargs.pop("moduleNumber", None) if kwargs: warnings.warn("unknown keyword arguments: %s" % kwargs.keys(), RuntimeWarning) # positional arguments if len(args) == 2: forwardChannel, reverseChannel = args elif len(args) == 3: moduleNumber, forwardChannel, reverseChannel = args elif len(args) != 0: raise ValueError("don't know how to handle %d positional arguments" % len(args)) if moduleNumber is None: moduleNumber = SensorBase.getDefaultSolenoidModule() if forwardChannel is None: raise ValueError("must specify forward channel") if reverseChannel is None: raise ValueError("must specify reverse channel") super().__init__(moduleNumber) self.valueEntry = None SensorBase.checkSolenoidModule(moduleNumber) SensorBase.checkSolenoidChannel(forwardChannel) SensorBase.checkSolenoidChannel(reverseChannel) portHandle = hal.getPortWithModule(moduleNumber, forwardChannel) self.forwardHandle = hal.initializeSolenoidPort(portHandle) try: portHandle = hal.getPortWithModule(moduleNumber, reverseChannel) self.reverseHandle = hal.initializeSolenoidPort(portHandle) except Exception: # free the forward handle on exception, then rethrow hal.freeSolenoidPort(self.forwardHandle) self.forwardHandle = None self.reverseHandle = None raise self.forwardMask = 1 << forwardChannel self.reverseMask = 1 << reverseChannel # Need this to free on unit test wpilib reset Resource._add_global_resource(self) hal.report(hal.UsageReporting.kResourceType_Solenoid, forwardChannel, moduleNumber) hal.report(hal.UsageReporting.kResourceType_Solenoid, reverseChannel, moduleNumber) LiveWindow.addActuatorModuleChannel("DoubleSolenoid", moduleNumber, forwardChannel, self) self.__finalizer = weakref.finalize(self, _freeSolenoid, self.forwardHandle, self.reverseHandle)
def _freeSolenoid(fwdHandle, revHandle): hal.freeSolenoidPort(fwdHandle) hal.freeSolenoidPort(revHandle)
def __init__(self, *args, **kwargs) -> None: """Constructor. Arguments can be supplied as positional or keyword. Acceptable positional argument combinations are: - forwardChannel, reverseChannel - moduleNumber, forwardChannel, reverseChannel Alternatively, the above names can be used as keyword arguments. :param moduleNumber: The module number of the solenoid module to use. :param forwardChannel: The forward channel number on the module to control (0..7) :param reverseChannel: The reverse channel number on the module to control (0..7) """ # keyword arguments forwardChannel = kwargs.pop("forwardChannel", None) reverseChannel = kwargs.pop("reverseChannel", None) moduleNumber = kwargs.pop("moduleNumber", None) if kwargs: warnings.warn( "unknown keyword arguments: %s" % kwargs.keys(), RuntimeWarning ) # positional arguments if len(args) == 2: forwardChannel, reverseChannel = args elif len(args) == 3: moduleNumber, forwardChannel, reverseChannel = args elif len(args) != 0: raise ValueError( "don't know how to handle %d positional arguments" % len(args) ) if moduleNumber is None: moduleNumber = SensorUtil.getDefaultSolenoidModule() if forwardChannel is None: raise ValueError("must specify forward channel") if reverseChannel is None: raise ValueError("must specify reverse channel") super().__init__(moduleNumber) self.valueEntry = None SensorUtil.checkSolenoidModule(moduleNumber) SensorUtil.checkSolenoidChannel(forwardChannel) SensorUtil.checkSolenoidChannel(reverseChannel) portHandle = hal.getPortWithModule(moduleNumber, forwardChannel) self.forwardHandle = hal.initializeSolenoidPort(portHandle) try: portHandle = hal.getPortWithModule(moduleNumber, reverseChannel) self.reverseHandle = hal.initializeSolenoidPort(portHandle) except Exception: # free the forward handle on exception, then rethrow hal.freeSolenoidPort(self.forwardHandle) self.forwardHandle = None self.reverseHandle = None raise self.forwardMask = 1 << forwardChannel self.reverseMask = 1 << reverseChannel # Need this to free on unit test wpilib reset Resource._add_global_resource(self) hal.report( hal.UsageReporting.kResourceType_Solenoid, forwardChannel, moduleNumber ) hal.report( hal.UsageReporting.kResourceType_Solenoid, reverseChannel, moduleNumber ) self.setName("DoubleSolenoid", moduleNumber, forwardChannel) self.__finalizer = weakref.finalize( self, _freeSolenoid, self.forwardHandle, self.reverseHandle )
def _freeSolenoid(fwdHandle: hal.SolenoidHandle, revHandle: hal.SolenoidHandle) -> None: hal.freeSolenoidPort(fwdHandle) hal.freeSolenoidPort(revHandle)
def _freeSolenoid(solenoidHandle: hal.SolenoidHandle) -> None: hal.freeSolenoidPort(solenoidHandle)
def _freeSolenoid(solenoidHandle: hal.SolenoidHandle) -> None: hal.freeSolenoidPort(solenoidHandle)
def _freeSolenoid(solenoidHandle): hal.freeSolenoidPort(solenoidHandle)
def _freeSolenoid(modulePort, solenoidPort): hal.freeSolenoidPort(solenoidPort) hal.freePort(modulePort)
def _freeSolenoid(solenoidHandle): hal.freeSolenoidPort(solenoidHandle)