-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathshell.py
49 lines (41 loc) · 1.28 KB
/
shell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
#
# eevidtron example code (youtube.com/eevidtron)
# written by Clifford Wolf (www.clifford.at)
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
# boilerplate code
from __future__ import division
from __future__ import print_function
# used standard libraries
import readline
import sys
# import device drivers
from vxi11Device import Vxi11Device
from usbtmcDevice import UsbtmcDevice
# check arguments
if len(sys.argv) != 3 or (sys.argv[1] != 'vxi11' and sys.argv[1] != 'usbtmc'):
print('Usage: %s {vxi11|usbtmc} <device-or-ip>', file=sys.stderr)
exit(1)
# open VXI-11 connection, if requested by user
if sys.argv[1] == 'vxi11':
dev = Vxi11Device(sys.argv[2], 'inst0')
# open USBTMC connection, if requested by user
if sys.argv[1] == 'usbtmc':
dev = UsbtmcDevice(sys.argv[2])
# read and execute commands
try:
while True:
cmd = raw_input('scpi> ')
if cmd.find('?') >= 0:
answer = dev.ask(cmd).strip()
print(answer)
else:
dev.write(cmd)
except EOFError:
pass