Jump to content
  • 0

Analog Discovery 2... How do I handle "Device is busy" message


eradarhughes

Question

I've searched past content and I've been unable to find a complete answer on how to handle a "Device is busy" error message on an Analog Discover 2's.    

Setup:

  • Raspberry Pi 4B 8GB RAM
  • Raspberry Pi OS 32-bit (full version -- not headless, but without monitor)
  • 128 GB fast SD-Card
  • AD2 with USB connection to Raspberry Pi USB port (USB 3)
  • AD2 powered separately
  • There are three of these setups (Pi+AD2+Power+Network) operating remotely on the same network, with all communicating back to a central monitoring PC
  • Hardware runs 24 hours/day, 7 days a week.
  • AD2 is being used for:
    • Waveform generation for an RF emitter
    • ADC for incoming signals.Real-time operation.
    • Real-time operation
  • 100% Python3 script running AD2, network, and processing tasks
  • Autostart (.desktop) launches script on bootup (due to chmod -x)

The remote locations will occasionally and unexpectedly power cycle.  There is no graceful closing of software or any devices when this happens.    When this occurs, the application script will autostart when power is restored and the program tries to reconnect to all devices.   (This includes re-establishing network connection back at the central command station PC.)   The AD2 gives the device is busy error message on all 3 setups every time -- without exception.    The script that launches the AD2 is the only script initiated at startup.

I tried the attached script segment to capture errors and to attempt to timeout the condition.    But it doesn't work.  It will just keep looping and supply a continuous device is busy message.  My patience only permitted me to watch this for 5 minutes, but I would assume it will be indefinite.   You can see that much of this code comes straight out of the sample scripts that comes with installation of of the Waveform API.  

Currently the fix is to just restart the program.  Doing so will automatically free up the device and the script will run properly    Having the customer to kill the application and restart it is not ideal.  Is there a solution for this?    

I suspect that perhaps this might be a previous state that is somehow stored or that the device is busy still booting itself while the script is launched.  Unsure as to what may actually be happening, can someone help me?    My apologizes for the novella, but I wanted to supply as much detail as possible.

 


 

AD2 Startup Python Script

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @eradarhughes

Try to reload the dwf library, I think in Python is: del dwf; dwf = cdll.LoadLibrary(...)

This library uses the adept.runtime for device access which utilizes a shared device table with info (sn, busy...) On app/script crash the busy flag could remain set.
The table is erased when all the adept libraries are detached. If you are running other apps using dwf or other adept libraries those should also restart or reload the libs.

Link to comment
Share on other sites

  • 0

Thanks for responding to my question.      I tried the del dwf and reloading the library and it didn't make a difference.   I do not have any other application running.     I did try adding some addition sleep time after and before these calls and that too had no effect.

 

 

Link to comment
Share on other sites

  • 0

 

Hi @eradarhughes

Are you calling FDwfDeviceClose(All) in your script?

You could try the following to have a software device reconnect but this would fail if the device is kept open by any process:

import sys
from ctypes import *

if sys.platform.startswith("win"):
    ftd = windll.ftd2xx
elif sys.platform.startswith("darwin"):
    ftd = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/Frameworks/libftd2xx.dylib")
else:
    ftd = cdll.LoadLibrary("libftd2xx.so")

ver = c_uint()
ftd.FT_GetLibraryVersion(byref(ver))
print("FTDI Version: "+hex(ver.value))

cDev = c_int()
if ftd.FT_CreateDeviceInfoList(byref(cDev)) != 0 :
    print("FT_CreateDeviceInfoList failed")
    quit()

print("Devices: "+str(cDev.value))

for i in range(cDev.value):
    hif = c_void_p(0)
    if ftd.FT_Open(c_int(i), byref(hif)) != 0 :
        print("Failed FT_Open")
        continue
    if ftd.FT_CyclePort(hif) != 0 :
        print("Failed FT_CyclePort")

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...