Python

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


Program example using AioSingleAi

#---------------------------
# 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
AiData = ctypes.c_long()  #Converted data

#---------------------------
# 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 input method
# Input method: Single-end input
#---------------------------

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

#---------------------------
# Setting the analog input range
# Range: -10V to +10V
#---------------------------
Ret.value = caio.AioSetAiRangeAll( Id , caio.PM10 )
if Ret.value != 0:
    AioGetErrorString( Ret , ErrorString )
    print( f"AioSetAiRangeAll : {ErrorString.value.decode('sjis')}" )
    Ret.value = caio.AioExit( Id )
    sys.exit( )

#---------------------------
# 1 time analog input for the specified channel
# channel: 0
#---------------------------
Ret.value = caio.AioSingleAi( Id , 0 , ctypes.byref(AiData) )
if Ret.value != 0:
    AioGetErrorString( Ret , ErrorString )
    print( f"AioSingleAi : {ErrorString.value.decode('sjis')}" )
    Ret.value = caio.AioExit( Id )
    sys.exit( )

print( f"Channel0 : {AiData.value}\n" )

#---------------------------
# 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( )