#!/usr/bin/python

import time
import sys
import subprocess


def test_async():
    """"
    Simulate permit signal and ON signal from PLC.
    Confirm pulse generation with async mode. 10ms
    """
    print '1.set beam-on schedule (10ms diff + 3s pulse.)'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 10000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 20000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 30000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 40000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 50000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 1000000', shell=True)
    # 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 10000000', shell = True)
    time.sleep(1)
    print '3. Write PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(1)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print "end of async, non-prepro mode test!"

def test_async_limit():
    """"
    Mode Limit Stop test.
    Pulse lenght was set to 3s, but it stop in 1s because of mode limit.
    """
    print '1.set beam-on schedule'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 1000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 11000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 21000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 31000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 41000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 3000000', shell=True)
    # 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-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(6)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print "end of async, non-prepro mode test!"

def test_async_prepro():
    """PrePro mode test"""
    print '1.set beam-on schedule'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 100000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 200000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 300000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 400000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 500000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 3000000', shell=True)
    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 10000000', shell = True)
    time.sleep(1)
    print '1.Set Pre-Pro flag'
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-PREP-MODE 1', shell = True)
    time.sleep(1)
    print '2.Reset Mode 1 flag'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1.SVAL 0', shell = True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1 0', shell = True)
    print '3.Write PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 1', shell=True)
    time.sleep(2)
    print '4.Write HVON'
    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)
    time.sleep(4)
    print '5.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(3)
    print '6.Reset Pre-Pro flag'
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-PREP-MODE 0', shell = True)
    time.sleep(1)
    print '7. Reset PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print 'end of async, prepro mode testscript!'

def test_async_shortpulse():
    """Short Pulse Mode test"""
    #print '1.Set puls length to 1ms (1ms diff)'
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-SHORT-PULSE 1', shell=True) #Set short pulse mode.
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1 1', shell = True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 1000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 2000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 3000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 4000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 5000', shell=True) #Should be grater than 1ms.
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 1000', shell=True)
    print '1.Set puls length to 100us (100us diff)'
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-SHORT-PULSE 1', shell=True) #Set short pulse mode.
    #res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1 1', shell = True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 100', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 200', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 300', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 400', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 800', shell=True) #Should be grater than 1ms.
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 100', shell=True)
    print '1.Set puls length (100us diff)'
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-SHORT-PULSE 1', shell=True) #Set short pulse mode.
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-MD1 1', shell = True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 100', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 200', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 300', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 400', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 800', shell=True) #Should be grater than 1ms.
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 500', shell=True)
    print '2.Write PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 1', shell=True)
    time.sleep(1)
    print '3.Write HVON'
    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(1)
    print '4.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 '5.Reset PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print '6.Reset short pulse mode'
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-SHORT-PULSE 0', shell=True) #Set short pulse mode.
    print "-----------------------------------------\n"

def test_async_longpulse():
    """"
    Simulate permit signal and ON signal from PLC.
    Confirm pulse generation with async mode. 10ms
    """
    print '1.set beam-on schedule (10ms diff + 50ms pulse.)'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 10000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 20000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 30000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 40000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 50000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 3600000000', shell=True)
    # 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 180000000', shell = True)
    time.sleep(1)
    print '3. Write PERMIT'
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(185)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print "end of async, non-prepro mode test!"

def test_async_both():
    """"
    Simultanious operation test.
    """
    print '1.set beam-on schedule (10ms diff + 500ms pulse.)'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 10000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 20000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 30000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 40000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 50000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 500000', shell=True)

    res = subprocess.call('caput EC-GN-P01-PA2F:STAT-DT-HVON 10000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB2F:STAT-DT-HVON 20000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB2F:STAT-DT-SWON 40000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA2F:STAT-DT-SWON 50000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF:STAT-DT-SHOTLEN 500000', shell=True)
    # 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-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(1)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    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!"

def test_async_GYA():
    """"
    Test GYA operation with Async mode.
    """
    #print '1.set beam-on schedule (1s diff + 1s pulse.)'
    #print '1.set beam-on schedule (100ms diff + 1s pulse.)'
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 100000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 200000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 300000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 400000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 500000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 1000000', shell=True)
    #print '1.set beam-on schedule (10ms diff + 100ms pulse.)'
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 10000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 20000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 30000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 40000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 50000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 100000', shell=True)
    #print '1.set beam-on schedule (1ms diff + 10ms pulse.)'
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 1000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 2000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 3000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 4000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 5000', shell=True)
    #res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 10000', shell=True)
    print '1.set beam-on schedule (1s diff + 20s pulse.)'
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-HVON 1000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-HVON 2000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 3000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB1F:STAT-DT-SWON 4000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA1F:STAT-DT-SWON 5000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GAF:STAT-DT-SHOTLEN 20000000', shell=True)
    # 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-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(30)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print "end of async, non-prepro mode test!"

def test_async_GYB():
    """"
    Test GYB operation with Async mode.
    """
    print '1.set beam-on schedule (1s diff + 1s pulse.)'
    res = subprocess.call('caput EC-GN-P01-PA2F:STAT-DT-HVON 1000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB2F:STAT-DT-HVON 2000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PMF:STAT-DT-HVON 3000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PB2F:STAT-DT-SWON 4000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-PA2F:STAT-DT-SWON 5000000', shell=True)
    res = subprocess.call('caput EC-GN-P01-GBF:STAT-DT-SHOTLEN 20000000', shell=True)
    # 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.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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(30)
    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!"
def test_async_GYA_manual():
    """"
    Test GYA operation with Async mode.
    """
    print '1.. Set delays and pulse length on HMI and set sleep time here:'
    inp_val = raw_input()
    try:
        sleep_time = float(inp_val)
    except:
        return
    # 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-GY1PRM.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(sleep_time)
    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-GY1PRM.SVAL 0', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-CON-GY1PRM 0', shell=True)
    print "end of async, non-prepro mode test!"

def test_async_GYB_manual():
    """"
    Test GYA operation with Async mode.
    """
    print '1.. Set delays and pulse length on HMI and set sleep time here:'
    inp_val = raw_input()
    try:
        sleep_time = float(inp_val)
    except:
        return
    # 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.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.SVAL 1', shell=True)
    res = subprocess.call('caput EC-GN-P01-GPS:PLC4110-YTS-ST3R 1', shell=True)       #HVON signal from PLC
    time.sleep(sleep_time)
    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!"
