• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Interact with a SCPI device, checking for errors each time."""
7
8import cellular_system_error
9import logging
10import prologix_scpi_driver
11import scpi
12import sys
13
14try:
15    [target] = sys.argv[1:]
16except ValueError:
17    print 'usage: %s gpib_host_name' % sys.argv[0]
18    # Default to the PXT.
19    target = '172.22.50.244'
20
21logging.basicConfig(level=logging.INFO)
22
23driver = prologix_scpi_driver.PrologixScpiDriver(hostname=target,
24                                                 port=1234,
25                                                 read_timeout_seconds=1)
26s = scpi.Scpi(driver)
27s.opc_on_stanza = False
28
29while True:
30    try:
31        line = raw_input('scpi> ').rstrip()
32    except EOFError:
33        print
34        exit(0)
35
36    try:
37        if line[-1:] == '?':
38            try:
39                s.Query(line)
40            #  Catch everything, we always want to try to recover.
41            except Exception:
42                print "**************"
43                print "Query did not result in any data before the timeout"
44                print "**************"
45        else:
46            try:
47                s.SendStanza([line])
48            #  Catch everything, we always want to try to recover.
49            except Exception as e:
50                print "**************"
51                print "Command failed"
52                print "**************"
53
54    except cellular_system_error:
55        continue
56