| gclib 354 Communications API for Galil controllers and PLCs |

All Data Structures Files Functions Variables Typedefs Macros Pages
Python

## Install gclib

The gclib Python wrapper assumes the default gclib installation location.

## Install Python

- See https://www.python.org/ if Python is not already installed on the system. The gclib Python wrapper supports Python versions 2 and 3.
- On Windows, choose to add Python to the environment variable during installation. This allows Python to be invoked from the command line.

## Install the gclib Python module

### Windows

- Type the following commands into a command prompt.

    C:\Users\username>cd Desktop
    C:\Users\username\Desktop>mkdir python_temp
    C:\Users\username\Desktop>cd python_temp
    C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\source\wrappers\python\*" .
    C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\examples\python\*" .
    C:\Users\username\Desktop\python_temp>python setup.py install
    running install
    running build
    running build_py
    creating build
    creating build\lib
    copying gclib.py -> build\lib
    running install_lib
    copying build\lib\gclib.py -> C:\Python34\Lib\site-packages
    byte-compiling C:\Python34\Lib\site-packages\gclib.py to gclib.cpython-34.pyc
    running install_egg_info
    Writing C:\Python34\Lib\site-packages\gclib-1.0-py3.4.egg-info

- The gclib Python wrapper is now installed. Go to the next section, Using gclib from the Python Interpreter.

### Linux

- Type the following commands into a Terminal prompt.

    $ mkdir ~/python_temp
    $ cd ~/python_temp/
    $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python.tar.gz
    gclib.py
    setup.py
    $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python_examples.tar.gz
    example.py
    $ sudo python setup.py install
    [sudo] password for user:
    running install
    running build
    running build_py
    creating build
    creating build/lib
    copying gclib.py -> build/lib
    running install_lib
    copying build/lib/gclib.py -> /usr/lib/python2.7/site-packages
    byte-compiling /usr/lib/python2.7/site-packages/gclib.py to gclib.pyc
    running install_egg_info
    Writing /usr/lib/python2.7/site-packages/gclib-1.0-py2.7.egg-info

- The gclib Python wrapper is now installed. Go to the next section, Using gclib from the Python Interpreter.

### OS X

- Be sure that the Create Environment Variable step has been followed in the OS X installation instructions.
- Type the following commands into a Terminal prompt.

    $ mkdir ~/python_temp
    $ cd ~/python_temp/
    $ tar -xvf /Applications/gclib/source/gclib_253_python.tar.gz
    x gclib.py
    x setup.py
    $ tar -xvf /Applications/gclib/examples/gclib_253_python_examples.tar.gz
    x example.py
    $ sudo python setup.py install
    running install
    running build
    running build_py
    creating build
    creating build/lib
    copying gclib.py -> build/lib
    running install_lib
    copying build/lib/gclib.py -> /Library/Python/2.7/site-packages
    byte-compiling /Library/Python/2.7/site-packages/gclib.py to gclib.pyc
    running install_egg_info
    Writing /Library/Python/2.7/site-packages/gclib-1.0-py2.7.egg-info

- The gclib Python wrapper is now installed. Go to the next section, Using gclib from the Python Interpreter.

## Using gclib from the Python Interpreter

- Invoke the Python Interpreter.
- Type the following into the Python prompt.

    >>> import gclib
    >>> g = gclib.py()
    >>> g.GOpen('192.168.0.42 --direct')
    >>> print(g.GInfo())
    192.168.0.42, DMC4080 Rev 1.2c, 783

## Running Python scripts

- Navigate the terminal to the location from Install the gclib Python module where example.py was copied.
- Open example.py in a text editor.
- Set the address in the g.GOpen() call to match an avaiable connection.
- Execute the following command at the Terminal.

    $ python example.py
    gclib version: py.127.110.250
    192.168.0.42, DMC4080 Rev 1.2c, 783

- Experiment with the example by uncommenting sections, between the triple quotes, '''.

    $ python example.py
    gclib version: py.127.110.250
    192.168.0.42, DMC4080 Rev 1.2c, 783
    GProgramDownload() correctly errored. Can't fit with level 3 compression
    Uploaded program:
    #A;i=0;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1
    i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;i=i+1;EN
    Downloaded program verified
    Array element verified
     187942.0000

    Starting move...
    done.

## Getting help

    >>> help(g.GOpen)
    Help on method GOpen in module gclib:

    GOpen(address) method of gclib.py instance
        Opens a connection a galil controller.
        See the gclib docs for address string formatting.
        See Link GOpen() <http://www.galil.com/sw/pub/all/doc/gclib/html/gclib_8h_aef4aec8a85630eed029b7a46aea7db54.html#aef4aec8a85630eed029b7a46aea7db54>

    >>> help(g.GCommand)
    Help on method GCommand in module gclib:

    GCommand(command) method of gclib.py instance
        Performs a command-and-response transaction on the connection.
        Trims the response.
        See Link GCommand() <http://www.galil.com/sw/pub/all/doc/gclib/html/gclib_8h_a5ac031e76efc965affdd73a1bec084a8.html#a5ac031e76efc965affdd73a1bec084a8>

    >>> 'for a full listing, try help(g)'