first post, I'm using a stepper motor with a 4A stepper interface, in windows, under Python.
Everything runs as expected, motor operates well but I have one problem : if I disconnect the USB interface while the program is running, it crashes with a recursive mutex error.
Enclosed here is a my setup, a simple sample code and output (The disconnect event is registered):
Setup :
-------
General
Python 3.12.8
OS : Windows 10
Library :
Name: phidget22
Version: 1.22.20250106
Stepper interface :
DeviceName: 4A Stepper Phidget
DeviceVersion: 110
Hub interface
Connected to :
Hub: HUB0002 (6-Port USB VINT Hub Phidget) v101
Sample code :
-------------
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.Stepper import *
class mot_class:
def __init__(self, parent=None):
self.info = ""
self.info2 = ""
self.status = 0
def init(self):
if self.status == 0:
try:
self.motor = Stepper()
self.motor.openWaitForAttachment(5000)
self.motor.setOnDetachHandler(self.onDetachMotor)
self.motor.setOnAttachHandler(self.onAttachMotor)
self.motor.open()
self.info="I/F connected"
self.status = 1
except PhidgetException as e:
return
def onAttachMotor(self,info):
self.info = "I/F reconnected"
self.info2 = info
self.status = 1
def onDetachMotor(self,info):
self.info = "I/F disconnected"
self.info2 = info
self.status = 0
if __name__ == "__main__":
mot=mot_class()
mot.init()
while 1:
print(str(mot.info) + " - " +str(mot.info2))
Output :
--------
(program is running and you pull the USB plug)
I/F connected -
I/F connected -
I/F connected -
I/F connected -
I/F disconnected - PhidgetStepper
I/F disconnected - PhidgetStepper
lock 00000001802D48C0 failed: recursive mutex enter
I/F disconnected - PhidgetStepper
recursive mutex
I/F disconnected - PhidgetStepper
(returns to prompt)
Note: I also have a force interface (bridge), and this one you can attach and reattach without problem.
Any help would be appreciated.
Sincerely,
Anthony.
Note : edited for insertion of code tags.