Trying to get Error when FT232H Adafruit Breakout is not plugged in

3 visualizaciones (últimos 30 días)
Hello, I am having an issue getting an error to show using MATLAB to connect to FT232H Adafruit Breakout via Python. I wanted to throw an error when the FT232H is not plugged in using a message box in Matlab. However, this was the only example code that I could find online. Is this the proper way of doing this? It seems like it's not catching the error properly when it is not plugged in.
try py.list(['x','y',1]) catch e e.message
%While there is a Python exception, adafruit_flag = 0.
while(isa(e,'matlab.exception.PyException'))
handles.adafruit_flag = 0;
e.ExceptionObject
button = questdlg('Error. Adafruit is not connected. If you want to reconnect, reconnect and press yes. Else press no to exit and close down Bode','Yes', 'No');
switch button
case 'Yes'
break;
case 'No'
%shutoff device
end
end

Respuesta aceptada

Sarah Crimi
Sarah Crimi el 28 de Ag. de 2018
I figured this out. You have to create a function in Python that flags the user if the Adafruit product ID is equal to what it is on your computer.
#!/usr/bin/python
import sys
import usb.core
def checkadafruit():
# find USB devices
dev = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
flag = 0
for cfg in dev:
#if int(cfg.idProduct) == 24596:
# print('yes')
a = int(cfg.idVendor)
b = int(cfg.idProduct)
c = 1027;
d=24596;
if b == d:
flag = flag + 1
else:
flag = flag + 0
return flag

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by