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

3 ビュー (過去 30 日間)
Sarah Crimi
Sarah Crimi 2018 年 8 月 17 日
回答済み: Sarah Crimi 2018 年 8 月 28 日
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

採用された回答

Sarah Crimi
Sarah Crimi 2018 年 8 月 28 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by