00001 # Python {#python}
00002
00003 ## Install gclib
00004
00005 The gclib Python wrapper assumes the default gclib \link installation \endlink location.
00006
00007 ## Install Python
00008
00009 * See https:
00010 * On Windows, choose to add Python to the environment variable during installation. This allows Python to be invoked from the command line.
00011
00012 ## Install the gclib Python module
00013
00014 ### Windows
00015
00016 * Type the following commands into a <a href="http://windows.microsoft.com/en-us/windows-vista/open-a-command-prompt-window" target="_blank">command prompt</a>.
00017
00018
00019 C:\Users\username>cd Desktop
00020 C:\Users\username\Desktop>mkdir python_temp
00021 C:\Users\username\Desktop>cd python_temp
00022 C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\source\wrappers\python\*" .
00023 C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\examples\python\*" .
00024 C:\Users\username\Desktop\python_temp>python setup.py install
00025 running install
00026 running build
00027 running build_py
00028 creating build
00029 creating build\lib
00030 copying gclib.py -> build\lib
00031 running install_lib
00032 copying build\lib\gclib.py -> C:\Python34\Lib\site-packages
00033 byte-compiling C:\Python34\Lib\site-packages\gclib.py to gclib.cpython-34.pyc
00034 running install_egg_info
00035 Writing C:\Python34\Lib\site-packages\gclib-1.0-py3.4.egg-info
00036
00037
00038 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
00039
00040
00041 ### Linux
00042
00043 * Type the following commands into a Terminal prompt.
00044
00045
00046 $ mkdir ~/python_temp
00047 $ cd ~/python_temp/
00048 $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python.tar.gz
00049 gclib.py
00050 setup.py
00051 $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python_examples.tar.gz
00052 example.py
00053 $ sudo python setup.py install
00054 [sudo] password for user:
00055 running install
00056 running build
00057 running build_py
00058 creating build
00059 creating build/lib
00060 copying gclib.py -> build/lib
00061 running install_lib
00062 copying build/lib/gclib.py -> /usr/lib/python2.7/site-packages
00063 byte-compiling /usr/lib/python2.7/site-packages/gclib.py to gclib.pyc
00064 running install_egg_info
00065 Writing /usr/lib/python2.7/site-packages/gclib-1.0-py2.7.egg-info
00066
00067
00068 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
00069
00070
00071 ### OS X
00072
00073 * Be sure that the *Create Environment Variable* step has been followed in the \link osx OS X\endlink installation instructions.
00074 * Type the following commands into a Terminal prompt.
00075
00076
00077 $ mkdir ~/python_temp
00078 $ cd ~/python_temp/
00079 $ tar -xvf /Applications/gclib/source/gclib_253_python.tar.gz
00080 x gclib.py
00081 x setup.py
00082 $ tar -xvf /Applications/gclib/examples/gclib_253_python_examples.tar.gz
00083 x example.py
00084 $ sudo python setup.py install
00085 running install
00086 running build
00087 running build_py
00088 creating build
00089 creating build/lib
00090 copying gclib.py -> build/lib
00091 running install_lib
00092 copying build/lib/gclib.py -> /Library/Python/2.7/site-packages
00093 byte-compiling /Library/Python/2.7/site-packages/gclib.py to gclib.pyc
00094 running install_egg_info
00095 Writing /Library/Python/2.7/site-packages/gclib-1.0-py2.7.egg-info
00096
00097 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
00098
00099
00100 ## Using gclib from the Python Interpreter
00101
00102 * Invoke the <a href="https://docs.python.org/2/tutorial/interpreter.html" target="_blank">Python Interpreter</a>.
00103 * Type the following into the Python prompt.
00104
00105
00106
00107 >>> import gclib
00108 >>> g = gclib.py()
00109 >>> g.GOpen('192.168.0.42 --direct')
00110 >>> print(g.GInfo())
00111 192.168.0.42, DMC4080 Rev 1.2c, 783
00112
00113 ## Running Python scripts
00114
00115 * Navigate the terminal to the location from **Install the gclib Python module** where example.py was copied.
00116 * Open *example.py* in a text editor.
00117 * Set the address in the g.GOpen() call to match an avaiable connection.
00118 * Execute the following command at the Terminal.
00119
00120
00121 $ python example.py
00122 gclib version: py.127.110.250
00123 192.168.0.42, DMC4080 Rev 1.2c, 783
00124
00125 * Experiment with the example by uncommenting sections, between the triple quotes, '''.
00126
00127
00128 $ python example.py
00129 gclib version: py.127.110.250
00130 192.168.0.42, DMC4080 Rev 1.2c, 783
00131 GProgramDownload() correctly errored. Can't fit with level 3 compression
00132 Uploaded program:
00133 #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
00134 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
00135 Downloaded program verified
00136 Array element verified
00137 187942.0000
00138
00139 Starting move...
00140 done.
00141
00142 ## Getting help
00143
00144
00145 >>> help(g.GOpen)
00146 Help on method GOpen in module gclib:
00147
00148 GOpen(address) method of gclib.py instance
00149 Opens a connection a galil controller.
00150 See the gclib docs for address string formatting.
00151 See Link GOpen() <http:
00152
00153 >>> help(g.GCommand)
00154 Help on method GCommand in module gclib:
00155
00156 GCommand(command) method of gclib.py instance
00157 Performs a command-and-response transaction on the connection.
00158 Trims the response.
00159 See Link GCommand() <http:
00160
00161 >>> 'for a full listing, try help(g)'
00162
00163
00164
00165
00166