You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
265 lines
8.2 KiB
Python
265 lines
8.2 KiB
Python
""" =============================================================
|
|
*** modified 2022 - four wire resistance mode
|
|
*** Institut f. Konstruktionsrechnik, Eggert Jung
|
|
============================================================= """
|
|
|
|
|
|
""" ================================================================================
|
|
*** Copyright 2019 Tektronix, Inc. ***
|
|
*** See www.tek.com/sample-license for licensing terms. ***
|
|
================================================================================ """
|
|
|
|
"""
|
|
====================================================================================================
|
|
This example configures a series of channels within the 3706A mainframe for
|
|
DCV measurement scanning. Additionally, a log file is created on a USB drive
|
|
connected to the front port of the meter and writes the measurement information
|
|
after each scan.
|
|
====================================================================================================
|
|
"""
|
|
|
|
## channel.exclusiveclose(
|
|
|
|
import socket
|
|
import struct
|
|
import math
|
|
import time
|
|
import argparse
|
|
|
|
import numpy as np
|
|
from matplotlib import pyplot
|
|
|
|
import channels
|
|
import liveview
|
|
|
|
echoCmd = 0
|
|
|
|
def instrConnect(mySocket, myAddress, myPort, timeOut, doReset, doIdQuery):
|
|
mySocket.connect((myAddress, myPort)) # input to connect must be a tuple
|
|
mySocket.settimeout(timeOut)
|
|
if doReset == 1:
|
|
instrSend(mySocket, "reset()")
|
|
if doIdQuery == 1:
|
|
tmpId = instrQuery(mySocket, "*IDN?", 100)
|
|
print(tmpId)
|
|
return mySocket
|
|
|
|
def instrDisconnect(mySocket):
|
|
mySocket.close()
|
|
return
|
|
|
|
def instrSend(mySocket, cmd):
|
|
if echoCmd == 1:
|
|
print(cmd)
|
|
cmd = "{0}\n".format(cmd)
|
|
mySocket.send(cmd.encode())
|
|
return
|
|
|
|
def instrQuery(mySocket, cmd, rcvSize):
|
|
instrSend(mySocket, cmd)
|
|
time.sleep(0.1)
|
|
return mySocket.recv(rcvSize).decode()
|
|
|
|
def Write_Data(output_data_path, dataStr):
|
|
# This function writes the floating point data to the
|
|
# target file.
|
|
#for f in floats:
|
|
ofile = open(output_data_path, "a") # append the target data
|
|
dataStr = "{0}".format(dataStr)
|
|
ofile.write(dataStr)
|
|
|
|
ofile.close() # Close the data file.
|
|
|
|
return
|
|
|
|
def Configure_Backplane(s):
|
|
instrSend(s, "reset()")
|
|
instrSend(s, "dmm.func = \"fourwireohms\"")
|
|
#instrSend(s, "dmm.nplc = 0.1")
|
|
|
|
instrSend(s, "dmm.autorange = dmm.OFF")
|
|
instrSend(s, "dmm.range = 10000")
|
|
|
|
## crossover connection is made on backplane 3 & 4
|
|
instrSend(s, 'channel.setbackplane("1001:1030", "1913")')
|
|
instrSend(s, 'channel.setbackplane("1031:1060", "1924")')
|
|
|
|
instrSend(s, 'channel.setbackplane("2001:2030", "2913")')
|
|
instrSend(s, 'channel.setbackplane("2031:2060", "2924")')
|
|
|
|
instrSend(s, 'channel.setbackplane("3001:3030", "3913")')
|
|
instrSend(s, 'channel.setbackplane("3031:3060", "3924")')
|
|
|
|
return
|
|
|
|
def diff_4W_mess(s, ch1, ch2):
|
|
instrSend(s, 'channel.exclusiveclose("{}")'.format(ch1))
|
|
instrSend(s, 'channel.close("{}")'.format(ch2))
|
|
#print(instrQuery(s, "print(dmm.measure())", 64)[:-1], end='\t')
|
|
return float(instrQuery(s, "print(dmm.measure())", 64))
|
|
|
|
def get_mapped(arr):
|
|
out = np.zeros(shape=(9, 10))
|
|
|
|
for i in range(0,90):
|
|
x, y = channels.map[i]
|
|
out[x-1][y-1] = arr[i]
|
|
|
|
return out
|
|
|
|
def get_vector_mapped(arr):
|
|
out = np.zeros(shape=(9, 10, 2))
|
|
|
|
for i in range(0,90):
|
|
x, y = channels.map[i]
|
|
out[x-1][y-1] = arr[i]
|
|
|
|
return out
|
|
|
|
def done():
|
|
instrSend(s, "beeper.beep(0.500, 440)")
|
|
instrSend(s, "beeper.beep(0.500, 440)")
|
|
instrSend(s, "beeper.beep(0.500, 440)")
|
|
instrSend(s, "beeper.beep(0.350, 349)")
|
|
instrSend(s, "beeper.beep(0.150, 523)")
|
|
instrSend(s, "beeper.beep(0.500, 440)")
|
|
instrSend(s, "beeper.beep(0.350, 349)")
|
|
instrSend(s, "beeper.beep(0.150, 523)")
|
|
instrSend(s, "beeper.beep(1.000, 440)")
|
|
instrSend(s, "beeper.beep(0.500, 659)")
|
|
instrSend(s, "beeper.beep(0.500, 659)")
|
|
instrSend(s, "beeper.beep(0.500, 659)")
|
|
instrSend(s, "beeper.beep(0.350, 698)")
|
|
instrSend(s, "beeper.beep(0.150, 523)")
|
|
instrSend(s, "beeper.beep(0.500, 415)")
|
|
instrSend(s, "beeper.beep(0.350, 349)")
|
|
instrSend(s, "beeper.beep(0.150, 523)")
|
|
instrSend(s, "beeper.beep(1.000, 440)")
|
|
|
|
def calc_vector(px, py, point_specific_matrix):
|
|
vect = [0, 0]
|
|
print("spcific point = {}, {}".format(px, py))
|
|
for x in range(9):
|
|
for y in range(10):
|
|
if(px != x or py != y):
|
|
diff = [x-px, y-py] #Abstandsvektor
|
|
mag = np.sqrt(diff[0]**2 + diff[1]**2) #betrag
|
|
vect[0] += point_specific_matrix[x][y]*diff[0] / mag
|
|
vect[1] += point_specific_matrix[x][y]*diff[1] / mag
|
|
print("{}: vect += {} / {} == {}".format([x,y],diff, mag, vect))
|
|
return vect
|
|
|
|
""" ==============================================================================================================
|
|
MAIN CODE STARTS HERE
|
|
============================================================================================================== """
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('-view', default="R")
|
|
parser.add_argument('-fromfile')
|
|
parser.add_argument('-tofile')
|
|
parser.add_argument('-ip', default="192.168.0.53")
|
|
parser.add_argument('-port', default=5025)
|
|
args = parser.parse_args()
|
|
|
|
ip_address = args.ip
|
|
port = args.port
|
|
|
|
# reserve space for matrixes
|
|
full_matrix = np.zeros(shape=(90, 90))
|
|
point_specific_matrix = np.zeros(shape=(9, 10))
|
|
|
|
|
|
t1 = time.time() # Start the timer...
|
|
|
|
if args.fromfile:
|
|
#TODO check bounds of imported matrix
|
|
full_matrix = np.genfromtxt(args.fromfile, delimiter='\t')
|
|
if args.view == "R":
|
|
viewer = liveview.ResistanceView(maximum=full_matrix.max())
|
|
for row in full_matrix:
|
|
point_specific_matrix=get_mapped(row)
|
|
viewer.updateView(point_specific_matrix)
|
|
if args.view == "V":
|
|
vectormap = np.zeros(shape=(90, 2))
|
|
i = 0
|
|
for row in full_matrix:
|
|
print(i)
|
|
point_specific_matrix=get_mapped(row)
|
|
vectormap[i] = calc_vector(channels.map[i][0], channels.map[i][1], point_specific_matrix)
|
|
i+=1
|
|
print()
|
|
|
|
|
|
else:
|
|
s = socket.socket() # Establish a TCP/IP socket object
|
|
instrConnect(s, ip_address, port, 20000, 0, 0)
|
|
|
|
Configure_Backplane(s)
|
|
|
|
if args.view == "R":
|
|
viewer = liveview.ResistanceView(maximum=4000)
|
|
|
|
x = 0
|
|
y = 0
|
|
print()
|
|
for ch1 in [*range(1001, 1031)] + [*range(2001, 2031)] + [*range(3001, 3031)]:
|
|
for ch2 in [*range(1031, 1061)] + [*range(2031, 2061)] + [*range(3031, 3061)]:
|
|
full_matrix[x][y]=diff_4W_mess(s, ch1, ch2)
|
|
if args.view == "R":
|
|
point_specific_matrix=get_mapped(full_matrix[x])
|
|
viewer.updateView(point_specific_matrix)
|
|
y+=1
|
|
y=0
|
|
x+=1
|
|
|
|
done()
|
|
|
|
# Close the socket connection
|
|
instrDisconnect(s)
|
|
|
|
if args.view == "N":
|
|
neighview = np.zeros(shape=(30,32))
|
|
|
|
i = 0
|
|
for row in full_matrix:
|
|
point_specific_matrix=get_mapped(row)
|
|
|
|
#coordinates of specific point
|
|
y_pos = channels.map[i][1] - 1
|
|
x_pos = channels.map[i][0] - 1
|
|
|
|
if(x_pos+1 < 9):
|
|
neighview[(x_pos*3)+2][(y_pos*3)+1] = point_specific_matrix[x_pos+1][y_pos]
|
|
|
|
if(x_pos-1 >= 0):
|
|
neighview[(x_pos*3)+0][(y_pos*3)+1] = point_specific_matrix[x_pos-1][y_pos]
|
|
|
|
if(y_pos+1 < 10):
|
|
neighview[(x_pos*3)+1][(y_pos*3)+2] = point_specific_matrix[x_pos][y_pos+1]
|
|
|
|
if(y_pos-1 >= 0):
|
|
neighview[(x_pos*3)+1][(y_pos*3)+0] = point_specific_matrix[x_pos][y_pos-1]
|
|
|
|
i+=1
|
|
|
|
viewer = liveview.ResistanceView(maximum=full_matrix.max())
|
|
viewer.updateView(neighview)
|
|
|
|
|
|
if args.view == "M":
|
|
viewer = liveview.ResistanceView(maximum=full_matrix.max())
|
|
viewer.updateView(get_mapped(np.mean(full_matrix, axis = 0)))
|
|
|
|
|
|
if args.tofile:
|
|
np.savetxt(args.tofile, full_matrix, delimiter="\t")
|
|
|
|
t2 = time.time()
|
|
|
|
# Notify the user of completion and the data streaming rate achieved.
|
|
print("done")
|
|
print("Total Time Elapsed: {0:.3f} s".format(t2-t1))
|
|
|
|
input("Press Enter to continue...")
|
|
exit()
|