0

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
    You've defined your problem (twice) as *it doesn't work*, which is an absolutely useless and meaningless problem description. What **specific** problem are you having? What **specifically** does *doesn't work* mean? If you're not sure why you need to be more specific, call your local auto repair shop and say *My car doesn't work. It's a Ford Fusion. What's wrong with it?* and see if they can help without having a lot more details. – Ken White Jun 30 '17 at 02:06
  • @KenWhite You are correct. The problem that I'm running into is it does not work, as with most posts on Stack Overflow. The question that I was asking for help on was, "Is it possible that Fusion 360 doesn't have access to the USB ports? If so, how could I fix it?" I'm almost 14, and this coding thing is all kinda new to me. I apologize for any confusion that I may have caused. I also really appreciate your response, so thank you. – Jesse Fryar Jul 04 '17 at 22:06

1 Answers1

0

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.