Page 1 of 1

Result data type in async callback

Posted: Sat Sep 18, 2021 1:26 pm
by jnbastoky
The details parameter in the AsyncHandler callback for Phidget22.Devices.VoltageOutput.setVoltage_async() and Phidget22.Devices.DigitalOutput.setState_async() is returned as Python type bytes instead of type string.

Printing the value returned by the AysncHandler result value gives a byte string:

Code: Select all

b'Success'
Example:

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.DigitalOutput import *
from Phidget22.ErrorCode import *
from Phidget22.Net import *
import time

Net.addServer('phidget',
			  'phidget.localdomain',
			  5661,
			  '',
			  0)

ch = DigitalOutput()
ch.setDeviceSerialNumber(123456)
ch.setHubPort(0)
ch.setIsRemote(True)
ch.setIsHubPortDevice(False)
ch.setChannel(0)
ch.openWaitForAttachment(1000)

def AsyncResult(ch, res, details):
	# if res != ErrorCode.EPHIDGET_OK:
	print("Async results: %i : %s" % (res, details))


ch.setState_async(False, AsyncResult)
# NOTE: Make sure to wait for async call to complete before closing the channel
time.sleep(1)

ch.close()