[Home]Using HAL In Python

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Difference (from prior major revision) (no other diffs)

Added: 5a6,14


To run the program with realtime:

cd to the folder that pygtk.py is in.

type 'halrun'

type 'loadusr python pygtk.py'


If using simulator

cd to folder type 'python pygtk.py'



Pygtk and HAL


Here is sample python code that shows how to create a custom widget
(an LED) and how to connect to HAL with python: upload:pygtk_HAL.py
upload:pygtk_HAL.png

To run the program with realtime:
cd to the folder that pygtk.py is in.
type 'halrun'
type 'loadusr python pygtk.py'

If using simulator
cd to folder type 'python pygtk.py'

I found this pages informative about custom widgets: http://zetcode.com/tutorials/pygtktutorial/customwidget/
http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
http://www.pygtk.org/articles/cairo-pygtk-widgets/cairo-pygtk-widgets.htm
http://www.pygtk.org/articles/cairo-pygtk-widgets/cairo-pygtk-widgets2.htm

and for general pygtk info: http://www.pygtk.org/pygtk2tutorial/index.html
http://www.pygtk.org/docs/pygtk/index.html
http://www.pygtk.org/articles.html

This is some of the info from the python imported module hal:

Help on module hal:

NAME
    hal - Interface to emc2's hal

FILE
    /home/chester/emc2-dev/lib/python/hal.so

DESCRIPTION
    This module allows the creation of userspace HAL components in Python.
    This includes pins and parameters of the various HAL types.
    
    Typical usage:
    
    import hal, time
    h = hal.component("component-name")
    # create pins and parameters with calls to h.newpin and h.newparam
    h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
    h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
    h.ready() # mark the component as 'ready'
    
    try:
        while 1:
            # act on changed input pins; update values on output pins
            time.sleep(1)
            h['out'] = h['in']
    except KeyboardInterrupt: pass
    
    When the component is requested to exit with 'halcmd unload', a
    KeyboardInterrupt exception will be raised.

DATA
    HAL_BIT = 1
    HAL_FLOAT = 2
    HAL_IN = 16
    HAL_IO = 48
    HAL_OUT = 32
    HAL_RO = 64
    HAL_RW = 192
    HAL_S32 = 3
    HAL_U32 = 4

Methods defined here:
       exit(...)
           Call hal_exit
       
       getprefix(...)
           Get the prefix for newly created pins and parameters
       
       newparam(...)
           Create a new parameter
       
       newpin(...)
           Create a new pin
       
       ready(...)
           Call hal_ready
       
       setprefix(...)
           Set the prefix for newly created pins and parameters
       
FUNCTIONS
    component_exists(...)
        Return a TRUE value if the named component exists
    
    pin_has_writer(...)
        Return a FALSE value if a pin has no writers and TRUE if it does


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited January 27, 2010 9:48 pm by Chris M (diff)
Search:
Published under a Creative Commons License