【发布时间】:2018-02-11 06:31:42
【问题描述】:
我正在制作自己的 3D 鼠标,有点像 3D Connexion's 自己的模型。我使用 Autodesk 的 Fusion 360 作为我的应用程序,并使用 Fusion 的 API(应用程序接口)与鼠标进行交互。我有一个陀螺仪+加速度计,可以将原始测量值发送到 Arduino 中,然后发送这些值(通过串行端口使用串行库)。然后,我使用 PySerial 库(因为 Fusion 的 API 使用 python 作为它的语言)来读取来自 Arduino 的数据,并将其发送到 Fusion 中,在那里我可以控制相机的位置。我遇到的问题是,为了测试,我可以使用 Python 脚本将陀螺仪 + 加速度计的值打印到命令提示符。但是当我在 Fusion 的代码编辑器(Spyder)中尝试完全相同的脚本时,它不起作用。我知道正在导入串行库,但脚本不起作用。 Fusion 360 是否可能无法访问 USB 端口?如果是这样,我该如何解决?
这是我的代码的一小段:
#This is a python script that when run in the CMD, it works just fine.
import serial
ser = serial.Serial()
ser.baudrate = 9600
ser.port = 'COM3'
ser.open()
while True:
result = ser.readline()
result = str(result)
print (result)
这段代码所做的只是读取连接到 Arduino 的电位器的值。然后它将这些值打印到 CMD 中。
这是来自 Fusion 360 API 的代码:
#This is the Fusion 360 code that doesn't work.
import adsk.core, adsk.fusion, adsk.cam, traceback
import serial
def get(app):
try:
ui = app.UserInterface
ser = serial.win32.Serial()
ser.baudrate = 9600
ser.port = 'COM3'
ser.open()
value = ser.read()
value = str(value)
adsk.doEvents()
ui.messageBox(value)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def Main():
try:
app = adsk.core.Application.Get()
ui = app.UserInterface
ui.messageBox("Everything is working till this point")
adsk.doEvents()
get(app)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Main()
exit()
提前致谢!
【问题讨论】:
-
您已将您的问题(两次)定义为它不起作用,这是一个绝对无用且毫无意义的问题描述。您遇到了什么具体问题? 具体 不起作用是什么意思?如果您不确定为什么需要更具体,请致电您当地的汽车维修店并说我的车坏了。这是福特Fusion。有什么问题? 看看他们是否可以在没有更多细节的情况下提供帮助。
-
@KenWhite 你是对的。我遇到的问题是它不起作用,就像 Stack Overflow 上的大多数帖子一样。我寻求帮助的问题是,“Fusion 360 是否可能无法访问 USB 端口?如果是,我该如何解决?”我快 14 岁了,这种编码对我来说有点新鲜。对于我可能造成的任何混乱,我深表歉意。我也非常感谢您的回复,非常感谢。