AN-INI-1-002 IOcab 8444opto Basic Example
AN-INI-1-002 IOcab 8444opto Basic Example
AN-INI-1-002 IOcab 8444opto Basic Example
Version 1.1
2010-04-30
Table of Contents
1
Copyright © 2010 - Vector Informatik GmbH
Contact Information: www.vector.com or ++49-711-80 670-0
IOcab 8444opto Basic Example
1.0 Overview
This application note describes a small setup for a single IOcab 8444opto to test the digital/analog input and ouput
lines. A test application configures the lines of the IOcab, measures them cyclically and displays the results on the
screen. The test application uses the XL Driver Library to access the IOcab 8444opto. The XL Driver Library can
be found on the Vector Driver Disk (included in CANcardXL delivery) or on our website www.vector.com.
2.0 Setup
The example is split into two parts: A hardware setup and the configuration and measurement software.
The following chapters will describe each part in detail.
2.1 Hardware
This chapter describes the use case of the IOcab 8444opto, followed by the test setup.
A digital output line always affects two digital lines, which cannot be configured as input. Figure 2 shows, which
lines are affected. Please refer to the IOcab 8444opto user manual for further details.
2
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
DOUT0 1
1
9
2
9
2
2
10
10
DOUT0 3
3
1
11
11
4
4
12
12
DOUT1 5
5
13
2
13
6
6
14
14
DOUT1 7
7
1
15
15
8
8
DOUT2
DSUB15
2
DOUT2
1
DOUT3
2
DOUT3
1
DIN0
DIN1
DIN2
DIN3
DIN4
DIN5
DIN6
DIN7
DIN_GND
software
DIO0 1 DIO0 Digital Output
controlled
switch DIO1 9 DIO1 Digital Output
Figure 3: Externally supplied digital output. Output at DIO1 can be controlled by software.
3
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
software
7 AIO1 Analog Input
controlled
switch 15 AIO2 Analog Input
8 AIO3 Analog Input
Figure 4: Analog output and inputs. Inputs AIO2…AIO3 controlled by push buttons.
software
DIO0 8 AIO3 Analog Input
controlled
switch DIO1 1 DIO0 Digital Output
9 DIO1 Digital Output
2 DIO2 Digital Input
10 DIO3 Digital Input
digital
test setup
Figure 5: Setup with digital and analog lines. Digital output supplied by AIO0.
2.2 Software
This chapter describes the principles of the IOcab 8444opto configuration.
4
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
Source code:
// DIO0/DIO1 = Output (0b00000011), DIO2...DIO7 = Input (0b11111100)
switchMask = SWITCH_DIO0_DIO01;
digitalOutputMask = OUTPUT_DIO0_DIO01;
digitalInputMask = DIO_ALL & (~digitalOutputMask);
if (xlDAIOSetDigitalParameters(g_xlPortHandle,
g_xlChannelMask,
digitalInputMask,
digitalOutputMask)) {
printf("\nERROR: xlDAIOSetDigitalParameters failed\n");
return 0;
}
You will notice that the parameter digitalInputMask sets all digital IO lines, except for the output lines. This
ensures that no line is configured as input AND output at the same time. This would lead to an undefined state.
5
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
Source code:
// AIO0 = Output (0b0001), AIO1...AI03 = Input (0b1110)
analogOutputMask = AIO0;
analogInputMask = AIO_ALL & (~analogOutputMask);
if (xlDAIOSetAnalogParameters(g_xlPortHandle,
g_xlChannelMask,
analogInputMask,
analogOutputMask, 0x00)) {
printf("\nERROR: xlDAIOSetAnalogParameters failed\n");
return 0;
}
You will notice that the parameter analogInputMask sets all analog IO lines, except for the output lines. This
ensures that no line is configured as input AND output at the same time. This would lead to an undefined state.
Finally, a measurement frequency is set up which generates xlEvents cyclically. This event contains measured
data, which is received through the hardware queue. The frequency used in this example is 500 ms.
// Measure cyclically analog and digital ports
if (xlDAIOSetMeasurementFrequency(g_xlPortHandle,
g_xlChannelMask,
frequency)) {
printf("\nERROR: xlDAIOSetMeasurementFrequency failed\n");
return 0;
}
6
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
The outputMask bit sequence for the switches is as follows (can be combined with OR):
• DIO0 and DIO1: 0b0001
• DIO2 and DIO3: 0b0010
• DIO4 and DIO5: 0b0100
• DIO6 and DIO7: 0b1000
In xlDAIOexample the function ToggleSwitch is defined, which opens/closes all switches simultaneously by
pressing [ENTER].
void ToogleSwitch()
{
//closes/opens all relays at the same time
switchState = ~switchState;
if (xlDAIOSetDigitalOutput(g_xlPortHandle,
g_xlChannelMask,
switchMask,
switchState)) {
printf("\nERROR: xlDAIOSetDigitalOutput failed\n");
}
}
7
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
The following output will be displayed, when AIO2 has been connected with a wire to AIO0, the switch at DIO/DIO1
has been selected and turned on by software:
Example 2 (no external supply)
AIO0 4032mV Measured value of set output voltage (4096mV).
AIO1 0mV No input applied.
AIO2 4032mV AIO2 connected to AIO0.
AIO3 0mV No input applied.
Relays selected DIO/D01 The first switch is selected.
Relays state ON DIO1 connected to (supplied) DIO0.
Digital Port DIO7 DIO6 DIO5 DIO4 DIO3 DIO2 DIO1 DIO0 value
0 0 0 0 0 0 1 1 (3)
If an external supply is used, the digital input lines DIO4…DIO7 can also be used:
Example 3 (external supply)
AIO0 0mV No input applied.
AIO1 0mV No input applied.
AIO2 0mV No input applied.
AIO3 0mV No input applied.
Relays selected DI6/D07 The last switch is selected.
Relays state ON DIO7 is connected to (ext. supplied) DIO6.
Digital Port DIO7 DIO6 DIO5 DIO4 DIO3 DIO2 DIO1 DIO0 value
1 1 0 0 0 0 0 0 (C0)
8
Application Note AN-INI-1-002
IOcab 8444opto Basic Example
4.0 Contacts
9
Application Note AN-INI-1-002