-
Notifications
You must be signed in to change notification settings - Fork 0
/
readout.py
58 lines (47 loc) · 1.48 KB
/
readout.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
49
50
51
52
53
54
55
56
57
58
import zmq
import time
import multiprocessing
import larpix
from larpix.format import pacman_msg_format
cmd = 'tcp://127.0.0.1:5555'
data = 'tcp://127.0.0.1:5556'
N_READOUTS = 1 #number of readouts
datafile = "readout-test.h5"
def readout():
try:
commander = zmq.Context().socket(zmq.REQ)
commander.connect(cmd)
# Using SUB socket to collect data
reader = zmq.Context().socket(zmq.SUB)
reader.connect(data)
reader.setsockopt(zmq.SUBSCRIBE, b"")
print("Press ENTER to start listening...")
input()
commander.send(b'')
print("Signal sent to PACMAN card.")
commander.recv()
messages = 0
while True:
message = reader.recv()
print("Message received:", message)
messages += 1
print("Total messages received:", messages)
print("Converting to a packet...")
packet = pacman_msg_format.parse(message)
print("Writing to HDF5 file:", datafile)
larpix.format.hdf5format.to_file(datafile,packet)
print("Message written to file.")
except:
raise
finally:
reader.close()
def main():
# Start tasks
def start(task, *args):
process = multiprocessing.Process(target=task, args=args)
process.daemon = True
process.start()
for i in range(N_READOUTS):
start(readout(), i)
if __name__ == "__main__":
main()