Controlling Agilent 6632B from python via RS232 - Page 1
Forum section: electronics / testgear

author: kt315
author_rank: Regular Contributor
timestamp: July 10, 2014, 02:50:39 am
content: Hi,After reading quite a few posts relaying feedback on the PSU, I decided to kill my jealousy before it killed me and got myself a new 10 years old 6632B. I've been extremely happy with up to the point when I decided to try to connect to it via RS232...I am using USB-serial bridge, and tried both pyvisa (which claims to support RS232) and pyserial equally unsuccessful.Here is the code that I am using.PySerial:Code:#!/usr/bin/pythonimport serialpsu=serial.Serial("/dev/tty.usbserial", 9600, timeout=1)psu.write("*IDN?\r\n")while 1:a=psu.read()print "%d\n" % ord(a)And PyVisa:Code:#!/usr/bin/pythonimport visalib = visa.VisaLibrary("/Library/Frameworks/visa.framework/visa")rm=visa.ResourceManager();print rm.list_resources()psu=visa.instrument("ASRL1::INSTR")psu.write("*IDN?\r\n")print(psu.read())I tried different combinations of the line terminator, which did not seem to make any difference.PySerial version output looks something like this:025225425202522542520PyVisa version just times out.When either of the versions is running, PSU switches display, which implies they are trying to talk to each other.All in all it looks like the settings for the serial connection are wrong, but I am out of ideas how to fix it.The settings on the PSU are as follows:ADDRESS 5REMOTE FP ENABLANG SCPIFLOW NONEPARITY NONEBAUDRATE 9600INTF HPIB (this one is interesting: when I switch it to RS232, it changes display message to "RS232 is in use", but does not keep the settings)At this point I am trying to do "hello world" type of application -- I am pretty sure I can take it from there.Any hints would be much appreciated ...

author: alex.forencich
author_rank: Frequent Contributor
timestamp: July 10, 2014, 05:07:25 am
content: For some reason Agilent supplies use a really whacky serial port configuration. You need a null modem cable/adapter in order for it to work correctly. This supply is nice in that it allows you to select the flow control setting; on the E3600 series I have not found a way to do that so it is stuck with DSR-DTR, which is not supported on Linux and so it needs to be emulated in software. Take a look at my Python IVI library, it has a wrapper script for pyserial that works around some of these issues.If you are using a null modem cable, the baud rate might be wrong. Getting large values can indicate that the receiver is running much faster than the transmitter. Can you check both the TX and RX sides to see if the serial rates match?

author: elliott
author_rank: Regular Contributor
timestamp: July 10, 2014, 07:45:53 am
content: Have you tried sending it commands directly from a terminal?

author: AndyC_772
author_rank: Super Contributor
timestamp: July 10, 2014, 07:57:40 am
content: Disable ''REMOTE FP", then you'll be able to set the interface to RS232.

author: kt315
author_rank: Regular Contributor
timestamp: July 10, 2014, 01:17:37 pm
content: Ho-ho !!!!Disabling FP did the trick for me ... At least I've got a meaningful response from it.Thanks a lot, guys, much appreciated.

author: senseless
author_rank: Contributor
timestamp: May 29, 2016, 12:11:40 am
content: Just for the record: If you want to communicate directly from a terminal with the unit, you have to be aware of the CR/LF difficulty. Just hitting Enter was not enough in my case. The following example shows how to send the appropriate CR+LF instead of CR with picocom:Code:sudo picocom --omap crcrlf -c -b 9600 /dev/ttyUSB0picocom v2.1port is : /dev/ttyUSB0flowcontrol : nonebaudrate is : 9600parity is : nonedatabits are : 8stopbits are : 1escape is : C-alocal echo is : yesnoinit is : nonoreset is : nonolock is : nosend_cmd is : sz -vvreceive_cmd is : rz -vv -Eimap is :omap is : crcrlf,emap is : crcrlf,delbs,Type [C-a] [C-h] to see available commandsTerminal ready*IDN?HEWLETT-PACKARD,6632B,0,A.01.04Thanks for using picocom