We've talked a little about setting an output from a screen control in section 4.6, but this requires user input. We also talked about setting an output based on an input in section 7.1. In this section we saw that you can easily set an output channel by simply assigning a value to it. So, to set a DAC channel named ValvePosition to 3 volts (assuming no Conversion exists on the channel), we would simply do:
ValvePosition = 3
You can also apply conversions to outputs like we did with inputs in section 4.3, however, the conversions work in reverse. For inputs, the conversion takes the raw voltage (counts or other units) from the LabJack and converts it into engineering units like temperature or pressure. For outputs, the conversion takes the engineering units and converts into voltage. So, for if we had a proportional valve that takes a 0 to 5V signal and we want to be able to specify the percentage open, where 0% = 0V and 100% = 5V, the conversion would be:
Value / 20
Then, to open the valve to 60% we could just do:
ValvePosition = 60
and 3 volts would be outputted from the DAC of the LabJack.
Now as a further example, lets say we'd like to ramp the valve position from 0 to 100% over 60 seconds in steps of 1%. The script is quite simple:
// initialize valve position to 0
ValvePosition = 0
while (ValvePosition < 100)
ValvePosition = ValvePosition + 1
delay(0.6)
endwhile
Doing a ramp and soak is not much harder, just split out the while loops. Lets say we want to ramp to 40% in 20 seconds, soak for 10 seconds, ramp to 80% in 40 seconds, soak for 5 seconds, then ramp back down to 0 in 60 seconds:
// initialize valve position to 0
ValvePosition = 0
// ramp to 40
while (ValvePosition < 40)
ValvePosition = ValvePosition + 1
delay(0.5)
endwhile
delay(10) // soak
// ramp to 80
ValvePosition = 40 // this is to make the graph look good
while (ValvePosition < 80)
ValvePosition++ // this is the same as VP = VP + 1
delay(1)
endwhile
delay(5) // soak again
ValvePosition = 80
// ramp down to 0
while (ValvePosition > 0)
ValvePosition--
delay(0.75)
endwhile
One important note: these sequences won't work if you try and ramp past the highest value of the output. If you try and set an output to an invalid value you will get an Alert and the channel WILL NOT update, so the while() will never exit because ValvePosition would never reach the desired point.