Electronic – How to use SCPI on HP33120A via RS232

controlmeasurementrs232

I have old Hewlet Packard 33120A function generator (it should be the same type as Agilent 33120A) and I would like to control it with MCU (ATMega). The generator has RS232 and use SCPI commands.

I made simple RS232 to TTL converter with MAX232, just with RX and TX lines. According to User's guide (chapter 4, section DTR/DSR Handshake Protocol) I tied the DSR to logic TRUE (negative voltage) and DTR is not connected. This configuration should disabled hardware handshake.

Now, I can connect converter to MCU or to computer. For my first experiment I used computer and this Python script:

import serial, sys, time

if __name__ == '__main__':
        if len(sys.argv) < 2:
                print 'Usage: %s <serial_port>' % sys.argv[0]
                sys.exit(1)

        s = serial.Serial(port=sys.argv[1], baudrate=2400, bytesize=8, parity='N', stopbits=2, timeout=None, xonxoff=0, rtscts=0)

        time.sleep(0.5)
        s.write('\n*CLS\n')
        time.sleep(0.5)
        s.write('SYST:REM\n')
        time.sleep(0.5)
        s.write('APPL:SIN 30E+3, 0.1\n')


        s.close()

This works without any problem. The generator set its output to 30kHz as expected. The problem is, when I try to read some response from generator. For example, this should return device name:

        s.write('*IDN?\n')
        print s.realine()

I am pretty sure the response is stored in generator's output buffer but no data are actually transmitted.

Is there any command to trigger transmitting data from buffer? Or do I need enable hardware handshake?

Is there anyone who has this generator? Do you use it with RS232 and SCPI?

Best Answer

The easiest way to debug SCPI over RS-232 is to use a terminal program with your existing serial interface. Just type the command and see what comes back. The terminal allows you to fairly easily fiddlle with baud rate, handshaking, echo and termination characters without relying on some unknown serial communication library in between (what you type is what you send, what is received is what is shown).

*IDN? doesn't need any special trigger or prompt for response. If the command is supported (according to the manual, it is), if the termination character is correct (which it appears to be, since your previous Python work had some success) and if the handshaking is correct, the instrument should respond immediately with the identification string.

Once you figure out exactly what the instrument expects and returns, you can then craft your Python script with ease.