Table of Contents

Computer Language

"...the purpose of a higher-level programming language 
is usually to provide some mediation between the way a 
programmer would like to provide instructions and the 
way a machine needs to have them."

Python

It seems like Python has come a long way in recent years and has been a hotbed of development.

It is avalible for most operating systems.

It is also possible use python on line without an install

Other links:

Why use Python?


Why Use a Scripting Language at all?

Put it a different way: when to use C and when to use a scripting language?

I suggest looking at http://gribblelab.org/CBootcamp/1_Why_Program_In_C.html#sec-3

1.Rapid development.

2.One would think that there would be a lot of free c language libraries for common tasks like using the serial port. What one finds is actually available are free Perl and Python modules. These are generally written in c but utilized using the scripting language.. This leads to quick efficient modules for common tasks and scripting for those things that are custom for the current project.

3.In general the scripting language handles the interface to the underlying operating system. The programmer does not need to learn the API each operating system that the script could be used with.

A Free Python Book

Example

plotting with matplotlib

Find an introduction to matplotlib at http://matplotlib.sourceforge.net/users/intro.html

More at matplotlib

Controlling GPIB, RS232, and USB instruments

We have a USB instrument: the TBS1022 from Tektronix.

The programmers manual for this instrument can be found at:

Note that the same manual covers both the TBS1022 and the TDS1002B. We actually have some of both of these.

At the http://pyvisa.sourceforge.net/ link some very simple code is given for talking to a digital multimeter

import visa
keithley = visa.instrumen("GPIB::12")

print keithley.ask("*IDN?")

We should also be able to talk to our scopes with this type of code. Something to try out. Found an example using usb at http://www1.tek.com/forum/viewtopic.php?f=5&t=5221

From that example can see the following (note the instrument name):

import visa
import numpy as np
from struct import unpack
import pylab

scope = visa.instrument('USB0::0x0699::0x0401::No_Serial::INSTR')

In another example the python script first reads the intrument name from the attached instruments: http://www.home.agilent.com/owc_discussions/thread.jspa?messageID=106272&tstart=0

"Example 01 (directly with PyVisa):"

import visa import pylab

# Get instrument VISAname
visaInstrList = visa.get_instruments_list()
myScope = visaInstrList[0]+'::INSTR'

scope = visa.instrument(myScope)

So I tried this out in a IDLE session.

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import visa
>>> visaInstrList = visa.get_instruments_list()
>>> myScope = visaInstrList
>>> myScope
['USB0::0x0699::0x03AE::C011174', 'COM1', 'COM3', 'LPT1', 'ASRL11']
>>> myScope = visaInstrList[0]+'::INSTR'
>>> scope = visa.instrument(myScope)
>>> scope.ask("*IDN?")
'TEKTRONIX,TBS 1022,C011174,CF:91.1CT FV:v26.01'
>>> scope.write('CH1:VOLTS 2.0')
>>> scope.write('TRIG:MAIN:LEVEL 2.4')
>>> scope.write('HOR:MAIN:SCALE 100E-6')

It appears to work! The TBS 1022 responded to the last three commands as expected (meaning that the vertical scale of channel one was set to 2 volts/div, the trigger level was set to 2.4 volts and the horizontal scale was set to 100 micro-seconds/div).

I also tried setting and reading both the time and date.

>>> scope.write('DATE "2013-06-18"')
>>> scope.write('TIME "18:37:00"')
>>> scope.ask('date?')
'"2013-06-18"'
>>> scope.ask('time?')
'"18:38:23"'

Using ethernet

Using USB

Python control of equipment

Python Socket Communication

Python in Education

Internal Representation of Integers

I looked this up since I was interested.

General Stuff to look at