# Unable to send commands to power supply using pyvisa

**URL:** <https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582>\
**Category:** Support\
**Created:** [12 July 2022 10:59 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582 "2022-07-12T10:59:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prem206382](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@Prem206382](https://forum.core-electronics.com.au/u/Prem206382)\
**Post date:** [12 July 2022 10:59 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/1 "2022-07-12T10:59:54Z")

</div>

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](https://core-electronics.com.au/guides/automating-test-equipment-with-python/)

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??

```auto
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')

```

---

<div class="post-metadata">

**Author:** ![Liam](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam/32/3562_2.png) [@Liam](https://forum.core-electronics.com.au/u/Liam)\
**Post date:** [14 July 2022 03:52 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/2 "2022-07-14T03:52:02Z")

</div>

Hi Prem,

Welcome to the forum!!

What does your console output when running the following?

```auto
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

---

<div class="post-metadata">

**Author:** ![Prem206382](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@Prem206382](https://forum.core-electronics.com.au/u/Prem206382)\
**Post date:** [14 July 2022 10:38 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/3 "2022-07-14T10:38:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Prem206382](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@Prem206382](https://forum.core-electronics.com.au/u/Prem206382)\
**Post date:** [26 July 2022 04:18 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/4 "2022-07-26T04:18:26Z")

</div>

Hi Liam, James  
Any updates on this ?

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [27 July 2022 02:00 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/5 "2022-07-27T02:00:32Z")

</div>

@Prem206382 since we don’t stock this supply, we have no real way to verify the [command set](https://manualzz.com/doc/en/27994999/peaktech-1565-operation-manual). It looks like your device is found, since you are connecting to a serial device [ASRL](https://pyvisa.readthedocs.io/en/1.8/names.html).  
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

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

```

---

<div class="post-metadata">

**Author:** ![Prem206382](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@Prem206382](https://forum.core-electronics.com.au/u/Prem206382)\
**Post date:** [4 August 2022 04:42 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/6 "2022-08-04T04:42:59Z")

</div>

@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) .

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [4 August 2022 06:55 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/7 "2022-08-04T06:55:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jegan223825](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Jegan223825](https://forum.core-electronics.com.au/u/Jegan223825)\
**Post date:** [24 January 2023 08:43 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/8 "2023-01-24T08:43:14Z")

</div>

Hi, is it possible to control PeakTech 1565 power supply using serial library in Python?

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [24 January 2023 09:02 UTC](https://forum.core-electronics.com.au/t/unable-to-send-commands-to-power-supply-using-pyvisa/14582/9 "2023-01-24T09:02:46Z")

</div>

Any device that can communicate over a serial connection will be able to control the device. As it is supplied with a USB-to-Serial adapter you can assume that TTL levels will work for the serial interface. However, finding details might be difficult - even discovering the baud rate might require some digging.
