pycanaero, a python binding to the C++ library to access CAN Aerospace over UDP

INTRODUCTION

This library allows an easy, reliable and fast access to CAN aerospace over network. It uses UDP multicast to feed multiple clients with flight data from a variety of flight simulators. Currently Laminar Research X-Plane (R) and Microsoft Flight Simulator (R) are supported. The list of simulators will expand in the future.

FEATURES

PREREQUISITES

On Windows, you need to have the Visual C++ 2010 x86 redistributables installed. They can be obtained from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84

USAGE SUMMARY

  1. install the libcanaero python module
  2. import libcanaero
  3. create a Receiver instance
  4. Inform the receiver instance which data you want to receive from or send to the network.
  5. Call Receiver.run() from your application's main loop or another thread

EXAMPLE

A minimum example on how to interact with a CAN Aerospace enabled simulator:

 # the threading library of python will easily execute the Receiver.run() function in background
 import threading

 # by importing all of libcanaero, we also get all the ID shortcuts
 from libcanaero import *

 # I will use this to quit the program by entering a non-integer value
 def isint(value):
   try:
     int(value)
     return True
   except:
     return False

 # This is an example of how you can execute the Receiver.run() function in a separate thread
 class AsyncReceiverRun(threading.Thread):
   def __init__(self, receiver):
     threading.Thread.__init__(self)
     self.recv = receiver
     self.continue_to_run = True
   def run(self):
     while self.continue_to_run:
       recv.run()
   def stop(self):
     self.continue_to_run = False

 # the minimum revision of the SCS identifier distribution this program needs
 revision_required = 1

 # create a receiver and announce ourselves to the bus
 recv = Receiver(revision_required)

 # this is the callback for the COM frequency. COM freqs are transmitted in kHz
 def comfreq( freq ):
   print "COM 1 freq is now %f\n" % (freq/1000.0)

 # this is the callback for the landing lights switch
 def landlight ( on ):
   if on:
     print "landing lights on"
   else:
     print "landing lights off"

 # this callback will print the EGT values of the engines.
 # EGT is transmitted in degrees Kelvin.
 def egt ( egt_array ):
   print "# | deg Celsius"
   i = 1
   for egt_val in egt_array:
     print "%(engine)d | %(value)f" %{'engine': (i), 'value': (egt_val - 273.2)}
     i+=1
   print "\n"

 # request the COM1 freq and bind it to the callback
 # note that this freq is transmitted as in integer, hence the I function
 recv.requestDataI(COM1_FREQ_KHZ.Id(), comfreq)

 # do the same for the landing light
 # note that the switch is transmitted as a bool, hence the B function
 recv.requestDataB(LIGHT_LANDING_SWITCH.Id(), landlight)

 # and finally, the EGT values
 # note that the engine values are transmitted as a vector of floats, hence the VF function
 recv.requestDataVF(ENG_EGT_K.Id(), egt)

 # start the receiver in background
 background = AsyncReceiverRun(recv)
 background.start()

 while True:
   entered = input("Please enter a new com frequency or a non-number to quit\n")
   if isint(entered):
     # send the new com freq as integer.
     recv.sendDataI(COM1_FREQ_KHZ.Id(), int(entered))
   else:
     break

 # turn on the landing lights before we quit ;)
 # note the use of the B function for switches
 recv.sendDataB(LIGHT_LANDING_SWITCH.Id(), True)

 background.stop()
 background.join()

NOTES

LICENSE

Copyright (C) 2008-2010 by Philipp Münzel. All rights reserved.

You are hereby granted the right to include an unmodified copy of libcanaero in binary form into your open- or closed-source, commercially or non-commercially licensed application.

Modifying your copy of libcanaero in any way is prohibited. Although some parts of libcanaero's source code (.h-files) are published, you are not allowed to modify these parts and/or create new binary distributions of libcanaero.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Generated on Tue Nov 16 22:47:00 2010 by  doxygen 1.6.3