xref: /aosp_15_r20/external/autotest/client/cros/cellular/scpi_shell (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
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 logging
9import sys
10
11from autotest_lib.client.cros.cellular import cellular_system_error
12from autotest_lib.client.cros.cellular import prologix_scpi_driver
13from autotest_lib.client.cros.cellular import scpi
14
15
16try:
17    [target] = sys.argv[1:]
18except ValueError:
19    print 'usage: %s gpib_host_name' % sys.argv[0]
20    # Default to the PXT.
21    target = '172.22.50.244'
22
23logging.basicConfig(level=logging.INFO)
24
25driver = prologix_scpi_driver.PrologixScpiDriver(hostname=target,
26                                                 port=1234,
27                                                 read_timeout_seconds=1)
28s = scpi.Scpi(driver)
29s.opc_on_stanza = False
30
31while True:
32    try:
33        line = raw_input('scpi> ').rstrip()
34    except EOFError:
35        print
36        exit(0)
37
38    try:
39        if line[-1:] == '?':
40            try:
41                s.Query(line)
42            #  Catch everything, we always want to try to recover.
43            except Exception:
44                print "**************"
45                print "Query did not result in any data before the timeout"
46                print "**************"
47        else:
48            try:
49                s.SendStanza([line])
50            #  Catch everything, we always want to try to recover.
51            except Exception as e:
52                print "**************"
53                print "Command failed"
54                print "**************"
55
56    except cellular_system_error:
57        continue
58