Author Topic: Controlling Agilent 6632B from python via RS232  (Read 8305 times)

0 Members and 1 Guest are viewing this topic.

Offline kt315Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Controlling Agilent 6632B from python via RS232
« on: July 10, 2014, 02:50:39 am »

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: [Select]
#!/usr/bin/python

import serial

psu=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: [Select]
#!/usr/bin/python

import visa

lib = 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:
0
252
254
252
0
252
254
252
0

PyVisa 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.  |O |O |O |O

The settings on the PSU are as follows:
ADDRESS 5
REMOTE FP ENAB
LANG SCPI
FLOW NONE
PARITY NONE
BAUDRATE 9600
INTF 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 ...
 

Offline alex.forencich

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: us
    • Alex Forencich
Re: Controlling Agilent 6632B from python via RS232
« Reply #1 on: July 10, 2014, 05:07:25 am »
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? 

Python-based instrument control: Python IVI, Python VXI-11, Python USBTMC
 

Offline elliott

  • Regular Contributor
  • *
  • Posts: 175
  • Country: us
Re: Controlling Agilent 6632B from python via RS232
« Reply #2 on: July 10, 2014, 07:45:53 am »
Have you tried sending it commands directly from a terminal?
 

Online AndyC_772

  • Super Contributor
  • ***
  • Posts: 4255
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Controlling Agilent 6632B from python via RS232
« Reply #3 on: July 10, 2014, 07:57:40 am »
Disable ''REMOTE FP", then you'll be able to set the interface to RS232.

Offline kt315Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Controlling Agilent 6632B from python via RS232
« Reply #4 on: July 10, 2014, 01:17:37 pm »
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.
 

Offline senseless

  • Contributor
  • Posts: 32
  • Country: de
Re: Controlling Agilent 6632B from python via RS232
« Reply #5 on: May 29, 2016, 12:11:40 am »
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: [Select]
sudo picocom --omap crcrlf -c -b 9600 /dev/ttyUSB0
picocom v2.1

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : yes
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        :
omap is        : crcrlf,
emap is        : crcrlf,delbs,

Type [C-a] [C-h] to see available commands

Terminal ready
*IDN?
HEWLETT-PACKARD,6632B,0,A.01.04

Thanks for using picocom
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf