From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2651 A TSP Script conversion to LabVIEW

Solved!
Go to solution

Hello,

 

I have a problem on the conversion of any TSP scripts that contain call functions and for end loops. I'm new to TSP scripts with trigger models. I used Test Script Builder (TSB) tool and am able to execute any TSP and generate raw data but I seems unable to convert most TSP codes in LabVIEW VISA command or TSP loader LV and execute it to generate data.. I can't find any tutorial or examples how to do it. 

Let's say.. Use the example KE2651A_Fast_ADC_Usage.tsp (pulse) and I'll just focus on function CapturePulseV(pulseLevel, pulseWidth, pulseLimit, numPulses) portion. I saw few LV examples that said loadscript myscript and close it by endscript.  I did many different approaches and I kept getting errors especially from print function that I am not able to generate any data via LV by having it to read data from buffer from inside the instrument. Some approaches, I got no error but no data.. Some approaches, I got -285 error.

The portion of the pulse TSP code that works in TSB is here (I am not including loadscript and endscript) and what is the PROPER way to re-code it to LabVIEW and execute it and get data? Thanks:

function CapturePulseV(pulseLevel, pulseWidth, pulseLimit, numPulses)
	if (numPulses == nil) then numPulses = 1 end

	-- Configure the SMU
	reset()
	smua.reset()
	smua.source.func			= smua.OUTPUT_DCVOLTS
	smua.sense					= smua.SENSE_REMOTE
	smua.source.rangev			= pulseLevel
	smua.source.levelv			= 0		-- The bias level
	smua.source.limiti			= 5		-- The DC Limit
	smua.measure.autozero		= smua.AUTOZERO_ONCE

	-- Use a measure range that is as large as the biggest
	-- possible pulse
	smua.measure.rangei			= pulseLimit
	smua.measure.rangev			= pulseLevel

	-- Select the fast ADC for measurements
	smua.measure.adc			= smua.ADC_FAST

	-- Set the time between measurements.  1us is the smallest
	smua.measure.interval		= 1e-6

	-- Set the measure count to be 1.25 times the width of the pulse
	-- to ensure we capture the entire pulse plus falling edge.
	smua.measure.count			=
					(pulseWidth / smua.measure.interval) * 1.25

	-- Prepare the reading buffers
	smua.nvbuffer1.clear()
	smua.nvbuffer1.collecttimestamps	= 1
	smua.nvbuffer1.collectsourcevalues	= 0
	smua.nvbuffer2.clear()
	smua.nvbuffer2.collecttimestamps	= 1
	smua.nvbuffer2.collectsourcevalues	= 0
	-- Can't use source values with async measurements

	-- Configure the Pulsed Sweep setup
	-----------------------------------
	-- Timer 1 controls the pulse period
	trigger.timer[1].count			= numPulses - 1
	-- -- 1% Duty Cycle
	trigger.timer[1].delay			= pulseWidth / 0.01
	trigger.timer[1].passthrough	= true
	trigger.timer[1].stimulus		= smua.trigger.ARMED_EVENT_ID

	-- Timer 2 controls the pulse width
	trigger.timer[2].count			= 1
	trigger.timer[2].delay			= pulseWidth - 3e-6
	trigger.timer[2].passthrough	= false
	trigger.timer[2].stimulus		=
				smua.trigger.SOURCE_COMPLETE_EVENT_ID


	-- Configure SMU Trigger Model for Sweep/Pulse Output
	-----------------------------------------------------
	-- Pulses will all be the same level so set start and stop to
	-- the same value and the number of points in the sweep to 2
	smua.trigger.source.linearv(pulseLevel, pulseLevel, 2)
	smua.trigger.source.limiti		= pulseLimit
	smua.trigger.measure.action		= smua.ASYNC
	-- We want to start the measurements before the source action takes
	-- place so we must configure the ADC to operate asynchronously of
	-- the rest of the SMU trigger model actions
	
	-- Measure I and V during the pulse
	smua.trigger.measure.iv(smua.nvbuffer1, smua.nvbuffer2)

	-- Return the output to the bias level at the end of the pulse/sweep
	smua.trigger.endpulse.action	= smua.SOURCE_IDLE
	smua.trigger.endsweep.action	= smua.SOURCE_IDLE
	smua.trigger.count				= numPulses
	smua.trigger.arm.stimulus		= 0
	smua.trigger.source.stimulus	= trigger.timer[1].EVENT_ID
	smua.trigger.measure.stimulus	= trigger.timer[1].EVENT_ID
	smua.trigger.endpulse.stimulus	= trigger.timer[2].EVENT_ID
	smua.trigger.source.action		= smua.ENABLE


	smua.source.output				= 1
	smua.trigger.initiate()
	waitcomplete()
	smua.source.output				= 0

	PrintPulseData()
end

function PrintPulseData()
	print("Timestamp\tVoltage\tCurrent")
	for i=1, smua.nvbuffer1.n do
		print(string.format("%g\t%g\t%g",
							smua.nvbuffer1.timestamps[i],
							smua.nvbuffer2[i],
							smua.nvbuffer1[i]))
	end
end

 

0 Kudos
Message 1 of 8
(6,715 Views)

Hi William,

 

It looks like the Test Script Builder you mentioned is not a National Instruments product, so it may be easier for us to help you from the LabVIEW end of things.  Could you post the code you were trying to run in LabVIEW, as well as any more detail you have on the error messages?

 

 

Regards,

0 Kudos
Message 2 of 8
(6,613 Views)

Oh, I'm sorry for not making my original post more clear with more information.  The instrument that I am working on is Keithley 2651-A and it uses Lua programming language. I was hoping to find a developer who is experienced with LV AND Keithley instrument scripting using its language. I am able to use script using Keithley's TSB software or TSP express inside it's instrument memory and generate data. But my biggest problem is to have LabVIEW to load the script into the instrument memory and run it then have LabVIEW obtain the data off instrument's memory to be used for data analysis within LV.

0 Kudos
Message 3 of 8
(6,441 Views)

Aren't you using the 2651 LabVIEW driver from Keithley? I haven't used it but there are numerous functions related to scripts and TSP.

0 Kudos
Message 4 of 8
(6,435 Views)

Yeah, there are several LV drivers but they were tailored and also I got some errors from those drivers as well. I am customizing "drivers" to do specific tasks I need to do. Those drivers are generic and it gets "screwed" up to do higher level tasks if I do not know how to script at all. I tried drivers alone on many approaches and was not able to get data at all and also got various errors or nothing came out. I decided to scrap drivers and focus my time on scripting without help of LV and finally got data I need directly from Keithley instrument into TSB or TSP express and understand how scripting works using trigger model, etc. With that, I would be able to develop my own customized LV drivers with all built-in scripts to handle any Keithley tasks I need to do in the long run. Once I finally can bridge the LV and Keithley for obtaining data then everything should be better. Basically, if script works just fine in TSB and generate data then try it via LV then should work fine with same data by loading script via LV using loadscript /endscript shell. Oddly, even with documentation, it said that just add loadscript/endscript will work for any user-owned programs such as LV but I kept getting -285 error trying to generate data via LV. 

0 Kudos
Message 5 of 8
(6,431 Views)

I don't quite understand where LabVIEW fits in. You first said you were trying to convert a script to LabVIEW and now you are saying you want to load a working script? The error code you get is one from the instrument. I don't have the manual so I would suggest you use yours to determine what the error means. 

0 Kudos
Message 6 of 8
(6,424 Views)
Solution
Accepted by topic author William_Wood

I finally solved it myself! I have to create shell load first as per documentation but the problem was scripts with functions but I solved it by introducing separate function VISA write THEN retrieve data from instrument buffer memory directly by VISA read after that. I made TSP_Function Script Loader that simply allows us to copy/paste any TSP codes (any *.tsp) from TSB program or embedded into this loader.vi and type in function name(parameters) as defined from its own pasted script then it'll generate raw data directly in string array that can be broken in parts or re-structured in anything you want such as for graphics etc. 

That's all I really need to do so I can do any tsp codes in LV and get data out of it easily via defined function. This Loader.VI now behaves exactly the same way as keithley-made TSB program that I am using. 

 

I'm adding TSP_Function Script Loader.vi (in LV 2011+) here.

Message 7 of 8
(6,380 Views)

Ok, Since I finally am able to use any *.tsp codes onto LV platform with no problem now. For fun, I decided to import KE2651A_Fast ADC Usage.tsp (from Keithley 2651 A example code) onto LV platform using my new TSP_Function Script Loader.vi (updated) as subroutine into KE2651A_Fast ADC Usage.vi along with plots and readable data format for anyone who are interested in learning how to do it.

 

This should mimic what TSB (Test Script Builder) program behaves by dumping raw data into output but it can't be manipulated such as graphs, etc like this vi can.

 

Enjoy.

 

Both VIs are in LV 2011

KE651A_Fast ADC Usage.vi (main)

TSP_Function Script Loader.vi (subroutine)

Download All
Message 8 of 8
(6,366 Views)