-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogAllTcpSocketScpi.py
More file actions
78 lines (59 loc) · 2.47 KB
/
LogAllTcpSocketScpi.py
File metadata and controls
78 lines (59 loc) · 2.47 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Goal:
# Connect to a SpikeSafe and read all events
import sys
import logging
import spikesafe_python
### set these before starting application
# SpikeSafe IP address and port number
ip_address: str = '10.0.0.220'
port_number: int = 8282
### setting up sequence log
log = logging.getLogger(__name__)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s.%(msecs)03d, %(levelname)s, %(message)s',
datefmt='%m/%d/%Y %I:%M:%S',
handlers=[
logging.FileHandler("SpikeSafePythonSamples.log"),
logging.StreamHandler(sys.stdout)
]
)
### start of main program
try:
log.info("LogAllTcpSocketScpi.py started.")
log.info("Python version: {}".format(sys.version))
# instantiate new TcpSocket to connect to SpikeSafe
tcp_socket = spikesafe_python.TcpSocket(enable_logging=False)
# set TcpSocket to log all SCPI
tcp_socket.enable_logging = True
# set TcpSocket to log all SCPI as info level messages
tcp_socket.default_log_level = 20
# connect to SpikeSafe
tcp_socket.open_socket(ip_address, port_number)
# reset to default state and check for all events,
# it is best practice to check for errors after sending each command
tcp_socket.send_scpi_command('*RST')
# parse the SpikeSafe information
spikesafe_info = spikesafe_python.SpikeSafeInfoParser.parse_spikesafe_info(tcp_socket)
# request SpikeSafe memory table
tcp_socket.send_scpi_command('MEM:TABL:READ')
# read SpikeSafe memory table and print SpikeSafe response to the log file
data = tcp_socket.read_data()
# read all events in SpikeSafe event queue, store in list, and print them to the log file
# here it's expected to receive 1 event: 102, External Pause Signal Ended
event_data = spikesafe_python.ReadAllEvents.read_all_events(tcp_socket)
# disconnect from SpikeSafe
tcp_socket.close_socket()
log.info("LogAllTcpSocketScpi.py completed.\n")
except spikesafe_python.SpikeSafeError as ssErr:
# print any SpikeSafe-specific error to both the terminal and the log file, then exit the application
error_message = 'SpikeSafe error: {}\n'.format(ssErr)
log.error(error_message)
print(error_message)
sys.exit(1)
except Exception as err:
# print any general exception to both the terminal and the log file, then exit the application
error_message = 'Program error: {}\n'.format(err)
log.error(error_message)
print(error_message)
sys.exit(1)