gclib 2.0.9
Communications API for Galil controllers and PLCs
 
Loading...
Searching...
No Matches
Python

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.
>cd %temp%
>mkdir py
>cd py
>copy "c:\Program Files (x86)\Galil\gclib\source\wrappers\python\*" .
c:\Program Files (x86)\Galil\gclib\source\wrappers\python\gclib.py
c:\Program Files (x86)\Galil\gclib\source\wrappers\python\setup.py
    2 file(s) copied.
>copy "c:\Program Files (x86)\Galil\gclib\examples\python\*" .
c:\Program Files (x86)\Galil\gclib\examples\python\example.py
    1 file(s) copied.
>python setup.py install
running install
running build
running build_py
creating build
creating build\lib
copying gclib.py -> build\lib
running install_lib
running install_egg_info
Removing C:\Users\user\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\gclib-1.0-py3.7.egg-info
Writing C:\Users\user\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\gclib-1.0-py3.7.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 py
$ cd py
$ cp /usr/share/gclib/src/wrappers/python/* .
$ cp /usr/share/gclib/doc/examples/python/* .
$ 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_python.tar.gz
x gclib.py
x setup.py
$ tar -xvf /Applications/gclib/examples/gclib_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

>>> import gclib
>>> g = gclib.py()
>>> g.GOpen('192.168.0.42')
>>> 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.

>>> 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.

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