def main(): """Do the test""" global t if len(argv) != 5: print("Syntax: ihctest ihcurl username password resourceid") exit() url = argv[1] resid = int(argv[4]) ihc = IHCController(url, argv[2], argv[3]) # Un-comment the line below to use pycurl connection # ihc.client.connection = IHCCurlConnection( url) if not ihc.authenticate(): print("Authenticate failed") exit() print("Authenticate succeeded\r\n") # read project project = ihc.get_project() if project is False: print("Failed to read project") else: print("Project downloaded successfully") log = ihc.client.get_user_log() if log: print("log: " + log) runtimevalue = ihc.get_runtime_value(resid) print("Runtime value: " + str(runtimevalue)) ihc.set_runtime_value_bool(resid, not runtimevalue) runtimevalue = ihc.get_runtime_value(resid) print("Runtime value: " + str(runtimevalue)) # ihc.client.enable_runtime_notifications( resid) # changes = ihc.client.wait_for_resource_value_changes( 10) # print( repr( changes)) ihc.add_notify_event(resid, on_ihc_change, True) while True: i = input() if i == "1": t = datetime.now() ihc.set_runtime_value_bool(resid, False) continue if i == "2": t = datetime.now() ihc.set_runtime_value_bool(resid, True) continue if i == "q": break ihc.disconnect()
def main(): """Do the test""" starttime = datetime.now() def on_ihc_change(ihcid, value): """Callback when ihc resource changes""" print("Resource change " + str(ihcid) + "->" + str(value) + " time: " + gettime()) def gettime(): dif = datetime.now() - starttime return str(dif) cmdline = open(".parameters", "rt").read() args = cmdline.split(" ") if len(args) != 4: print( "The '.parameters' file should contain: ihcurl username password resourceid" ) exit() url = args[0] username = args[1] password = args[2] resid = int(args[3]) if not IHCController.is_ihc_controller(url): print("The device in this url does not look like a IHC controller") exit() print("Url response like a IHC controller - now authenticating") ihc = IHCController(url, username, password) if not ihc.authenticate(): print("Authenticate failed") exit() print("Authenticate succeeded\r\n") # read the ihc project project = ihc.get_project() if project is False: print("Failed to read project") else: print("Project downloaded successfully") log = ihc.client.get_user_log() if log: print("log: " + log) info = ihc.client.get_system_info() print(info) runtimevalue = ihc.get_runtime_value(resid) print("Runtime value: " + str(runtimevalue)) ihc.set_runtime_value_bool(resid, not runtimevalue) runtimevalue = ihc.get_runtime_value(resid) print("Runtime value: " + str(runtimevalue)) ihc.client.enable_runtime_notification(resid) changes = ihc.client.wait_for_resource_value_changes(10) print(repr(changes)) ihc.add_notify_event(resid, on_ihc_change, True) while True: i = input() if i == "1": starttime = datetime.now() ihc.set_runtime_value_bool(resid, False) continue if i == "2": starttime = datetime.now() ihc.set_runtime_value_bool(resid, True) continue if i == "q": break ihc.disconnect() ihc.client.connection.session.close()