#!/usr/bin/python

import time
import sys
import subprocess

import test_async
import test_sync
import test_ready_hw
import test_setup_hw
import test_standby_hw
import test_ready
import test_setup
import test_standby


""""
Test GYB operation with Async mode.
This code can be executed when WaitPermit state.
"""
# turn on permit
print '2.. set PulseLengthLimitMode to 1 flag'
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1.SVAL 1', shell = True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1 1', shell = True)
res = subprocess.call('caput EC-GN-P01-GPF:STAT-MD1-LIM 1000000', shell = True)
time.sleep(1)
print '3. Write PERMIT'
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM.SCAN Passive', shell=True)
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM.SIML ', shell=True)
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM.SIMM 1', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM.SVAL 1', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM 1', shell=True)
time.sleep(1)
# trun on HVON trigger
print '4. Write HVON'
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R.SCAN Passive', shell=True)
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R.SIML ', shell=True)
#res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R.SIMM 1', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R.SVAL 1', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
time.sleep(11)
print '5. Confirm generated pulse'
print '6. Reset HVON'
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R.SVAL 0', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 0', shell=True)
time.sleep(1)
print '7. Reset PERMIT'
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM.SVAL 0', shell=True)
res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY2PRM 0', shell=True)
print "end of async, non-prepro mode test!"

