except UafError, e:
    print("Some error occurred: %s" %e)
    
    

print("")
print("Third option: use the convenience function beginRead() to read data asynchronously")
print("==================================================================================")

# notice we enable asynchronous communication now by providing the printResult() method as 
# a callback function!

try:
    asyncReadResult = myClient.beginRead(addresses     = [someDoubleNode, someUInt32Node, 
                                                          someStringNode, someLocalizedTextNode, 
                                                          someSByteArrayNode],
                                         serviceConfig = serviceConfig, # optional argument
                                         sessionConfig = sessionConfig, # optional argument
                                         callback      = printResult) # callback function!
    
    # check if there was an "immediate" error on the client side when executing the asynchronous 
    # service call:
    if asyncReadResult.overallStatus.isGood():
        print("OK, the client could invoke the asynchronous request without problems.")
        print("Let's wait a second for the result ...")
        
        time.sleep(1)
        
        print("The read result should have been received by now!")

except UafError, e:
    print("Some error occurred: %s" %e)
time.sleep(1) # wait one second for the async call result to arrive (and the callback function to be called)



# =====================================================================================================================
print("")
print("Asynchronous reading")
print("====================")
print("")

def printMyAsyncReadResult(asyncResult):
    print(" --> received async read result:")
    print("     - temperature setpoint : %.3f" %asyncResult.targets[0].data.value)
    print("     - heater setpoint      : %d"   %asyncResult.targets[1].data.value)

immediateResult = myClient.beginRead( addresses = [address_TSetpoint, address_HeaterStatus],
                                      callback  = printMyAsyncReadResult ) 

time.sleep(1) # wait one second for the async call result to arrive (and the callback function to be called)



# =====================================================================================================================
print("")
print("Asynchronous writing")
print("====================")
print("")

def printMyAsyncWriteResult(asyncResult):
    print(" --> received async write result:")
    print("      - write status : %s" %asyncResult.targets[0].status)
print("")
print("Asynchronous reading")
print("====================")
print("")


def printMyAsyncReadResult(asyncResult):
    print(" --> received async read result:")
    print("     - temperature setpoint : %.3f" %
          asyncResult.targets[0].data.value)
    print("     - heater setpoint      : %d" %
          asyncResult.targets[1].data.value)


immediateResult = myClient.beginRead(
    addresses=[address_TSetpoint, address_HeaterStatus],
    callback=printMyAsyncReadResult)

time.sleep(
    1
)  # wait one second for the async call result to arrive (and the callback function to be called)

# =====================================================================================================================
print("")
print("Asynchronous writing")
print("====================")
print("")


def printMyAsyncWriteResult(asyncResult):
    print(" --> received async write result:")
except UafError, e:
    print("Some error occurred: %s" %e)
    
    

print("")
print("Third option: use the convenience function beginRead() to read data asynchronously")
print("==================================================================================")

# notice we enable asynchronous communication now by providing the printResult() method as 
# a callback function!

try:
    asyncReadResult = myClient.beginRead(addresses       = [someDoubleNode, someUInt32Node, 
                                                            someStringNode, someLocalizedTextNode, 
                                                            someSByteArrayNode],
                                         serviceSettings = serviceSettings, # optional argument
                                         sessionSettings = sessionSettings, # optional argument
                                         callback        = printResult)     # callback function!
    
    # check if there was an "immediate" error on the client side when executing the asynchronous 
    # service call:
    if asyncReadResult.overallStatus.isGood():
        print("OK, the client could invoke the asynchronous request without problems.")
        print("Let's wait a second for the result ...")
        
        time.sleep(1)
        
        print("The read result should have been received by now!")

except UafError, e:
    print("Some error occurred: %s" %e)