version 1.1
1. Summary
The driver scans all connected boards at startup time and assigns them a device
number from 0 to 19. This number will be used to address the card. You can
combine any number of the abovementionned types of card, the only restriction
being that the number of card is equal or below 20.
The driver is written in C++, and expose C functions that can be called from
most languages. A visual basic sample is given, which allow you to test the
functionalities, and to read the device numbers attributed to your hardware.
Licensing
This software is copyrighted. The copies are digitally tagged to identify
their initial origin.
personal use license: you may use this driver for your own private use.
Redistribution of software including this driver is strictly prohibited. You must
obtain it from www.cockpitware.com.
Developer license: you are entitled to redistribute this driver along with your
software, in an unlimited number of copies. This is subject to the payment of a
fee. Pleas contact olivier at cockpitware.com if you are interested.
2. Initializing the driver
- file : reference (pointer) to a text file handle, which will be used to log
information, and can be useful for debugging.
- handle : A window handle, corresponding to your application window, so
the driver can send messages to your window.
Then, additional parameters must be sent, like the number of master cards
connected to each USB expansion card, and the numbers of A/D channels in use
on each expansion card. For this purpose, use the following functions :
To set the number nb of master cards in use on the USB expansion card, the
USB expansion card being labelled by dev. IMPORTANT : the call to
SetMasterCardNbr must occur BEFORE the call of InitUSBCardParams, in the case
where you use mastercards and the usb expansion cards. Otherwise,
unpredictable behaviour may occur (unitialized pointers).
To set the number nb of A/D channels in use on the USB expansion card labelled
by dev.
Then you can start to send commands to all cards and get information from
them, using different functions listed below.
Each USB exp card has 4 A/D channel. Each channel can read an input voltage
between 0 and 5V, and convert it in a 8bit value : 0 for 0 volt and 255 for 5
volts. You can get the value present on a given A/D channel by using the
function:
C version :
dev is the device number of the given USB expansion card, and channel is the
A/D channel number to read (from 0 to 3). A value between 0 and 255 is
returned. A negative returned value is an error code : -1 indicates an improper
channel number, and -10 a improper device number.
Each master card has 72 inputs, so 288 inputs per USB expansion card, labelled
from 0 to 287.
C version :
Basic version :
dev is the device number (0..19) and n is the input number, as indicated in the
table above. The returned value is either 0 or 1, to indicate that the input is ON
or OFF, or a negative value to indicate an error condition (see function table in
annex).
You may also want to write the initial state of an input buffer. Real hardware
input are read when they change, and their state is stored in a buffer. In
particular cases, it may be interesting to change this value. In particular, the
USB microcode (in the device on some versions of the usb expansion cards)
suffers from an initialization bug where the 9th input of a group is not always well
initialized at startup. The value of this buffer may be changed by the following
command:
C version :
With the following function, you can test whether any input has changed:
C version :
Beware that reading any input with the GetMasterInput function resets the state
of the GetMasterInputChange function until the next change. You need to read all
the inputs to determine all those that have changed.
If you try to set an output in the “output gap” (for example between 0 and 11, or
183 and 203), nothing will happen (it will be intercepted by the driver).
C version :
Basic:
In some case, it may be interesting to be able to read the state of the output
internal buffer (the value that was previously set on the output). This is achieved
using the function :
Button helpers
You register the input “num” at device “dev” as being a pushbutton, with initial
state “initial (0 or 1)”. You can then read its state (0 or 1) using:
Each master card can connect to 4 display cards, each having 16 digits, so 64
display per master card. So, a USB expansion card can hold up to 256 displays.
The displays (single digits) are labelled from 0 to 255 for each USB expansion
card:
C version :
Basic version :
dev is the device number (0..19) and display is the display number, between 0
and 255. value correspond to the digit value, and can take the following values :
value on
display
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 Blank
248 -
249 6
250 t
251 d
252 Intensity
control
In some case, you need to check the values in a display. You can use the
following function to read the display buffer :
C version :
Here, the format parameter is the number of digits (7 segments displays) used
to display the number.
Most of the time, you want to display a multi-digit number, for ex. 357
To simplify your life and avoid you to manipulate decimal coded binary and other
funny things, this is included in this driver.
You need to declare that a display will be associated with others to display the
multi-digit number. The displays used MUST be in consecutive order.
C version :
Basic version :
Then, you can display a number of several digits on your registered display, by
calling :
Then, it may also useful to blank a whole group of digits, forming a registered
display. This can be made with :
In most cases, you also need to use rotary encoders. In this version, Gray
rotary encoders, using two entries of a mastercard are fully supported. You need
to declare them with:
C version:
int SetGray(int dev, int num, int input, int type, int initial int high,
int low, int incr)
Basic version:
Parameter Meaning
Device number (USB expansion card)
dev
It is often very handy that the increment increases with the rotating speed of the
rotary encoder, so you can reach a distant setpoint more easily. This is controlled
by an acceleration parameter, which is set by the function:
C version :
Basic version :
Of course, the most important thing is to be able to read the encoder value. You
can do so with:
C version :
Basic version :
Finally, most of the time, you want to display the value from a Gray encoder on a
Display. To avoid you the burden of programming this, we have included in the
driver a direct connection from encoders to displays.
Once you have set an encoder with SetGray and a multi-digit display with
RegisterDisplay, you can connect them with:
C version :
Basic version :
Where dev and num corresponds to the device number (usb expansion card)
and encoder number(label, see 3-f) for the Gray encoder considered. devlink
and numlink correspond to the device and display number of the multi digit
display which must display the encoder values.
Then, after that, when you turn the Gray encoder, the display will automatically
reflect the encoder value (which you can still read with ReadGray).
4. USB servos card
This card allows to control up to 6 servo-motors and has four 8bit A/D channels.
Each servo takes a setpoint between 0 and 1023, i.e. the setpoint has
1024 different values (10 bits resolution). The setpoint is given using the
following function:
C version :
Basic version :
As usual, dev and servo corresponds to the device number (servo card) and
servo number in the given card (0 to 5). Setpoint is the setpoint value
(0..1023).
The A/D channels are 8bit in width, they return values between 0 and 255. There
are four channels, labelled from 1 to 4.
C version :
Basic version :
The driver can get values from multiple USB key cards. All input are
collected in a buffer. The buffer values are in the form of a two byte unsigned
value. The upper part is the device number, identifying a given keyboard, and
the lower part is the key code for the key which has been pressed.
C version :
USHORT GetKBDBuffer ()
Basic version :
GetKBDBuffer () As UShort
If you make windows programming, you can benefit from using windows
messages, to be notified in real time of the event of a key pressed.
int RegisterKbdMessage();
This will register for you a windows message, so your code can be notified by
windows.
Then use a code similar to this one to intercept the corresponding message with
the value (code) of the key pressed :