Skip to content

Commit

Permalink
fixes small issue triggered by using PWM Phidgets with and without fu…
Browse files Browse the repository at this point in the history
…ll addressing in one command sequence
  • Loading branch information
MAKOMO committed Oct 28, 2024
1 parent 971929f commit 80cecda
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions src/artisanlib/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4195,9 +4195,10 @@ def phidgetBinaryOUTattach(self, channel:int, serial:Optional[str]=None) -> None
do.setIsRemote(False)
do.setIsLocal(True)
self.aw.ser.PhidgetDigitalOut[serial].append(do)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetDigitalOut[str(ser)] = self.aw.ser.PhidgetDigitalOut[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number
# self.aw.ser.PhidgetDigitalOut[str(ser)] = self.aw.ser.PhidgetDigitalOut[None]
try:
ch = self.aw.ser.PhidgetDigitalOut[serial][channel]
ch.setOnAttachHandler(self.phidgetOUTattached)
Expand All @@ -4210,7 +4211,8 @@ def phidgetBinaryOUTattach(self, channel:int, serial:Optional[str]=None) -> None
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort()) # NOTE: ch.getHubPort() returns -1 if not yet attached
self.aw.ser.PhidgetDigitalOut[str(si)] = self.aw.ser.PhidgetDigitalOut[None]
if si is not None:
self.aw.ser.PhidgetDigitalOut[si] = self.aw.ser.PhidgetDigitalOut[None]
except Exception: # pylint: disable=broad-except
pass

Expand Down Expand Up @@ -4329,9 +4331,14 @@ def phidgetOUTattach(self, channel:int, serial:Optional[str]=None) -> None:
do.setIsRemote(False)
do.setIsLocal(True)
self.aw.ser.PhidgetDigitalOut[serial].append(do)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetDigitalOut[str(ser)] = self.aw.ser.PhidgetDigitalOut[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number and serial:port number
# for sn in (str(ser) if port is None else [str(ser),f'{str(ser)}:{str(port)}']):
# self.aw.ser.PhidgetDigitalOut[sn] = self.aw.ser.PhidgetDigitalOut[None]
# self.aw.ser.PhidgetDigitalOutLastPWM[sn] = self.aw.ser.PhidgetDigitalOutLastPWM[None]
# self.aw.ser.PhidgetDigitalOutLastToggle[sn] = self.aw.ser.PhidgetDigitalOutLastToggle[None]

try:
ch = self.aw.ser.PhidgetDigitalOut[serial][channel]
if not ch.getAttached():
Expand All @@ -4344,7 +4351,10 @@ def phidgetOUTattach(self, channel:int, serial:Optional[str]=None) -> None:
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort())
self.aw.ser.PhidgetDigitalOut[str(si)] = self.aw.ser.PhidgetDigitalOut[None]
if si is not None:
self.aw.ser.PhidgetDigitalOut[si] = self.aw.ser.PhidgetDigitalOut[None]
self.aw.ser.PhidgetDigitalOutLastPWM[si] = self.aw.ser.PhidgetDigitalOutLastPWM[None]
self.aw.ser.PhidgetDigitalOutLastToggle[si] = self.aw.ser.PhidgetDigitalOutLastToggle[None]
except Exception: # pylint: disable=broad-except
pass

Expand Down Expand Up @@ -4618,9 +4628,10 @@ def phidgetVOUTattach(self, channel:int, serial:Optional[str]) -> None:
vo.setIsRemote(False)
vo.setIsLocal(True)
self.aw.ser.PhidgetAnalogOut[serial].append(vo)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetAnalogOut[str(ser)] = self.aw.ser.PhidgetAnalogOut[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number
# self.aw.ser.PhidgetAnalogOut[str(ser)] = self.aw.ser.PhidgetAnalogOut[None]
try:
ch = self.aw.ser.PhidgetAnalogOut[serial][channel]
ch.setOnAttachHandler(self.phidgetOUTattached)
Expand All @@ -4633,7 +4644,8 @@ def phidgetVOUTattach(self, channel:int, serial:Optional[str]) -> None:
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort())
self.aw.ser.PhidgetAnalogOut[str(si)] = self.aw.ser.PhidgetAnalogOut[None]
if si is not None:
self.aw.ser.PhidgetAnalogOut[si] = self.aw.ser.PhidgetAnalogOut[None]
try:
self.aw.ser.PhidgetAnalogOut[str(s)][channel].setEnabled(True) # the output on this device is always enabled
except Exception: # pylint: disable=broad-except
Expand Down Expand Up @@ -4741,9 +4753,10 @@ def phidgetDCMotorAttach(self, channel:int, serial:Optional[str] = None) -> None
dcm.setIsRemote(False)
dcm.setIsLocal(True)
self.aw.ser.PhidgetDCMotor[serial].append(dcm)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetDCMotor[str(ser)] = self.aw.ser.PhidgetDCMotor[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number
# self.aw.ser.PhidgetDCMotor[str(ser)] = self.aw.ser.PhidgetDCMotor[None]
try:
ch = self.aw.ser.PhidgetDCMotor[serial][channel]
ch.setOnAttachHandler(self.phidgetOUTattached)
Expand All @@ -4756,7 +4769,8 @@ def phidgetDCMotorAttach(self, channel:int, serial:Optional[str] = None) -> None
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort())
self.aw.ser.PhidgetDCMotor[str(si)] = self.aw.ser.PhidgetDCMotor[None]
if si is not None:
self.aw.ser.PhidgetDCMotor[si] = self.aw.ser.PhidgetDCMotor[None]
except Exception: # pylint: disable=broad-except
pass

Expand Down Expand Up @@ -5274,9 +5288,10 @@ def phidgetStepperAttach(self, channel:int, serial:Optional[str]=None) -> None:
stepper.setIsRemote(True)
stepper.setIsLocal(False)
self.aw.ser.PhidgetStepperMotor[serial].append(stepper)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetStepperMotor[str(ser)] = self.aw.ser.PhidgetStepperMotor[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number
# self.aw.ser.PhidgetStepperMotor[str(ser)] = self.aw.ser.PhidgetStepperMotor[None]

try:
ch = self.aw.ser.PhidgetStepperMotor[serial][channel]
Expand All @@ -5290,7 +5305,8 @@ def phidgetStepperAttach(self, channel:int, serial:Optional[str]=None) -> None:
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort())
self.aw.ser.PhidgetStepperMotor[str(si)] = self.aw.ser.PhidgetStepperMotor[None]
if si is not None:
self.aw.ser.PhidgetStepperMotor[si] = self.aw.ser.PhidgetStepperMotor[None]
except Exception: # pylint: disable=broad-except
pass

Expand Down Expand Up @@ -5385,9 +5401,10 @@ def phidgetRCattach(self, channel:int, serial:Optional[str]=None) -> None:
rcservo.setIsRemote(True)
rcservo.setIsLocal(False)
self.aw.ser.PhidgetRCServo[serial].append(rcservo)
if serial is None:
# we make this also accessible via its serial number
self.aw.ser.PhidgetRCServo[str(ser)] = self.aw.ser.PhidgetRCServo[None]
# this is not needed here as we add those a bit below on successful attach
# if serial is None:
# # we make this also accessible via its serial number
# self.aw.ser.PhidgetRCServo[str(ser)] = self.aw.ser.PhidgetRCServo[None]
try:
ch = self.aw.ser.PhidgetRCServo[serial][channel]
ch.setOnAttachHandler(self.phidgetOUTattached)
Expand All @@ -5400,7 +5417,8 @@ def phidgetRCattach(self, channel:int, serial:Optional[str]=None) -> None:
if serial is None and ch.getAttached():
# we make this also accessible via its serial number + port
si = self.serialPort2serialString(ch.getDeviceSerialNumber(),ch.getHubPort())
self.aw.ser.PhidgetRCServo[str(si)] = self.aw.ser.PhidgetRCServo[None]
if si is not None:
self.aw.ser.PhidgetRCServo[si] = self.aw.ser.PhidgetRCServo[None]
except Exception: # pylint: disable=broad-except
pass

Expand Down

0 comments on commit 80cecda

Please sign in to comment.