1. Read isolated digital inputs
# read bit 0 isolated input
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID, 0)
if ok==0:
print 'di_readbit: isolated input 0 is %d' % err_or_val
else:
print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
# read bit 8 isolated input
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID+1, 0)
if ok==0:
print 'di_readbit: isolated input 8 is %d' % err_or_val
else:
print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
# read bit 13 isolated input
#ok,txt,error|value = pci.do_readbit(port,bit) - read specified bit from specified port
ok,txt,err_or_val = io.di_readbit(bionicapi.PORT_ID+1, 5)
if ok==0:
print 'di_readbit: isolated input 8 is %d' % err_or_val
else:
print 'di_readbit: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
2. Write isolated outputs
# write bit 2 isolated output to 1
mask = 0b00000010 # Write the binary mask of 00000010
ok,txt,err_or_val = io.do_writebit(bionicapi.PORT_ID, mask, 1)
if ok==0:
print 'do_writebit: isolated output 0 is %d' % 1
else:
print 'do_writebit: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)
# write bits 3 and 4 isolated output to 1
mask = 0b00001100 # Write the binary mask of 00001100
ok,txt,err_or_val = io.do_writebit(bionicapi.PORT_ID, mask, 1)
if ok==0:
print 'do_writebit: isolated output 0 is %d' % 1
else:
print 'do_writebit: 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( bionicapi.PORT_ID,0xff,1)
if ok==0:
print 'do_writebyte: isolated output byte (bits 0..7) is %d' % 1
else:
print 'do_writebyte: 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( bionicapi.PORT_ID+1,0xff,1)
if ok==0:
print 'do_writebyte: isolated output byte (bits 8..15) is %d' % 1
else:
print 'do_writebyte: error %s, subcode %d when writing' % (io.OPCODES[ok], err_or_val)
3. Analog IO
# read analog input value from 0. channel
ok,txt,err_or_val = io.ad_readanalog(0)
if ok==0:
print 'ad_readanalog: 0. channel analog input value is %d' % err_or_val
else:
print 'ad_readanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
# read analog input value from 2. channel
ok,txt,err_or_val = io.ad_readanalog(2)
if ok==0:
print 'ad_readanalog: 2. channel analog input value is %d' % err_or_val
else:
print 'ad_readanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
# write analog value to 0. output channel
ok,txt,err_or_val = io.da_writeanalog(0, 1)
if ok==0:
print 'da_writeanalog: 0. channel analog output value is %f' % 1
else:
print 'da_writeanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
# write analog value to 1. output channel
ok,txt,err_or_val = io.da_writeanalog(1, 5.5)
if ok==0:
print 'da_writeanalog: 1. channel analog output value is %f' % 5.5
else:
print 'da_writeanalog: error %s, subcode %d when reading' % (io.OPCODES[ok], err_or_val)
4. Close device
io.close()
|