Page 1 of 1

Better error if RCServo or DCMotor API Phidget opened elsewhere

Posted: Mon Jun 28, 2021 8:44 pm
by Rhybot
If one does the following in Python with Phidget22==1.7.20210504:
1. Instantiate an RCServo or DCMotor API and connect to it via openWaitForAttachment at a particular address (serial number + port + channel combo)
2. Command the RCServo or DCMotor API to move around
3. Instantiate an RCServo or DCMotor API later on, and attempt to connect to it at the same address: the attachment fails with no special details or error code

Can you add a new error code/description for a duplicate connection attempt?

Re: Better error if RCServo or DCMotor API Phidget opened elsewhere

Posted: Wed Jun 30, 2021 9:16 am
by mparadis
Did you set an error handler? There's already EPHIDGET_BUSY (Error 0x09) for this. This is what it looks like when you print the error string:

Code: Select all

Code: EEPHIDGET_BUSY
Description: Local device: <TMP1200 (RTD Phidget) v108 -> HUB0000 Port:0 S/N:561013> open failed because device is in use. Check that the Phidget is not already open in another program, such as the Phidget Control Panel, or another program you are developing.
Also if you're catching exceptions in your code, the Timeout exception will tell you if a matching device exists but is busy:

Code: Select all

Traceback (most recent call last):
  File "error.py", line 28, in <module>
    main()
  File "error.py", line 19, in main
    temperatureSensor0.openWaitForAttachment(5000)
  File "C:\Python27\lib\site-packages\Phidget22\Phidget.py", line 551, in openWaitForAttachment
    raise PhidgetException(result)
Phidget22.PhidgetException.PhidgetException: PhidgetException 0x03 (Timed Out)
Local device: <TMP1200 (RTD Phidget) v108 -> HUB0000 Port:0 S/N:561013> open failed because device is in use. Check that the Phidget is not already open in another program, such as the Phidget Control Panel, or another program you are developing.