Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

:: SCPI commands thru RS232

2015, 2015-P, 2016, 2016-P
Post Reply
oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

:: SCPI commands thru RS232

Post by oootoke » October 3rd, 2015, 9:22 pm

hello everyone
i am a new owner of a rather fabulous piece of used K2015 THD. i am currently trying to use/try the remote command side of things (RS232) to explore this gear further. i am very new (noob) to benchbased DMMs, i hope to garner more experience (and correct methods) to use this beast :) i hope to receive some kind help/tips :)

atm, i am able to to use ":FETC?\r" in python to draw out some useful physical realtime measurements :D
the method and gear --> WinXP SP3 --> python 2.7 (with pyserial 2.7/xlwt) --> prolific RS232(USB) --> K2015THD
the nooby code

Code: Select all

import time
import serial  # additional addon library package
import math
import xlwt # additional addon library package
import os
SHTR = 40 #row limit of datasheet 65535
SHTC = 2 #column limit of datasheet 1024
SHTC -= 1 #in XLWT, first physical column is marked zero
RLIM = 65535 # row limit of opencalc
CLIM = 1024 # column limit of opencalc
FLIM = 4 #file limit, number of files to save
out=''
VV=''
print "TEST CPU clock   ","%+0.9f"%(time.clock())
TT = 0
float (TT)
CC = 0
int(CC)

ser = serial.Serial(  # RS232 port configuration
	port='COM3',
	baudrate=4800,
	parity=serial.PARITY_NONE,
	stopbits=serial.STOPBITS_ONE,
	bytesize=serial.EIGHTBITS,
	xonxoff=True,
	timeout=3,
	rtscts=False,
	dsrdtr=False
)

def cls():
	os.system(['clear','cls'][os.name == 'nt'])

def CHKS():
	ser.close() # RS232 port close and re-open
	time.sleep(0.1)
	ser.open()
	time.sleep(0.1)
	return
	
def READSS():
	ser.write(':FETCh?\r')  #\r\n char term = CR LF
	time.sleep(0.05)  #output cycle delay
	out=''
	while ser.inWaiting() > 0:
		out += ser.read(16)
		TT = "{:+9.2f}".format(time.clock())
		if out != '':
			out=out.rstrip()
			VV = out
			return VV,TT

def range(R1, R2, R3):
	y = R1
	while y < R2:
		yield y
		y += R3

def range(R4, R5, R6):
	X = R4
	while X < R5:
		yield X
		X += R6

def range(F1, F2, F3):
	FF1 = F1
	while FF1 < F2:
		yield FF1
		FF1 += F3

for FF1 in range(0,FLIM,1):
	wb = xlwt.Workbook()
	ws = wb.add_sheet("DATA")
	
	for y in range(0,SHTC,2):
	
		for x in range(0,SHTR,1):
		
			VV,TT = READSS()
			VV = float(VV)
			VV = "{:+0.12f}".format(VV)
			print "   ","%06d"%y,"%06d"%x, VV , TT
			ws.write(x,y,TT)
			ws.write(x,y+1,VV)
			CC +=1
	
	FN =''
	FN = "DATA_" + str(FF1) +".xls"
	print "  sheet full, total entries", CC
	print "  sheet written to", FN
	wb.save(FN)
	
	
exit()
so far so good. @ 4.8kbps, i was able to retrieve reading @ approx 14Hz rate. at some point of code testing, i was able to get about 50Hz rate but with some instability (regarding this issue of instability, i have some suspicion there could be a problem (or operating limitation) i do not know of :?: )

as i read the K2015 manual PDF, i noticed that there is (page 5-31) a DREAL FORMat. i try to activate this but it did not seem to "appear" in FETCh. am i to assume that FETCh will not be issued numeric DREAL but only ASCII ?

i am furthering the python "exploits" by trying to change the DMM measuring mode to say ":SENSe:FUNC DIOD". however when i try to issue this command,

ser.write(':SENS:FUNC DIOD')
(i tried this command with and without "\r", i am not sure if there should be \r?)
the DMM also does not respond. what could i have missed? i have tried this on a clean power up, and sometimes after a few tries, the RS232 may jam up. do i assume the RS232 USB interface might be faulty?

then i also tried to read some other parameters of K2015 after failing to set a SENS/FUNC, 1 of which is the *ESR?
i use this

Code: Select all

import time
import serial
import array
# configure the serial connections
ser = serial.Serial(
	port='COM3',
	baudrate=4800,
	parity=serial.PARITY_NONE,
	stopbits=serial.STOPBITS_ONE,
	bytesize=serial.EIGHTBITS,
	xonxoff=True
)

ser.close()
ser.open()
ser.isOpen()

while True :
	ser.write('*ESR?\r')
	time.sleep(0.1)
	out=''
	C2 = 0
	C1 = ser.inWaiting()
	AA1 = ''
	print " SER",C1
	#array.CC(c) = 0
	while ser.inWaiting() > 0:
		AA1 += ser.read(1)
		C3 = ser.inWaiting()
		TT = "{:+9.2f}".format(time.clock())
		print TT,"- SER-",C1 ,"- SS-",C3 , "- AA1-", AA1, "-|"
		#if AA1 != '' or '\r' :
		#	AA2 = bin(int(AA1))
		#	print "AA2", AA2
		#	AA2 = format(AA2, '08b')
		#	print "AA2", AA2
		#	AA3 = format(AA2, '08b')
		#	print AA1, AA2, AA3
					#out=out.rstrip()
		#	print (time.time(),out)
else : exit()
	  
the STRING returned is interesting. serial length is 2, the last char "|" is sometimes flipped over, so could it be the K2015 is trying to issue CR+LF ? i need some enlightenment on this as i have set only "CR" in the K2015, and i seem to be looking at a line-fed (LF) printed onscreen (see image http://i.imgur.com/KdvPd3P.jpg) :)

any help most very appreciated :) tyvm for reading such a long post :P (i need to add that i am about 4 days old in python, there could have been some poor interpretation of my coding/understanding of python)

kamsa hamida !

oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

Re: :: SCPI commands thru RS232

Post by oootoke » October 3rd, 2015, 10:13 pm

as i further try SCPI things with the K2015. the data returned gave me an answer to the question of why i cant set DREAL with

ser.write(':FORM:DATA DREAL\r')
time.sleep(0.7) #output cycle delay
ser.write(':FORM:DATA?\r')
time.sleep(0.1)

the VFD returns a error +808, which the error page i didnt read into depth. ASCII only with RS232 (i try to read back into pages around 4-4, there doesnt seem to be any mention of that, or it could be a norm i do not know of). i guess that comes with zero working experience with RS232 communication (or any protocol). on the other hand, when the K2015 beeps during this RS232 exercise, i wonder if it is to acknowledge the error OR to acknowledge command recieved to change FORMat? does anyone know?

however, the problem remains which i must unravel. how to send SCPI properly to ask the K2015 to change from VOLT to DIOD :?: :)

brian.d.smith
Keithley Applications
Keithley Applications
Posts: 402
Joined: June 10th, 2013, 6:00 am
Country: United States

Re: :: SCPI commands thru RS232

Post by brian.d.smith » October 4th, 2015, 7:06 pm

Below is a Python program that controls the model 2015. I agree that the model 2015 is a very nice DMM.

Code: Select all


# This Python program communicates with a Keithley model 2015 DMM over RS232 via
# a 9-pin serial cable connected between the Windows PC and the model 2015.
# The instrument is configured via the front panel for RS232 communications at 9600 baud
# with no flow control and CRLF line termination.


import visa                                #   NI VISA
import time                                #   Python time module
A = visa.instrument("ASRL1::instr")        #   COM1 assigned to A
print (A.ask('*IDN?\r\n'))                 #   Query identity and print
time.sleep(1)                              #   Pause 1 second
A.write("*RST\r\n")                        #   reset the instrument    
A.write("RES:NPLC 1\r\n")                  #   set NPLC to 1
A.write("TRIG:DEL 0\r\n")                  #   set trigger delay to 0
A.write("SENS:FUNC 'RES'\r\n")             #   set the measurement function to 2-wire ohms
A.write("SAMP:COUN 8\r\n")                 #   set sample count to 8 (instrument takes 8 measurements)
A.write("TRIG:COUN 1\r\n")                 #   set trigger count to 1 ( test is run 1 time)
A.write("TRAC:FEED:CONT NEXT\r\n")         #   the storage process starts, fills the buffer and then stops
A.write("FORM:ELEM READ\r\n")              #   specifies the elements in the string for the measurements    
A.write("TRAC:CLE\r\n")                    #   clears the buffer
A.write("INIT\r\n")                        #   takes the instrument out of the idle state                        
print (A.ask("TRAC:DATA?\r\n"))            #   retrieves the readings from the trace buffer  


oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

Re: :: SCPI commands thru RS232

Post by oootoke » October 5th, 2015, 1:21 am

Hi Brian, thanks for the addon. i installed visa 1.8. and tried some test code.

ref to the 1.8 visa PDF (page 7). everything works until rm.open_resources('blablabla'). the code could retrieve what the keithley configuration panel set (ie : ASLR1::INSTR) but failed to execute rm.open_resources('blablabla'). i dont suppose you know how to unravel this? or point me to a thread that is solved? ( i have a stinking suspicion that the prolific RS232 is the culprit, but i couldnt figure out why i could recieve data w/o problems thru pyserial but not everything else, i have logged quite abit of raw tests http://2.bp.blogspot.com/-Hncjj7L1oz4/V ... d-1_13.jpg)

oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

Re: :: SCPI commands thru RS232

Post by oootoke » October 5th, 2015, 3:39 am

update. i just recieved a new FTDI USB RS232 interface, this device seem to have solved the problems of transmitting commands to the keithley (i have 2 prolific RS232, and both are seemingly crap, they are genuine prolific, 1 doesnt respond, the other recieves data well but doesnt transmit commands to control the keithley, i think on your side it be best to tell everyone to use FTDI as the defacto RS232 interface). the PyVISA and VISA side of things are still not working thru RS232, i suppose these are not as easy to unravel.

thanks for your time Brian and for showing me the VISA stuff. :D much appreciated

brian.d.smith
Keithley Applications
Keithley Applications
Posts: 402
Joined: June 10th, 2013, 6:00 am
Country: United States

Re: :: SCPI commands thru RS232

Post by brian.d.smith » October 5th, 2015, 5:48 am

I did not originally get that you are using a USB-to-RS232 dongle. That explains the problem.

My setup is a Dell laptop with a Dell docking station. The docking station provides the RS232 port.

Great to hear that you have your setup working now. Enjoy!

oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

Re: :: SCPI commands thru RS232

Post by oootoke » October 8th, 2015, 9:14 pm

hello again Brian

in going thru some of the workings of the 2015THD, i wasnt entirely sure of what the APERTURE setting does. is there some material i could read from keithley regarding this operating parameter?

Dale C
Keithley Applications
Keithley Applications
Posts: 2842
Joined: June 10th, 2010, 6:22 am
Country: United States
Contact:

Re: :: SCPI commands thru RS232

Post by Dale C » October 12th, 2015, 6:33 am

Aperture is the time the A/D convert "looks" at the input signal.
It is related to PLC(Power Line Cycle).
NPLC and Aperture mean the same thing but a little different.
NPLC is the Number of Power Line Cycles the A/DS converter looks at the signal.
Aperture is the time the A/D converter looks at the signal.

oootoke
Posts: 7
Joined: October 3rd, 2015, 8:42 pm
Country: Singapore

Re: :: SCPI commands thru RS232

Post by oootoke » November 27th, 2015, 6:18 am

hello again, my dear keithley advisors ! i hope you are all in good health.
i am still learning more about the K2015 THD (very very slowly lol)

my new question is about repeating averaging usage. as told by fellow forum members, HP 3458a primarily extends its NPLC range upwards by averaging NPLC 10 readings. as the 2015 have a max NPLC of 10. am i right to conclude that by using the "repeating average" function correctly, i could scale this NPLC "block" up by "100 averages" and obtain mathematically a NPLC 1000 ? or do i use "moving average", i am thinking "repeating average" is the correct averaging?

ie : either NPLC 10 * REP 100 ... or NPLC 10 * MOV 100 (figuratively)

thanks for your time

brian.d.smith
Keithley Applications
Keithley Applications
Posts: 402
Joined: June 10th, 2013, 6:00 am
Country: United States

Re: :: SCPI commands thru RS232

Post by brian.d.smith » December 15th, 2015, 6:33 am

From the model 2015 Users Manual page 3-4


Filter types
The moving average filter (Figure 3-1) uses a first-in, first-out stack. When the stack becomes
full, the measurement conversions are averaged, yielding a reading. For each subsequent
conversion placed into the stack, the oldest conversion is discarded, and the stack is re-averaged,
yielding a new reading.
For the repeating filter (Figure 3-1), the stack is filled and the conversions are averaged to
yield a reading. The stack is then cleared and the process starts over. Choose this filter for scanning
so readings from other channels are not averaged with the present channel.

Response time
The filter parameters have speed and accuracy tradeoffs for the time needed to display, store,
or output a filtered reading. These affect the number of reading conversions for speed versus
accuracy and response to input signal changes.

Post Reply

Return to “Series 2015 & 2016 THD/Audio Analyzers”

Who is online

Users browsing this forum: No registered users and 2 guests