Thursday, July 5, 2018

[Python 3] Power supply control (KIKUSUI, Regulated DC Power Supply, PMX35-3A) via USB

1. Python library used
 1) pyvisa
    Frontend library
 2) pyvisa-py
    : Compatible library able to be used instead of the proprietary library NI-VISA
     Backend library
 3) pyusb (or libsub1)
   If you cannot detect usb drive with pyusb, then install the dependencies " libusb1 "
   - pip install pyusb for pyusb,
   - pip install libusb1 for libusb1
   : I did it after installing 'libusb1'
 4)  pyserial
 
For access to USB, both pyusb and pyserial are necessary to be installed.

2. KI-VISA ( for USB driver)
 It is compliant with IVI VISA specification 5.0, and the device driver for usb compatible products is installed automatically.
 After installing this, I had a power supply with python.

 file name : kivisa_5_5_0_275(x64).exe

3. Python 3 code

import visa

rm = visa.ResourceManager()
sl = rm.list_resources()
print(sl)

inst = rm.open_resource(sl[0]) # sl[0] is KIKUSUI power supply
# To automatically find a instrument
# serialno = '0x5555555'
# for sn in sl:
#     i = sn.find(serialno)
#     if i == 0:
#        inst = rm.open_resource(i)
inst.query('*IDN?')
inst.write('*IDN?')

# Preset, can avoid the initial error when connected to power supply 
inst.write("rst; status:preset; *cls")

# inst.write('SOUR:POW:MODE ON')

# inst.write("INST P6V") # Select +6V output
inst.write('VOLT 6.0') # Set output voltage to 6.0 V
inst.write('CURR 1.0') # Set output current to 1.0 A

# Most straightforward method
# to program the power supply over the remote interface
#  inst.write("APPL P6V, 6.0, 1.0")

# Output on/off
inst.write("OUTP OFF")
inst.write("OUTP ON")


1 comment:

  1. Am trying to write variable value ='VOLT 6.0' in place of inst.write('VOLT 6.0') .Eg Variable ='VOLT 6.0' inst.write(Variable ) ,I observed Power supply error .Any Idea,Please share

    ReplyDelete