Difference between revisions of "Using Python to Automate MAS"
(→Getting Started with Python) |
(→Getting Started with Python) |
||
Line 1: | Line 1: | ||
− | == Getting Started with Python | + | = The MCE library - mce.py = |
+ | |||
+ | Basic python access to the C language "mce_interface" library is provided by a swig wrapper. This produces mce_library.py. Higher level support is then exposed by mce.py, which exposes basic MCE objects. | ||
+ | |||
+ | == Basic reading and writing == | ||
+ | |||
+ | Note that mce.read and mce.write expect '''lists''' as arguments, and return lists by default, even for single-item parameters. | ||
+ | from mce import mce # Import the basic MCE class | ||
+ | m = mce() # Get one | ||
+ | sa_bias = m.read('sa', 'bias') # This will return a list of integers, one per column | ||
+ | m.write('cc', 'led', [7]) # Note that we pass a list containing the single item 7 | ||
+ | |||
+ | == Reading frames from the MCE == | ||
+ | |||
+ | Frames can only be read directly into python; support for triggering writes to disk from python is not yet in place. | ||
+ | |||
+ | from mce import mce | ||
+ | m = mce() | ||
+ | data = m.read_frames(10, data_only=True) # This will read in 10 frames in the form of a (10, n_channels) array. | ||
+ | |||
+ | When you do read the header (data_only=False), the data is returned as a tuple with all the headers in the first returned value and all the frame data in the second tuple element. | ||
+ | |||
+ | = Getting Started with Python = | ||
To install the Emacs template file for python, type the following: | To install the Emacs template file for python, type the following: | ||
sudo apt-get install python-mode | sudo apt-get install python-mode | ||
− | Here is | + | Here is another way to command the MCE from python (discouraged...): |
mce@mce-ubc-2:~$ python | mce@mce-ubc-2:~$ python | ||
Python 2.4.3 (#2, Mar 7 2008, 01:58:20) | Python 2.4.3 (#2, Mar 7 2008, 01:58:20) | ||
Line 18: | Line 40: | ||
When creating a python script, for the script to be executable, you must put the following line of code at the top: | When creating a python script, for the script to be executable, you must put the following line of code at the top: | ||
#!/bin/python | #!/bin/python | ||
+ | or possibly | ||
+ | #!/usr/bin/python | ||
And you must change the permissions of the file to the following: | And you must change the permissions of the file to the following: |
Revision as of 18:47, 1 April 2009
Contents
The MCE library - mce.py
Basic python access to the C language "mce_interface" library is provided by a swig wrapper. This produces mce_library.py. Higher level support is then exposed by mce.py, which exposes basic MCE objects.
Basic reading and writing
Note that mce.read and mce.write expect lists as arguments, and return lists by default, even for single-item parameters.
from mce import mce # Import the basic MCE class m = mce() # Get one sa_bias = m.read('sa', 'bias') # This will return a list of integers, one per column m.write('cc', 'led', [7]) # Note that we pass a list containing the single item 7
Reading frames from the MCE
Frames can only be read directly into python; support for triggering writes to disk from python is not yet in place.
from mce import mce m = mce() data = m.read_frames(10, data_only=True) # This will read in 10 frames in the form of a (10, n_channels) array.
When you do read the header (data_only=False), the data is returned as a tuple with all the headers in the first returned value and all the frame data in the second tuple element.
Getting Started with Python
To install the Emacs template file for python, type the following:
sudo apt-get install python-mode
Here is another way to command the MCE from python (discouraged...):
mce@mce-ubc-2:~$ python Python 2.4.3 (#2, Mar 7 2008, 01:58:20) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.system('mce_cmd -x rb cc fw_rev') This is mce_cmd version MAS/trunk/230 Line 0 : ok : 0x400000b Processed 0 lines, exiting. 0 >>>
When creating a python script, for the script to be executable, you must put the following line of code at the top:
#!/bin/python
or possibly
#!/usr/bin/python
And you must change the permissions of the file to the following:
chmod a+x <python_script_name>
In Emacs, to get high-lighting, type
<alt>+<x> python-mode