| gclib 354 Communications API for Galil controllers and PLCs |

All Data Structures Files Functions Variables Typedefs Macros Pages
python.md
1 # Python {#python}
2
3 ## Install gclib
4
5 The gclib Python wrapper assumes the default gclib \link installation \endlink location.
6
7 ## Install Python
8
9 * See https://www.python.org/ if Python is not already installed on the system. The gclib Python wrapper supports Python versions 2 and 3.
10 * On Windows, choose to add Python to the environment variable during installation. This allows Python to be invoked from the command line.
11
12 ## Install the gclib Python module
13
14 ### Windows
15
16 * 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>.
17
18
19 C:\Users\username>cd Desktop
20 C:\Users\username\Desktop>mkdir python_temp
21 C:\Users\username\Desktop>cd python_temp
22 C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\source\wrappers\python\*" .
23 C:\Users\username\Desktop\python_temp>copy "c:\Program Files (x86)\Galil\gclib\examples\python\*" .
24 C:\Users\username\Desktop\python_temp>python setup.py install
25 running install
26 running build
27 running build_py
28 creating build
29 creating build\lib
30 copying gclib.py -> build\lib
31 running install_lib
32 copying build\lib\gclib.py -> C:\Python34\Lib\site-packages
33 byte-compiling C:\Python34\Lib\site-packages\gclib.py to gclib.cpython-34.pyc
34 running install_egg_info
35 Writing C:\Python34\Lib\site-packages\gclib-1.0-py3.4.egg-info
36
37
38 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
39
40
41 ### Linux
42
43 * Type the following commands into a Terminal prompt.
44
45
46 $ mkdir ~/python_temp
47 $ cd ~/python_temp/
48 $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python.tar.gz
49 gclib.py
50 setup.py
51 $ tar -xvf /usr/share/doc/gclib/src/gclib_256_python_examples.tar.gz
52 example.py
53 $ sudo python setup.py install
54 [sudo] password for user:
55 running install
56 running build
57 running build_py
58 creating build
59 creating build/lib
60 copying gclib.py -> build/lib
61 running install_lib
62 copying build/lib/gclib.py -> /usr/lib/python2.7/site-packages
63 byte-compiling /usr/lib/python2.7/site-packages/gclib.py to gclib.pyc
64 running install_egg_info
65 Writing /usr/lib/python2.7/site-packages/gclib-1.0-py2.7.egg-info
66
67
68 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
69
70
71 ### OS X
72
73 * Be sure that the *Create Environment Variable* step has been followed in the \link osx OS X\endlink installation instructions.
74 * Type the following commands into a Terminal prompt.
75
76
77 $ mkdir ~/python_temp
78 $ cd ~/python_temp/
79 $ tar -xvf /Applications/gclib/source/gclib_253_python.tar.gz
80 x gclib.py
81 x setup.py
82 $ tar -xvf /Applications/gclib/examples/gclib_253_python_examples.tar.gz
83 x example.py
84 $ sudo python setup.py install
85 running install
86 running build
87 running build_py
88 creating build
89 creating build/lib
90 copying gclib.py -> build/lib
91 running install_lib
92 copying build/lib/gclib.py -> /Library/Python/2.7/site-packages
93 byte-compiling /Library/Python/2.7/site-packages/gclib.py to gclib.pyc
94 running install_egg_info
95 Writing /Library/Python/2.7/site-packages/gclib-1.0-py2.7.egg-info
96
97 * The gclib Python wrapper is now installed. Go to the next section, **Using gclib from the Python Interpreter**.
98
99
100 ## Using gclib from the Python Interpreter
101
102 * Invoke the <a href="https://docs.python.org/2/tutorial/interpreter.html" target="_blank">Python Interpreter</a>.
103 * Type the following into the Python prompt.
104
105
106
107 >>> import gclib
108 >>> g = gclib.py()
109 >>> g.GOpen('192.168.0.42 --direct')
110 >>> print(g.GInfo())
111 192.168.0.42, DMC4080 Rev 1.2c, 783
112
113 ## Running Python scripts
114
115 * Navigate the terminal to the location from **Install the gclib Python module** where example.py was copied.
116 * Open *example.py* in a text editor.
117 * Set the address in the g.GOpen() call to match an avaiable connection.
118 * Execute the following command at the Terminal.
119
120
121 $ python example.py
122 gclib version: py.127.110.250
123 192.168.0.42, DMC4080 Rev 1.2c, 783
124
125 * Experiment with the example by uncommenting sections, between the triple quotes, '''.
126
127
128 $ python example.py
129 gclib version: py.127.110.250
130 192.168.0.42, DMC4080 Rev 1.2c, 783
131 GProgramDownload() correctly errored. Can't fit with level 3 compression
132 Uploaded program:
133 #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
134 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
135 Downloaded program verified
136 Array element verified
137 187942.0000
138
139 Starting move...
140 done.
141
142 ## Getting help
143
144
145 >>> help(g.GOpen)
146 Help on method GOpen in module gclib:
147
148 GOpen(address) method of gclib.py instance
149 Opens a connection a galil controller.
150 See the gclib docs for address string formatting.
151 See Link GOpen() <http://www.galil.com/sw/pub/all/doc/gclib/html/gclib_8h_aef4aec8a85630eed029b7a46aea7db54.html#aef4aec8a85630eed029b7a46aea7db54>
152
153 >>> help(g.GCommand)
154 Help on method GCommand in module gclib:
155
156 GCommand(command) method of gclib.py instance
157 Performs a command-and-response transaction on the connection.
158 Trims the response.
159 See Link GCommand() <http://www.galil.com/sw/pub/all/doc/gclib/html/gclib_8h_a5ac031e76efc965affdd73a1bec084a8.html#a5ac031e76efc965affdd73a1bec084a8>
160
161 >>> 'for a full listing, try help(g)'
162
163
164
165
166