OK, more baby steps on the way to making Philippe's system work. My end goal is the Raspberry Pi system using Philippe's library and Jupyter notebooks, but my first effort is to get to a functional system on the PC.
Please, no complaints, I know this is ugly and basic. But it also works to get folks started.
You'll need to complete each one, mostly in order, to avoid getting stuck.
1) Get your GPIB adapter or E5810 working and scan the instruments. Make sure you see what you expect to see!
The instruments must be listed for the next step (I think...), if your adapter has simple management software (it may not)
2) Load NI Explorer. This is your basic GPIB interface library. Find and install your instruments in the GPIB tree. They have long names, like the ones in my example code. In the snip attached, these are connected to the E5810.
3) Load Thonny.
https://thonny.org/.
This is an easy starter environment. Later, Jupyter notebooks and the Raspberry Pi.
4) Load my test program, tweak for your instruments, and walk through any library errors. Thonny has many libraries already available, The only one you might have to hunt down is PyVISA.
The code is messy, and includes a lot of redundant or irrelevant stuff that I left in for reference. Also, the 34420A setup causes non-critical errors.
5) Start your first logging!
Once you are here, you can write code for many instruments.
6) At this stage, we are still hacking at the lowest level. This is where Philippe's libraries will help us. So get this started.
Next steps:
- Philippe's libraries
- Jupyter notebooks
- Move to Raspberry Pi for logging (we'll keep development on the PC)
#This section is not essential, as the instrument names defined in here are local. However, it shows you how a Python function appears.
def InstrumentNames():
#Instrument inventory and aliases. Note that these are local names, so pretty useless.
HP34420A = 'TCPIP0::192.168.0.110::gpib0,10::INSTR'
HP3458A2 = 'TCPIP0::192.168.0.110::gpib0,20::INSTR'
print ('\033[1m','\n',"Instrument Addr Name GPIB Address",'\033[0m')
print ("HP 34420A 10 HP34420A ",HP34420A)
print ("HP 3458A2 20 3458A-2 ",HP3458A2)
#These three lines are critical.
import sys
import pyvisa
import time
localtime = time.asctime( time.localtime(time.time()) )
rm = pyvisa.ResourceManager() #Shorthand for use later on. when you use "rm", you get the component on the right - in this case, a function.
print("\nList of Instruments Detected\n",rm.list_resources()) # ...so here you see pyvisa.ResourceManager.list_resources()
HP34420A = 'TCPIP0::192.168.0.110::gpib0,10::INSTR' #These next half dozen populated lines are not essential, but they do list your instruments.
HP3458A2 = 'TCPIP0::192.168.0.110::gpib0,20::INSTR'
print ('\033[1m','\n',"Instrument Addr Name GPIB Address",'\033[0m')
print ("HP 34420A 10 HP34420A ",HP34420A)
print ("HP 3458A2 20 3458A-2 ",HP3458A2)
InstrumentNames()
#34420A init #I think this section is also redundant, except maybe for the timeout. Also, the INITs in this code do not work right.
inst = rm.open_resource(HP34420A)
inst.write("*RST;*CLS")
inst.write(":SENS:FUNC:VOLT;:SENS:CHAN 1;:SENS:VOLT:CHAN1:RANG:AUTO ON")
inst.write("VOLTage:DC:RESolution:MIN;VOLTage:DC:NPLCycles:MAX")
inst.timeout = 10
#This is where things start to happen.
f = open("Voltage_standards4.txt", "w") #w means open for write. CHANGE TO #A (append) if you want to continue runs.
#f.write("Time \t\t\t\t\t\t2142A \t\t34420A-1 \t\t34420A-2\t\t8508A\r\n")
#open and read the file after the appending:
#f = open("demofile2.txt", "r")
#print(f.read())
#line = line.rstrip('\r\n') # strip out all tailing whitespace
#34420A commands
#SENSe1:VOLTage:RANGe 10 Channel 1 range 10 mV
#SENSe2:VOLTage:RANGe .1 Channel 2 range 10 mV
#ROUTe:TERMinals FRONt1 Select channel 1
#READ? Channel 1 measurement
#ROUTe:TERMinals FRONt2 Select channel 2
#READ?
#And finally the main loop.
i=1
while (i<50000):
f = open("Voltage_standards4.txt", "a")
i=i+1
f.write(time.asctime(time.localtime(time.time())))
f.write("\t")
inst = rm.open_resource(HP34420A)
inst.write("ROUTe:TERMinals FRONt1;")
f.write(inst.query(":READ?").rstrip('\r\n'))
f.write("\t")
inst = rm.open_resource(HP34420A)
inst.write("ROUTe:TERMinals FRONt2")
f.write(inst.query(":READ?").rstrip('\r\n')) #strip return and newline characters so we get one line per set of readings
f.write("\n")
print ("Complete!")