1. read isolated digital inputs and ttl inputs
# read bit 0 isolated input
ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_ID,0)
if ok==0:
print 'isolated input 0 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read bit 8 isolated input
ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_ID+1,0)
if ok==0:
print 'isolated input 8 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read bit 0 ttl input
ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_TTL,0)
if ok==0:
print 'ttl input 0 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read bit 8 ttl input
ok,txt,err_or_val = io.di_readbit( advantechapi.PORT_TTL+1,0)
if ok==0:
print 'ttl input 8 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read byte 0 isolated output
ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_ID)
if ok==0:
print 'isolated input byte 0 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read byte 1 isolated output
ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_ID+1)
if ok==0:
print 'isolated input byte 1 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read byte 0 ttl output
ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_TTL)
if ok==0:
print 'ttl input byte 0 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
# read byte 1 ttl output
ok,txt,err_or_val = io.di_readbyte( advantechapi.PORT_TTL+1)
if ok==0:
print 'isolated input byte 1 is %d' % err_or_val
else:
print "error %s, subcode %d when reading", % (io.OPCODES[ok],err_or_val)
2.write isolated outputs and ttl outputs
# write bit 0 isolated output
ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_ID,0,1)
if ok==0:
print 'isolated output 0 is %d' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write bit 8 isolated output
ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_ID+1,0,1)
if ok==0:
print 'isolated output 8 is %d' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write bit 0 ttl output
ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_TTL,0,1)
if ok==0:
print 'ttl output 0 is %d' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write bit 8 ttl output
ok,txt,err_or_val = io.do_writebit( advantechapi.PORT_TTL+1,0,1)
if ok==0:
print 'ttl output 8 is %d' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write byte 0 isolated output
ok,txt,err_or_val = io.do_writebyte( advantechapi.PORT_ID,0xff,1)
if ok==0:
print 'isolated output byte (bits 0..7) is %d (00000001)' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write byte 1 isolated output
ok,txt,err_or_val = io.do_writebyte( advantechapi.PORT_ID+1,0xff,1)
if ok==0:
print 'isolated output byte (bits 8..15) is %d (00000001)' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write byte 0 ttl output
ok,txt,err_or_val = io.do_writebyte( advantechapi.PORT_TTL,0xff,1)
if ok==0:
print 'ttl output byte (bits 0..7) is %d (00000001)' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
# write byte 1 ttl output
ok,txt,err_or_val = io.do_writebyte( advantechapi.PORT_ID+1,0xff,1)
if ok==0:
print 'ttl output byte (bits 8..15) is %d (00000001)' % 1
else:
print "error %s, subcode %d when writing, % (io.OPCODES[ok],err_or_val)
3. Analog IO
da_writeanalog(channel,value):
'ok,txt,error = pci.da_writeanalog(channel,value) - write analog value to specified channel'
ad_readanalog(channel):
'ok,txt,error|value = pci.ad_readanalog(channel) - read analog value from channel'
|