Unable to send commands to power supply using pyvisa

Hello all,

i am trying to automate the control of programmable power supply (peaktech 1565) using pyvisa.
i have gone through the reference
Automating Test-Equipment with Python - Tutorial Australia

so i used the commands based on the peaktech 1565 model manual. But I unable to send the commands. Could you check the following code and let me know , whats wrong??

import pyvisa
from pyvisa import constants

rm = pyvisa.ResourceManager()
rm.list_resources()
print("Resources detected\n{}\n".format(rm.list_resources()))
psu = rm.open_resource('ASRL3::INSTR', read_termination='\r', write_termination='\r',access_mode= pyvisa.constants.AccessModes.no_lock)  # Put your device IDs here
# psu = rm.open_resource('ASRL3::INSTR')
# psu.baud_rate = 9600
# psu.read_termination = '\r'
# psu.write_termination = '\r'
# psu.timeout = 2000
# values = "SOUT0"
# psu.write("SOUT0")
# psu.write_ascii_values('val',values)
# psu.query(":SOUT0")
# print(psu.session)
# print(psu.visa_attributes_classes)

# print(psu.get_visa_attribute(constants.VI_ATTR_RSRC_NAME))
# print('baudrate:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_BAUD))
# print('parity:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_PARITY))
# # print(psu.get_visa_attribute(constants.VI_ATTR_ASRL_CONNECTED))
# print('data bits:', psu.get_visa_attribute(constants.VI_ATTR_ASRL_DATA_BITS))
# print('stop bits:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_STOP_BITS))
# print('flowcntrl:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_FLOW_CNTRL))
# print('TMO:',psu.get_visa_attribute(constants.VI_ATTR_TMO_VALUE))
# print('TERminal enabled:',psu.get_visa_attribute(constants.VI_ATTR_TERMCHAR_EN))
# print('terminal value:',psu.get_visa_attribute(constants.VI_ATTR_TERMCHAR))
# print(psu.get_visa_attribute(constants.VI_ATTR_ASRL_ALLOW_TRANSMIT))
# print('eol:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_END_IN))
# print('eol:',psu.get_visa_attribute(constants.VI_ATTR_ASRL_END_OUT))
psu.write('VOLT140')
2 Likes

Hi Prem,

Welcome to the forum!!

What does your console output when running the following?

import pyvisa
rm = pyvisa.ResourceManager()
rm.list_resources()

After running your code I’d also get the log using pyvisa.log_to_screen() at the end to see what is happening.

Liam

Hi Liam,

when i run those 3lines, there no output.

but when i run the below code:
import pyvisa
rm = pyvisa.ResourceManager()
rm.list_resources()
print(“Resources detected\n{}\n”.format(rm.list_resources()))

i got the console output as:
Resources detected
(‘ASRL3::INSTR’,)

when i runned the line : pyvisa.log_to_screen()

i got the ouput like this :
2022-07-14 16:06:48,754 - pyvisa - DEBUG - Closing ResourceManager (session: 4097)
2022-07-14 16:06:48,758 - pyvisa - DEBUG - viClose(4097,) → 0

1 Like

Hi Liam, James
Any updates on this ?

1 Like

@Prem206382 since we don’t stock this supply, we have no real way to verify the command set. It looks like your device is found, since you are connecting to a serial device ASRL.
Are you able to query the maximum voltage allowable? (command GMAX from that command set). Is it possible your setpoint is being rejected because it is too high?
Do you have success with psu.write('VOLT1') instead?

How about just toggling the output with

# don't forget to import sleep!
while True:
    psu.write("SOUT1")
    sleep(1)
    psu.write("SOUT0")
    sleep(1)
1 Like

@Michael Thank you so much ,.

Its working now. we need to give some delay after the commands sent to Programmable supply.
Like → sleep(1) or time.sleep(1) .

1 Like

That’s awesome @Prem206382! So happy you found a solution :smiley:
Thanks for sharing it here so others can benefit from your findings :+1: