A Sample Explain™ Script

The following code is typical of a customized script. It is shown here so that you can get a feel for the overall structure and syntax of a script. If you are not familiar with object-oriented programming, this code can look particularly frightening. Don’t panic; we don’t expect you to understand this script yet.

The sample script automates a common corrosion test that determines the critical temperature at which pitting corrosion starts to occur. It does the test by running repetitive scans at different temperatures.

include “explain.exp” ; read in standard Framework library

global Pstat

global Output

function Main()

Pstat = PSTAT.New(“PSTAT”, “Pstat0”) ; Create Pstat object

if (Pstat.Open() eq FALSE) ; Open PStat object

Warning(“Can’t open the potentiostat”)

return

; Open the output file. All results will go to this file & be used later

in analysis.

Filename = “TPSCAN.DTA” ; Assign Filename

Output = OUTPUT.New(“OUTPUT”, Filename, “Output”) ; Create Output Object

if (Output.Open() eq FALSE)

Warning(“Can’t open the output file “, Filename)

return

Tinit = QUANT.New(“TINIT”, 25.0, “Start Temp. (C)”) ; Initial Temp Object

Tfinal = QUANT.New(“TFINAL”, 50.0, “Final Temp. (C)”) ; Final Temp Object

Tstep = QUANT.New(“TSTEP”, 5.0, “Temp. Step (C)”) ; Temp Step Object

; Ask user to fill in values for Tinit, Tfinal, Tstep

Setup(“Critical Pitting Temperature Scans”, Tinit, Tfinal, Tstep)

Printl(“Pitting Temperature Tests”)

Tinit.Printl() ; Print the Temperature Setup Parameters to output file

Tfinal.Printl()

Tstep.Printl()

; Create a cyclic ramp generator

; running from V=-1.0 V to 2.0 V to 0 V at 10 mV/s

; sample at 1 s intervals

Signal = VUPDN.New(“SIGNAL”, Pstat, -1.0, 2.0,0.0, 0.010, 0.010 1.0)

Pstat.SetSignal(Signal) ; Specify the signal for the Pstat object

T = Tinit.Value() ; Extract values from objects

Tf = Tfinal.Value() ; and store in variables

Ts = Abs(Tstep.Value())

if (T lt Tf) ; Temp scan going up?

while (T lt Tf)

SetTemp(T)

if (PitScan( -1.0) eq FALSE ) ; record a scan

break

T = T + Ts

else ; T > Tf temp scan going down

while (T gt Tf)

SetTemp(T)

if (PitScan( -1.0) eq FALSE )

break

T = T – Ts

SetTemp( NIL ) ; Clean up

Output.Close()

Pstat.Close()

return

function PitScan (Vinit)

; Create a curve to be run.

Curve = CPIV.New(“CURVE”, Pstat)

Pstat.SetStability(StabilityNorm) ; Set the potentiostat I/E Stability

Pstat.SetIchFilter(IchFilterSlow) ; Set the A/D I filter

Pstat.SetCASpeed(CASpeedNorm) ; Set the Control Amp stability

Pstat.SetIERange(0.1) ; Set the IE converter for big currents

Pstat.InitSignal() ; Initialize the signal

Pstat.SetCell(CellOn) ; Turn on the cell

Pstat.FindIERange() ; Run a current autorange scan

; so the initial points will be in the correct range

Status = Curve.Run() ; Actually run the curve here

Pstat.SetCell(CellOff) ; Turn off the cell

Curve.Printl() ; output curve results

Status ; make status the last thing evaluated

return ; so it will be then returned value

function SetTemp (T)

if (T eq NIL )

SetTemp(25.0) ; Recursive Function call!

return

Pstat.SetAnalogOut((T-25.0)*20.0) ; Controller = 20 mV/C, To = 25C