-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_iocs.py
38 lines (27 loc) · 877 Bytes
/
update_iocs.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
import logging
import random
import time
import numpy as np
from epics import PV
from p4p.client.thread import Context
logging.basicConfig(level=logging.WARNING)
temp_pv = PV('K2EG:TEST:TEMPERATURE')
ctxt = Context('pva')
table_pv = ctxt.get('K2EG:TEST:TWISS')
def update_iocs():
global temp_pv, table_pv, image_pv, ctxt
# Update temperature
temp_pv.value = random.uniform(89, 91)
# Update timestamp of table, any monitor will get a new result
ctxt.put('K2EG:TEST:TWISS', table_pv)
image_size = int(ctxt.get('K2EG:TEST:IMAGESIZE'))
# Update image
matrix = np.random.randint(0, 100, (image_size, image_size))
ctxt.put('K2EG:TEST:IMAGE', matrix)
def main():
while True:
start_time = time.time()
update_iocs()
time.sleep(max(0, 0.1 - (time.time() - start_time)))
if __name__ == "__main__":
main()