Measurement Computing Data Acquisition Systems rev.10.4 User Manual
Page 29

Digital I/O on P2
This program demonstrates the functions
controlling digital I/O on the P2 connector of the
device. First, the 3 digital ports on the 8255 are
configured as input, output, or both in the case of
port C; then, appropriate I/O commands are
issued. Functions used include:
•
VBdaqIOReadBit&(handle&,
devType&, devPort&,
whichDevice&, whichExpPort&,
bitNum&, bitValue&)
•
VBdaqIORead&(handle&,
devType&, devPort&,
whichDevice&, whichExpPort&,
value&)
•
VBdaqIOWriteBit&(handle&,
devType&, devPort&,
whichDevice&, whichExpPort&,
bitNum&, bitValue&)
•
VBdaqIOWrite&(handle&,
devType&, devPort&,
whichDevice&, whichExpPort&,
value&)
•
VBdaqIOGet8255Conf&(handle&,
portA&, portB&, portCHigh&,
portCLow&, config&)
Dim config&, byteVal&, bitVal&, x%
Dim buf(10) As Byte, active&, retCount&
handle& = VBdaqOpen&(“DaqBook0”)
ret& = VBdaqSetErrorHandler&(handle&, 100)
On Error GoTo ErrorHandlerDIG1
ret& = VBdaqIOGet8255Conf&(handle&, 0, 1, 0, 1, config&)
The function daqIOGet8255Conf returns the appropriate configuration value to use in daqIOWrite. As
shown above, the handle of the opened Daq device is the first parameter passed. The second, third, fourth,
and fifth parameters respectively indicate: the 8255 port A value, the port B value, the high-nibble value of
port C, and the low-nibble value of port C. The values for the parameters passed in the call shown above
will return the configuration value (port A = OUTPUT, port B = INPUT, port C / high nibble = output, port
C / low nibble = INPUT) in the config& parameter, which matches the current configuration of the 8255.
The daqIOWrite function writes the obtained configuration value to the selected port.
ret& = VBdaqIOWrite&(handle&, DiodtLocal8255&, Diodp8255IR&, 0, 0,_ config&)
Write hex 55 to port A on the Daq device’s base unit.
ret& = VBdaqIOWrite&(handle&, DiodtLocal8255&, Diodp8255A&, 0, 0,_ &H55)
Read port B and put the value into the variable byteVal%.
ret& = VBdaqIORead&(handle&, DiodtLocal8255&, Diodp8255B&, 0, 0,_ byteVal&)
Print "The value on digital port B : &H"; Hex$(byteVal&): Print
The following lines write to the high nibble of port C.
ret& = VBdaqIOWriteBit&(handle&,DiodtLocal8255&,Diodp8255CHigh&,0,_ 0,0,1)
ret& = VBdaqIOWriteBit&(handle&,DiodtLocal8255&,Diodp8255CHigh&,0,_ 0,1, 0)
ret& = VBdaqIOWriteBit&(handle&,DiodtLocal8255&,Diodp8255CHigh&,0,_ 0, 2, 1)
ret& = VBdaqIOWriteBit&(handle&,DiodtLocal8255&,Diodp8255CHigh&,0,_ 0, 3, 0)
Print "The high nibble of digital port C set to : 0101 (&H5)": Print
The next lines read the low nibble of port C on the base unit.
Programmer’s Manual
988594
API Programming, General Models 2-19