Driving a programmable power supply over SCPI from a PLC
*ADR, current and voltage setpoints with SOUR:CURR and SOUR:VOLT, output switching and telemetry readback. It is the exact pattern we run in a real fuse test bench deployment.Why SCPI plus a PLC beats a lab PC
pyserial is all it takes to speak to the instrument.The SCPI command set that matters
*ADR n selects the unit on a shared bus, SOUR:VOLT caps the voltage (5 V for fuse testing), SOUR:CURR sets the test current, and OUTP ON/OFF gates the power stage. A 50 ms pause after each write keeps the XG's parser happy at 9600 baud.Ramping instead of stepping
MEAS:CURR?) at each stage, and a finally block guarantees the output is cut even if the script crashes mid-test.A snippet from the implementation
Straight from the example as deployed on the Raspberry PLC 19R — copy it freely:
def current_ramp(supply, target_a, step_a=5.0, wait_s=0.5):
"""Raise the setpoint in steps to avoid stressing shunt and wiring."""
setpoint = 0.0
while setpoint < target_a:
setpoint = min(setpoint + step_a, target_a)
supply.set_current(setpoint)
print(" setpoint %.1f A -> supply measures %.2f A"
% (setpoint, supply.read_current()))
time.sleep(wait_s)The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Does this work with other SCPI power supplies?
Mostly yes. SOUR:CURR, SOUR:VOLT and OUTP are standard SCPI, so Keysight, Rigol or EA supplies accept the same core commands. Only the addressing (*ADR) and timing details are Sorensen-specific.
Why 9600 baud instead of something faster?
The XG's serial interface is most reliable at 9600 with short pauses between commands. Test sequences change setpoints every few hundred milliseconds at most, so bandwidth is never the bottleneck.
How do I know the real current matches the setpoint?
You measure it independently. In the full bench the current is read from a shunt through an ADS1015 ADC, and a closed-loop calibration routine trims the SCPI setpoint until the measured value converges.