This sample reads data from analog input channel 0.
import pyAPIUSBP
import time
import sys
# Initialize
try:
    aio = pyAPIUSBP.AIO.AIO('AIO000')
except:
    print 'AIO000 is not found.'
    sys.exit()
# Set AI range
aio.setAiRangeAll(pyAPIUSBP.AIO.PM5)
if sys.platform == 'win32':
    timefunc = time.clock
else:
    timefunc = time.time
startTime = timefunc()
# Read channel 0 for 10 seconds
while timefunc()-startTime<10:
    print aio.singleAi(0)
    time.sleep(0.5)
This sample outputs 1-byte data to digital output channel 0.
import pyAPIUSBP
import time
import sys
# Initialize
try:
    dio = pyAPIUSBP.DIO.DIO('DIO000')
except:
    print 'DIO000 is not found.'
    sys.exit()
if sys.platform == 'win32':
    timefunc = time.clock
else:
    timefunc = time.time
startTime = timefunc()
# Output 255 and 0 alternately for 10 seconds.
while timefunc()-startTime<10:
    dio.outputByte(0,0)
    print 0
    time.sleep(1)
    dio.outputByte(0,255)
    print 255
    time.sleep(1)
This is an example of callback function.
import pyAPIUSBP
import Tkinter
import time
import ctypes
from ctypes.wintypes import WPARAM, LPARAM
# Initialize
aio = pyAPIUSBP.AIO('AIO000')
# Define callback function
def showMessageId(id, message, wparam, lparam, param):
    if message==pyAPIUSBP.AIOM_AIE_END:
        print 'AIOM_AIE_END:', lparam
    elif message==pyAPIUSBP.AIOM_AIE_DATA_NUM:
        print 'AIOM_AIE_DATA_NUM:', lparam
    else:
        print message, lparam
    return 0
# Get prototype of callback function
callbackPrototype = ctypes.WINFUNCTYPE(ctypes.c_long,
                          ctypes.c_short,
                          ctypes.c_short,
                          ctypes.c_int,
                          ctypes.c_int,
                          ctypes.c_void_p)
# Get a pointer to the callback function
callback = callbackPrototype(showMessageId)
# Register callback function
aio.setAiCallBackProc(callback,
                      pyAPIUSBP.AIE_END|pyAPIUSBP.AIE_DATA_NUM, 0)
aio.setAiStopTimes(4000)
# Start analog input
aio.startAi()
time.sleep(5)
data = aio.getAiSamplingData(100)
print data