43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from datetime import datetime
|
|
import time
|
|
import PyCafe
|
|
cafe = PyCafe.CyCafe()
|
|
pd=cafe.getPV("BMA1:STA:2")
|
|
tz = pd.tsDate
|
|
time0 = datetime(tz[0], tz[1], tz[2], tz[3], tz[4], tz[5])
|
|
tn = datetime.now()
|
|
|
|
time1 = datetime(tn.year, tn.month, tn.day, tn.hour, tn.minute, tn.second)
|
|
|
|
difference = time1 - time0
|
|
|
|
minutes = divmod(difference.total_seconds(), 60)
|
|
print('Total difference in minutes: ', int(minutes[0]), 'minutes', int(minutes[1]), 'seconds')
|
|
|
|
|
|
def time_difference():
|
|
tn = datetime.now()
|
|
time1 = datetime(tn.year, tn.month, tn.day, tn.hour, tn.minute, tn.second)
|
|
difference = time1 - time0
|
|
return divmod(difference.total_seconds(), 60)
|
|
|
|
|
|
|
|
def cb(handle, pv, pvdata):
|
|
global time0
|
|
print(pv, handle)
|
|
pvdata.show()
|
|
tz = pvdata.tsDate
|
|
time0 = datetime(tz[0], tz[1], tz[2], tz[3], tz[4], tz[5])
|
|
print("time0 in callback", time0)
|
|
|
|
cafe.openMonitorPrepare()
|
|
cafe.monitorStart("BMA1:STA:2", cb=cb)
|
|
cafe.openMonitorNowAndWait(1.0)
|
|
|
|
for i in range(0, 360):
|
|
time.sleep(1)
|
|
minutes = time_difference()
|
|
print('Total difference in minutes: ', int(minutes[0]), 'minutes', int(minutes[1]), 'seconds')
|
|
print("time0 actual", time0)
|