Python

This is a program example in Python 3. Converted data and error details are displayed in the output window.
Program example using AioSingleAo


Program example using AioSingleAo

#---------------------------
# Variable declaration
#---------------------------

Ret = ctypes.c_long()  #Return value of the function
Id = ctypes.c_short()  #ID
ErrorString = ctypes.create_string_buffer(256)  #Array for storing error strings

#---------------------------
# Device initialization
# Device name: Aio000
#---------------------------

Ret.value = caio.AioInit ( b"AIO000" , ctypes.byref(Id) )
if Ret.value != 0:
    caio.AioGetErrorString( Ret, ErrorString )
    print( f"AioInit : {ErrorString.value.decode('sjis')}" )
    sys.exit( )

#---------------------------
# Setting the analog output range
# Range: -10V to +10V
#---------------------------

Ret.value = caio.AioSetAoRangeAll( Id , caio.PM10 )
if Ret.value != 0:
    AioGetErrorString( Ret , ErrorString )
    print( f"AioSetAoRangeAll : {ErrorString.value.decode('sjis')}" )
    Ret.value = caio.AioExit( Id )
    sys.exit( )

#---------------------------
# 1 time analog output for the specified channel
# Output channel: 0

# Output data: 800H
#---------------------------

Ret.value = caio.AioSingleAo( Id , 0 , 0x800 )
if Ret.value != 0:
    AioGetErrorString( Ret , ErrorString )
    print( f"AioSingleAo : {ErrorString.value.decode('sjis')}" )
    Ret.value = caio.AioExit( Id )
    sys.exit( )

print( f"Channel0 : 0x800" )

#---------------------------
# Device termination
#---------------------------

Ret.value = caio.AioExit ( Id )
if Ret.value != 0:
    AioGetErrorString( Ret , ErrorString )
    print( f"AioExit : {ErrorString.value.decode('sjis')}" )
    Ret.value = caio.AioExit( Id )
    sys.exit( )