def verify_initial_conn_state(inv, state, time_period=0, threshold=50, das=None): result = None start_time = time.time() while result is None: elapsed_time = time.time()-start_time if elapsed_time <= time_period: if not inverter.verify_conn_state(inv, state, threshold, das): ts.sleep(0.89) #Attempt to make loop exactly 1 second else: result = True else: result = False return result
def verify_initial_conn_state(inv, state, time_period=0, threshold=50, data=None): result = None start_time = time.time() while result is None: elapsed_time = time.time()-start_time if elapsed_time <= time_period: if not inverter.verify_conn_state(inv, state, threshold, data): ts.sleep(0.89) #Attempt to make loop exactly 1 second else: result = True else: result = False return result
def verify_conn_state_change(inv, state, time_window=0, timeout_period=0, verification_delay=5, threshold=50, data=None): result = None start_time = time.time() elapsed_time = 0 # Time window takes precedence over timeout period: time_window is passed first when time_window and timeout_period # are used at the same time. if time_window != 0: time_period = time_window + verification_delay # Note: the actual amount of time allowed for the change is time_period, not time_window ts.log('Randomization window in use. Waiting up to %d seconds for %s state' % (time_window, inverter.conn_state_str(state))) elif timeout_period != 0: time_period = timeout_period + verification_delay # Note: the actual amount of time allowed for the change is time_period, not timeout_period ts.log('Time period in use. Waiting up to %d seconds for EUT to revert to %s. ' 'Verification time is %d seconds.' % (timeout_period, inverter.conn_state_str(state), verification_delay)) else: time_period = verification_delay ts.log('Waiting for verification delay of up to %d seconds' % verification_delay) while result is None: if elapsed_time <= time_period: power = inverter.get_power(inv, data) ts.log('Elapsed time is %0.3f seconds, EUT power is %0.3f W' % (elapsed_time, power)) if not inverter.verify_conn_state(inv, state, threshold, data): ts.sleep(0.89) # Attempt to make loop exactly 1 second elapsed_time = time.time()-start_time else: ts.log('State changed to %s after %0.3f seconds' % (inverter.conn_state_str(state), elapsed_time)) result = True else: ts.log('Connection state did not change within required time') result = False log_conn_state(inv, data) return result
def test_run(): result = script.RESULT_FAIL data = None trigger = None inv = None pv = None disable = None try: # EUT communication parameters ifc_type = ts.param_value('comm.ifc_type') ifc_name = ts.param_value('comm.ifc_name') if ifc_type == client.MAPPED: ifc_name = ts.param_value('comm.map_name') baudrate = ts.param_value('comm.baudrate') parity = ts.param_value('comm.parity') ipaddr = ts.param_value('comm.ipaddr') ipport = ts.param_value('comm.ipport') slave_id = ts.param_value('comm.slave_id') # INV1 parameters operation = ts.param_value('inv1.operation') time_window = ts.param_value('inv1.time_window') timeout_period = ts.param_value('inv1.timeout_period') # Script timing and pass/fail criteria pretest_delay = ts.param_value('invt.pretest_delay') verification_delay = ts.param_value('invt.verification_delay') posttest_delay = ts.param_value('invt.posttest_delay') power_threshold = ts.param_value('invt.power_threshold') disable = ts.param_value('invt.disable') # initialize data acquisition system daq = das.das_init(ts) data = daq.data_init() trigger = daq.trigger_init() # initialize pv simulation pv = pvsim.pvsim_init(ts) pv.power_on() # It is assumed that the PV and Grid Simulators (if used) are connected to the EUT and operating properly # prior to running this test script. if pretest_delay > 0: ts.log('Waiting for pre-test delay of %d seconds' % pretest_delay) ts.sleep(pretest_delay) # Sandia Test Protocol: Communication is established between the Utility Management System Simulator and EUT ts.log('Scanning EUT') try: inv = client.SunSpecClientDevice(ifc_type, slave_id=slave_id, name=ifc_name, baudrate=baudrate, parity=parity, ipaddr=ipaddr, ipport=ipport) except Exception, e: raise script.ScriptFail('Error: %s' % e) # Define operation states (connected/disconnected) # Default state is required for timeout_periods because the EUT will return to that mode of operation default_state = inverter.CONN_CONNECT if operation == 'Connect': orig_state = inverter.CONN_DISCONNECT state = inverter.CONN_CONNECT elif operation == 'Disconnect': orig_state = inverter.CONN_CONNECT state = inverter.CONN_DISCONNECT else: ts.log('Unknown operation requested: %s' % operation) raise script.ScriptFail() # Sandia Test Protocol Step 1: Request Status of EUT. # Sandia Test Protocol Step 2: UMS receives response to the DS93 command. # Verify EUT is in correct state before running the test. if inverter.verify_conn_state(inv, orig_state, threshold=power_threshold, das=data) is False: # todo: update inverter module with das changed to data ts.log('Inverter not in correct state, setting state to: %s' % (inverter.conn_state_str(orig_state))) # EUT put into state where INV1 can be verified inverter.set_conn_state(inv, orig_state) if verify_conn_state_change(inv, orig_state, verification_delay=verification_delay, threshold=power_threshold, data=data) is False: raise script.ScriptFail() # Sandia Test Protocol Step 3: Inverter output is measured and logged. log_conn_state(inv, data=data) # Sandia Test Protocol Step 4: UMS issues the INV1 command. ts.log('Executing %s' % operation) inverter.set_conn_state(inv, state, time_window=time_window, timeout_period=timeout_period, trigger=trigger) # Sandia Test Protocol Step 5: Verify the INV1 command was successfully executed. if verify_conn_state_change(inv, state, time_window=time_window, verification_delay=verification_delay, threshold=power_threshold, data=data) is False: raise script.ScriptFail() # Verify revert (timeout) to default state if timeout period specified if timeout_period > 0: if verify_conn_state_change(inv, default_state, timeout_period=timeout_period, verification_delay=verification_delay, threshold=power_threshold, data=data) is False: raise script.ScriptFail() if posttest_delay > 0: ts.log('Waiting for post-test delay of %d seconds' % posttest_delay) ts.sleep(posttest_delay) result = script.RESULT_PASS