Wednesday, 18 January 2017

Tektronix TDS2024 Loging

I have Created a script for logging the measurements.

Note:
I did look at this code https://forum.tek.com/viewtopic.php?t=136170
Which is interesting but does not work with the current version of Python PyVISA lib.
Noting that this code works with version 1.8.
It also has no licence so technically it is copyrighted.  I have included the MIT licence.
With the code.  However this instrument is old so I do not know it it will be of any use to anyone.
on a side note I think VISA is a bad abbreviation for a standard as is the easily confused with the other uses of this name.


 # -*- coding: utf-8 -*-  
 """  
 Created on Tue Jan 17 14:42:26 2017  
   
 @author: craig.wroth  
   
 This Script will produce a Log File of Measurements from a Tektronix
2024B Oscilloscope. This is not the wave forms but the measurements of the 
Oscilloscope that have been set up using the Measure Button.
There is 5 available. The purpose of this is to allow for a very long time to
be monitored ie hours to days. 

See Following for More information
TDS 200-Series Digital Oscilloscope Programmer Manual
   
 Copyright (c) 2016 
 
 Permission is hereby granted, free of charge, to any person obtaining a copy  
 of this software and associated documentation files (the "Software"), to deal  
 in the Software without restriction, including without limitation the rights  
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 copies of the Software, and to permit persons to whom the Software is  
 furnished to do so, subject to the following conditions:  
   
 The above copyright notice and this permission notice shall be included in all  
 copies or substantial portions of the Software.  
   
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE  
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
 SOFTWARE.  
 """  
   
 import visa  
 import time  
 import os  
   
 rm = visa.ResourceManager()  
 alist = rm.list_resources()  
 print alist # Normaly (u'ASRL1::INSTR', u'ASRL3::INSTR', u'USB::0x0699::0x036A::C102692::INSTR')  
 #Note Our instrument is No3 Hence position 2 in list  
 inst = rm.open_resource(alist[2])  
 NewFile = time.strftime("%a%d%b%Y")+".csv"  
 Rev = 0  
 #Code to Increment File Rev on day  
 while os.path.exists(NewFile) == True:  
   NewFile = time.strftime("%a%d%b%Y")+"rev"+str(Rev)+".csv"  
   Rev = Rev+1  
     
 WF = open(NewFile,'w') #WF -> Working File  
 WF.write("Log File started ")  
 WF.write(time.asctime( time.localtime(time.time()) ))  
 WF.write("\n")  
 WF.close()  
   
 Stime = time.time() #Start Time  
 Duration = 0.1  #Time of test in mins  
 EndTime = Stime + Duration*60  
 SampleTime = 2 # Time between samples in sec note less that 1 not practical  
   
 WF = open(NewFile,'a')  
 WF.write("Time,Measure1,Measure2,Measure3,Measure4,Measure5\n")  
 inst.write(":header off")  
 WF.write("Measure Description,")  
 astring = inst.query("MEASUrement:MEAS1?")  
 print astring   
 WF.write(astring[:len(astring)-1] +",")  
 astring = inst.query("MEASUrement:MEAS2?")  
 print astring   
 WF.write(astring[:len(astring)-1] +",")  
 astring = inst.query("MEASUrement:MEAS3?")  
 print astring   
 WF.write(astring[:len(astring)-1] +",")  
 astring = inst.query("MEASUrement:MEAS4?")  
 print astring   
 WF.write(astring[:len(astring)-1] +",")  
 astring = inst.query("MEASUrement:MEAS5?")  
 print astring   
 WF.write(astring[:len(astring)-1] +",")  
 WF.write("\n")  
   
 inst.write(":header on")  
 while time.time() < EndTime :  
   WF.write(time.strftime("%X")+",")  
   atime = time.time()    
   print (time.strftime("%X"))  
   #print (atime)  
   atime = atime%1 #obtain fractions of seconds  
   #print (atime)  
   astring = inst.query("MEASUrement:MEAS1:VALue?")  
   astring = astring[len("MEASUrement:MEAS1:VALue?"):len(astring)-1] #Befor I discovered inst.write(":header off")  
   WF.write(astring +",")  
   astring = inst.query("MEASUrement:MEAS2:VALue?")  
   astring = astring[len("MEASUrement:MEAS2:VALue?"):len(astring)-1]  
   WF.write(astring +",")  
   astring = inst.query("MEASUrement:MEAS3:VALue?")  
   astring = astring[len("MEASUrement:MEAS3:VALue?"):len(astring)-1]  
   WF.write(astring +",")  
   astring = inst.query("MEASUrement:MEAS4:VALue?")  
   astring = astring[len("MEASUrement:MEAS4:VALue?"):len(astring)-1]  
   WF.write(astring +",")  
   astring = inst.query("MEASUrement:MEAS5:VALue?")  
   astring = astring[len("MEASUrement:MEAS5:VALue?"):len(astring)-1]  
   WF.write(astring +",")  
   WF.write("\n")  
   time.sleep((1-atime)+(SampleTime-1))  
   
   
   
   
 print ("The New File is "+NewFile)   
 print (time.asctime( time.localtime(time.time()) ))  
   
   
   
 WF.close()  
   
 inst.close()  
   

No comments:

Post a Comment