Does Fusion 360 not have access to USB ports by default?

421 Views Asked by At

I'm working on making my own 3D mouse, sort of like 3D Connexion's own model. I'm using Autodesk's Fusion 360 as my application, and Fusion's API(Application Program Interface) to interact with the mouse. I have a gyroscope + accelerometer that spits raw measurements into an Arduino, which then sends those values(through the serial port using the Serial library). I'm then using the PySerial library(because Fusion's API uses python for it's language) to read that data coming from the Arduino, and spit it into Fusion, where I can control the camera position. The issue that I'm running into is that, for testing, I can print the values of the gyro + accelerometer to the Command Prompt just fine with a Python script. But when I try the exact same script in Fusion's code editor(Spyder), it doesn't work. I know that the Serial library is being imported, but the script doesn't work. Is it possible that Fusion 360 doesn't have access to the USB ports? If so, how could I fix it?

Here is a little snipet of my code:

#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)

All that this code does, is it reads the value of a potentiometer hooked up to an Arduino. It then prints those values into the CMD.

Here is the code that comes from the 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()

Thanks in advance!

1

There are 1 best solutions below

0
TalkVideo Network On

In answer to your question, it may be so that Fusion360 does not have access to serial ports directly.

Fusion360 has a JavaScript API available and had to add custom calls to allow access to local machine resources like files.

(JavaScript does not have that natively).

That may be the nature of the problem you are up against, even though your program is written in Python. (I think F360 uses its JavaScript API to display its own User Interface).

Also, I see a difference between the code snippets:

ser = serial.win32.Serial() ... ser = serial.Serial()

Perhaps you can call the first program from F360, and simply write to a file or something like that, to test it.