| 1 |
.. comment:: |
| 2 |
the main title "Programming ExpEYES using Python" is removed |
| 3 |
It matters little for HTML help files, but it does matter for |
| 4 |
EPUB and PDF generated by Sphinx |
| 5 |
|
| 6 |
The GUI programs described in the previous sections are meant for a |
| 7 |
fixed set of experiments. To develop new experiments, one should know |
| 8 |
how to access the features of expEYES from software. Important function |
| 9 |
calls used for communicating with the device is given below. |
| 10 |
|
| 11 |
Establish Connection |
| 12 |
"""""""""""""""""""" |
| 13 |
|
| 14 |
To access the EYES17 hardware, the python modules for eyes17 must be |
| 15 |
installed. They should be inside a directory named eyes17, that could be |
| 16 |
in your home directory or on the Python PATH. **Every program should |
| 17 |
start with the following 2 lines** |
| 18 |
|
| 19 |
.. code-block:: python |
| 20 |
|
| 21 |
import eyes17.eyes |
| 22 |
p = eyes17.eyes.open() |
| 23 |
|
| 24 |
The variable ``p`` is the software object, representing the hardware. |
| 25 |
|
| 26 |
The following sections explains the Python function calls to access the |
| 27 |
eyes17 hardware. Each function call will be explained with an example |
| 28 |
usage. |
| 29 |
|
| 30 |
set_pv1(v), set_pv2(v) |
| 31 |
"""""""""""""""""""""" |
| 32 |
|
| 33 |
Sets the DC voltages at PV1 and PV2. PV1 range is -5 to 5. PV2 range is |
| 34 |
-3.3 to 3.3. |
| 35 |
|
| 36 |
.. code-block:: python |
| 37 |
|
| 38 |
print p.set_pv1(4) |
| 39 |
print p.set_pv2(2) |
| 40 |
|
| 41 |
The value set is printed. Measure the voltages using a meter. |
| 42 |
|
| 43 |
get_voltage(input) |
| 44 |
"""""""""""""""""" |
| 45 |
|
| 46 |
Returns the voltage at the specified input. |
| 47 |
|
| 48 |
.. code-block:: python |
| 49 |
|
| 50 |
print p.get_voltage('A1') |
| 51 |
print p.get_voltage('A2') |
| 52 |
print p.get_voltage('A3') |
| 53 |
print p.get_voltage('MIC') |
| 54 |
print p.get_voltage('SEN') |
| 55 |
|
| 56 |
Connect PV1 to A1 and use the set_pv1() and get_voltage together. This |
| 57 |
function sets the input range by trial |
| 58 |
|
| 59 |
and error, depending on the input signal. |
| 60 |
|
| 61 |
get_voltage_time(input) |
| 62 |
""""""""""""""""""""""" |
| 63 |
|
| 64 |
Returns a tuple, containing the computer's time stamp and the voltage at |
| 65 |
the specified input |
| 66 |
|
| 67 |
.. code-block:: python |
| 68 |
|
| 69 |
print p.get_voltage_time('A1') |
| 70 |
|
| 71 |
get_resistance() |
| 72 |
"""""""""""""""" |
| 73 |
|
| 74 |
Returns the value of resistance connected to SEN, it should be between |
| 75 |
100 Ohm and 100k for reasonable accuracy. |
| 76 |
|
| 77 |
.. code-block:: python |
| 78 |
|
| 79 |
print p.get_resistance() |
| 80 |
|
| 81 |
get_capacitance() |
| 82 |
""""""""""""""""" |
| 83 |
|
| 84 |
Returns the value of capacitance connected to IN1 (works well in pF |
| 85 |
ranges) |
| 86 |
|
| 87 |
.. code-block:: python |
| 88 |
|
| 89 |
print p.get_capacitance() |
| 90 |
|
| 91 |
get_version() |
| 92 |
""""""""""""" |
| 93 |
|
| 94 |
Returns the version number of the Firmware |
| 95 |
|
| 96 |
.. code-block:: python |
| 97 |
|
| 98 |
print p.get_version() |
| 99 |
|
| 100 |
get_temperature() |
| 101 |
""""""""""""""""" |
| 102 |
|
| 103 |
Returns the temperature of the processor inside eyes17 |
| 104 |
|
| 105 |
.. code-block:: python |
| 106 |
|
| 107 |
print p.get_temperature() |
| 108 |
|
| 109 |
set_state(OUPUT=value) |
| 110 |
"""""""""""""""""""""" |
| 111 |
|
| 112 |
Sets the output of OD1, SQ1 etc. Connect OD1 to A1 and run |
| 113 |
|
| 114 |
.. code-block:: python |
| 115 |
|
| 116 |
p.set_state(OD1=1) |
| 117 |
print p.get_voltage('A1') |
| 118 |
|
| 119 |
set_sine(frequency) |
| 120 |
"""""""""""""""""""" |
| 121 |
|
| 122 |
Generates the sinewave of requested frequency on WG (range from 5Hz to |
| 123 |
5000Hz). All intermediate values are not possible, function returns the |
| 124 |
actual value set. |
| 125 |
|
| 126 |
.. code-block:: python |
| 127 |
|
| 128 |
print p.set_sine(502) |
| 129 |
|
| 130 |
502.00803 |
| 131 |
|
| 132 |
set_sine_amp(amplitude) |
| 133 |
""""""""""""""""""""""" |
| 134 |
|
| 135 |
The amplitude can be set to 3 pre-defined values of the peak voltage ( |
| 136 |
0-> 80mV, 1-> 1V, 2-> 3V) |
| 137 |
|
| 138 |
.. code-block:: python |
| 139 |
|
| 140 |
p.set_sine_amp(2) |
| 141 |
|
| 142 |
Sets the amplitude to 3 volts peak. |
| 143 |
|
| 144 |
set_sqr1(frequency) |
| 145 |
""""""""""""""""""" |
| 146 |
|
| 147 |
Sets the frequency of SQ1 output (range from 4Hz to 1 MHz).All |
| 148 |
intermediate values are not possible, function returns the actual value |
| 149 |
set. |
| 150 |
|
| 151 |
.. code-block:: python |
| 152 |
|
| 153 |
print p.set_sqr1(15030) |
| 154 |
|
| 155 |
15030.53 |
| 156 |
|
| 157 |
set_sqr1_slow(frequency) |
| 158 |
"""""""""""""""""""""""" |
| 159 |
|
| 160 |
Sets the frequency of SQ1 output (range from 0.1Hz to 1 MHz).All |
| 161 |
intermediate values are not possible, function returns the actual value |
| 162 |
set. Resolution is high but WG is disabled when SQ1 is operated in this |
| 163 |
mode. |
| 164 |
|
| 165 |
.. code-block:: python |
| 166 |
|
| 167 |
print p.set_sqr1_slow(0.5) |
| 168 |
|
| 169 |
set_sqr2(frequency) |
| 170 |
""""""""""""""""""" |
| 171 |
|
| 172 |
Similar to set_sqr1() but SQ2 is not available along with WG, only one |
| 173 |
at a time. |
| 174 |
|
| 175 |
set_sqr1(frequency, dutyCyle) |
| 176 |
""""""""""""""""""""""""""""" |
| 177 |
|
| 178 |
Sets the frequency of SQ1 output (range from 0.1Hz to 1 MHz).All |
| 179 |
intermediate values are not possible, function returns the actual value |
| 180 |
set. |
| 181 |
|
| 182 |
.. code-block:: python |
| 183 |
|
| 184 |
print p.set_sqr1(1000, 30) # 1000Hz with 30% duty cycle |
| 185 |
|
| 186 |
get_freq(input) |
| 187 |
""""""""""""""" |
| 188 |
|
| 189 |
Measures the frequency of a square wave on the input, IN2 or SEN. |
| 190 |
Connect SQ1 to IN2 and run the code |
| 191 |
|
| 192 |
.. code-block:: python |
| 193 |
|
| 194 |
p.set_sqr1(1000) |
| 195 |
print p.get_freq('IN2') |
| 196 |
|
| 197 |
duty_cycle(input) |
| 198 |
""""""""""""""""" |
| 199 |
|
| 200 |
Measures the duty cycle a square wave on the input, IN2 or SEN. Connect |
| 201 |
SQ1 to IN2 and run the code |
| 202 |
|
| 203 |
.. code-block:: python |
| 204 |
|
| 205 |
p.set_sqr1(1000, 30) |
| 206 |
print p.duty_cycle('IN2') |
| 207 |
|
| 208 |
r2ftime(input1, input2) |
| 209 |
""""""""""""""""""""""" |
| 210 |
|
| 211 |
Measures the time interval between a rising edge on input1 to another |
| 212 |
one on input2, the inputs can be the same also. This can be tested using |
| 213 |
a square wave. |
| 214 |
|
| 215 |
Connect SQ1 to IN2 and run |
| 216 |
|
| 217 |
.. code-block:: python |
| 218 |
|
| 219 |
p.set_sqr1(1000, 30) |
| 220 |
print p.r2ftime('IN2', 'IN2') |
| 221 |
|
| 222 |
0.0003 |
| 223 |
|
| 224 |
The 1kHz square wave with 30% duty cycle has a Period of one millisecond |
| 225 |
and stays HIGH for .3 milliseconds. |
| 226 |
|
| 227 |
multi_r2rtime(input, numCycles) |
| 228 |
""""""""""""""""""""""""""""""" |
| 229 |
|
| 230 |
Measures the time interval between rising edges on input1. Time between |
| 231 |
2 edges is one cycle. Number of cycles to be measured also can be |
| 232 |
specified, default value is 1. The allowed values are 1,2,4,8,12,16,32 |
| 233 |
and 48. This can be tested using a square wave. |
| 234 |
|
| 235 |
Connect SQ1 to IN2 and run |
| 236 |
|
| 237 |
.. code-block:: python |
| 238 |
|
| 239 |
p.set_sqr1(1000) |
| 240 |
print p.multi_r2rtime('IN2', 8) |
| 241 |
|
| 242 |
0.008 |
| 243 |
|
| 244 |
select_range(channel, range) |
| 245 |
"""""""""""""""""""""""""""" |
| 246 |
|
| 247 |
The input range of A1 and A2 can be set from ±0.5\ V to ±16\ V |
| 248 |
fullscale, using the programmable gain amplifiers. |
| 249 |
|
| 250 |
.. code-block:: python |
| 251 |
|
| 252 |
p.select_range('A1', 4) # 4volt maximum |
| 253 |
p.select_range('A1', 8) # 8 volt maximum |
| 254 |
|
| 255 |
select_range(channel, range) |
| 256 |
"""""""""""""""""""""""""""" |
| 257 |
|
| 258 |
The input range of A1 and A2 can be set from ±0.5\ V to ±16\ V |
| 259 |
fullscale, using the programmable gain amplifiers. |
| 260 |
|
| 261 |
.. code-block:: python |
| 262 |
|
| 263 |
p.select_range('A1', 4) # 4volt maximum |
| 264 |
p.select_range('A1', 8) # 8 volt maximum |
| 265 |
|
| 266 |
capture1(Input, Number of samples, time interval) |
| 267 |
""""""""""""""""""""""""""""""""""""""""""""""""" |
| 268 |
|
| 269 |
Digitizes the specified input. The number of samples could be upto |
| 270 |
10000. The time gap between two consecutive samples id given in |
| 271 |
microseconds (range 2 to 1000 usec). |
| 272 |
|
| 273 |
.. code-block:: python |
| 274 |
|
| 275 |
print p.capture1('A1', 5, 5) |
| 276 |
|
| 277 |
will print two arrays of time and voltage. |
| 278 |
|
| 279 |
We need to plot the graph of the output for a better understanding. This |
| 280 |
can be done using the matplotlib module, imported using the pylab |
| 281 |
interface. Connect WG to A1 with a wire and run; |
| 282 |
|
| 283 |
.. code-block:: python |
| 284 |
|
| 285 |
from pylab import * |
| 286 |
p.set_sine_amp(2) |
| 287 |
p.set_sine(1000) |
| 288 |
p.select_range('A1', 4) |
| 289 |
t,v = p.capture1('A1', 300, 10) |
| 290 |
plot(t,v) |
| 291 |
show() |
| 292 |
|
| 293 |
The output of this code is given below. |
| 294 |
|
| 295 |
.. image:: pics/sine-mpl-screen.png |
| 296 |
:width: 400px |
| 297 |
|
| 298 |
|
| 299 |
capture2(Number of samples, time interval) |
| 300 |
"""""""""""""""""""""""""""""""""""""""""" |
| 301 |
|
| 302 |
Digitizes the inputs A1 and A2 together. The number of samples could be |
| 303 |
upto 10000. The time gap between two consecutive samples id given in |
| 304 |
microseconds (range 2 to 1000 usec). |
| 305 |
|
| 306 |
Connect WG to A1 and a diode from A1 to A2. Run the code below |
| 307 |
|
| 308 |
.. code-block:: python |
| 309 |
|
| 310 |
from pylab import * |
| 311 |
p.set_sine_amp(2) |
| 312 |
p.set_sine(1000) |
| 313 |
p.select_range('A1', 4) |
| 314 |
t,v,tt,vv = p.capture2(300, 10) |
| 315 |
plot(t,v) |
| 316 |
plot(tt,vv) |
| 317 |
show() |
| 318 |
|
| 319 |
The output of this code is given below. |
| 320 |
|
| 321 |
.. image:: pics/halfwave-mpl-screen.png |
| 322 |
:width: 400px |
| 323 |
|
| 324 |
capture4(Number of samples, time interval) |
| 325 |
"""""""""""""""""""""""""""""""""""""""""" |
| 326 |
|
| 327 |
Digitizes the inputs A1,A2,A3 and MIC together. The number of samples |
| 328 |
could be upto 10000. The time gap between two consecutive samples id |
| 329 |
given in microseconds (range 2 to 1000 usec). |
| 330 |
|
| 331 |
Connect WG to A3 and run the code given below. Result is shown above. |
| 332 |
|
| 333 |
.. code-block:: python |
| 334 |
|
| 335 |
from pylab import * |
| 336 |
p.set_sine_amp(2) |
| 337 |
p.set_sine(1000) |
| 338 |
p.select_range('A1', 4) |
| 339 |
res = p.capture4(300, 10) |
| 340 |
plot(res[4],res[5]) # A3 |
| 341 |
plot(res[6],res[7]) # MIC |
| 342 |
show() |
| 343 |
|
| 344 |
.. image:: pics/capture4-mpl-screen.png |
| 345 |
:width: 400px |
| 346 |
|
| 347 |
set_wave(frequency, wavetype) |
| 348 |
""""""""""""""""""""""""""""" |
| 349 |
|
| 350 |
If wavetype is not specified, it generates the waveform using the |
| 351 |
existing wave table. If wavetype is specified ('sine' or 'tria') |
| 352 |
|
| 353 |
corresponding wavetable is loaded. |
| 354 |
|
| 355 |
.. code-block:: python |
| 356 |
|
| 357 |
from pylab import * |
| 358 |
p.set_wave(1000, 'sine') |
| 359 |
p.set_wave(100) # Sets 100Hz using the existing table |
| 360 |
x,y = p.capture1('A1', 500,50) |
| 361 |
plot(x,y) |
| 362 |
p.set_wave(100, 'tria') # Sets triagular wave table and generates 100Hz |
| 363 |
x,y = p.capture1('A1', 500,50) |
| 364 |
plot(x,y) |
| 365 |
show() |
| 366 |
|
| 367 |
load_equation(function, span) |
| 368 |
""""""""""""""""""""""""""""" |
| 369 |
|
| 370 |
Makes the wave table using the quation. Connect WG to A1 and run the |
| 371 |
code below. The output also is shown below. |
| 372 |
|
| 373 |
.. code-block:: python |
| 374 |
|
| 375 |
from pylab import * |
| 376 |
|
| 377 |
def f1(x): |
| 378 |
return sin(x) + sin(3*x)/3 |
| 379 |
|
| 380 |
p.load_equation(f1, [-pi,pi]) |
| 381 |
p.set_wave(400) |
| 382 |
x,y = p.capture1('A1', 500,10) |
| 383 |
plot(x,y) |
| 384 |
show() |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
load_table(function, span) |
| 389 |
"""""""""""""""""""""""""" |
| 390 |
|
| 391 |
The wave table can be loaded with a 512 element array. Connect WG to A1 |
| 392 |
and run the code below. After taking the absolute value, the table |
| 393 |
starts with 256, goes down to zero and then goes upto 255, tracing a |
| 394 |
triagular wave. The tableoutput also is shown above. |
| 395 |
|
| 396 |
.. code-block:: python |
| 397 |
|
| 398 |
from pylab import * |
| 399 |
x = arange(-256, 256) |
| 400 |
x = abs(x) |
| 401 |
p.load_table(x) |
| 402 |
p.set_wave(400) |
| 403 |
x,y = p.capture1('A1', 500,10) |
| 404 |
plot(x,y) |
| 405 |
show() |
| 406 |
|
| 407 |
.. image:: pics/load-equation-mpl-screen.png |
| 408 |
:width: 400px |
| 409 |
|
| 410 |
.. image:: pics/load-table-mpl-screen.png |
| 411 |
:width: 400px |
| 412 |
|