Mission Planner + Python script, please help

 Hi everyone,

 I am using Mission Planner for a project. I need to get the altitude data out of the Mission Planner software via serial communication. To do so, I have tried to use a python script.  

 In my understanding from what I have read on the website 

http://planner.ardupilot.com/wiki/using-python-scripts-in-mission-planner/

 to add standard python libraries, I needed to add a line like 

sys.path.append(r"c:\python27\lib")to my code. I did that as well. But when I run the script in Mission Planner, I get an error, saying that
"Error running script Port is already open"
OR there is another error if I try to establish serial connection to Arduino Mega board from Mission Planner
"Error running script Access to the Port 'COM1' is denied"
How can I overcome this problem, what might be the reason for it?
You can my veery simple python script here as well.

#!/usr/bin/python

import sys
sys.path.append(r"c:\python27\lib")
sys.path.append(r"c:\Python27\Lib\pyserial-2.7")
import serial

print 'I am connected to Mission Planner!!!'

print 'I am alive!!!'

print cs.alt

print cs.pitch

ser = serial.Serial('COM1', 57600, timeout=10)
ser.open()
ser.write(float(cs.alt))

 Thank you all in advance for all the help!

 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  •  I have made some changes to the code, and was able to establish connection between the Mission Planner and a Virtual port. I have used a serial port monitor to see what was being passed from the serial connection.

     I also added some delays to my code, but actually am not sure which made it start to work.

     So, virtual port can be connected to Mission Planner. I will continue to work on making the same connection using a real port now!

     Wish me luck!

  • I'm a hardware guy, not a code demon, but I can tell you the biggest problem in your code is the COM1 declaration.

     

    As an example, Mission planner has no idea which COM port the ground radio is using until you select it from the drop down.  

    The same thing applies to the APM and Pixhawk.  When you connect via USB you have to wait for the  COM port drop down to show the device before you can click connect...

     

    •  Thank you Clifton for your help!

       I think the Arduino Mega board I am using (sometimes even Uno board) does not let the Mission Planner to send data through serial connection. I will continue to dig into that to figure it out!

  •  I really do not know why the fonts of the discussion is all mixed up. Sorry!

This reply was deleted.