![AWC GP3 Скачать руководство пользователя страница 19](http://html.mh-extra.com/html/awc/gp3/gp3_manual_3035292019.webp)
Reference
The GP3 has a simple command structure. When using the libraries, the commands are even simpler. Each
section below describes a command and how to execute it either directly or via the standard libraries. Unless
you are trying to write your own library for a different platform, you probably won't care about the direct
commands.
When using either ActiveX library, you must set the commport parameter to match the port the GP3 is using
(e.g., set to 1 for COM1). In addition, you must set portopen to TRUE to connect to the hardware.
If you are directly controlling the GP3 (and not using the library), you need to know a little bit about how the
protocol works. To prevent synchronization errors, each command byte starts with a 0 bit. Each data byte starts
with a 1 bit. This requires numbers to be packed to fit. In general a command has the binary format (the raw
commands are specified in binary):
0 C C C P P P L
Where C C C is the command code (0 to 7), P P P is typically a pin number (0-7) and L is the LSB of any data
byte. If additional data is required, the next byte sent will have the format:
1 N N N N N N N
Since this is only 7 bits, the convention is that the GP3 accepts the value divided by 2. The L bit from the
command makes the entire 8 bit number. All communications are at 57600 baud, 8 bits, 1 stop bit, and no parity.
In addition, there is a 16-bit argument (ARG) that can be set by special commands. Some commands use this
argument word as an additional source of data. When the GP3 sends data to the PC, it is not encoded in any
particular way since the GP3 only responds to queries from the PC there is no chance of desynchronizing. All
data back and forth is in binary (although the results from a raw inp command happen to be an ASCII "0" and
"1").
By default, all digital I/O pins are inputs until you change them explicitly to outputs. Hardware handshaking
allows you to determine when the GP3 is busy. The GP3 will remain busy while performing any operation,
although hardware PWM and the hardware counter works without tieing up the GP3.
For the purposes of this manual, a byte has 8 bits and a word has 16 bits. Raw commands are shown in binary.
Each raw command is a single byte, not 8 ASCII characters.
Common Commands
These commands are provided in the standard ActiveX libraries. In addition, each command discusses the raw
command bytes you would send to duplicate the command if you are writing your own libraries.
high(pin), low(pin) –
These commands are the easiest way to manipulate the output pins of the GP3. These
commands force the pin (from 0 to 7) to be an output and set the logic state to high, low respectively.
Raw
command: 0 0 0 1 P P P H where P P P is the pin number and H=0 for low or 1 for high.
toggle(pin) –
Sets an output pin (from 0 to 7) to an output and inverts its current state.
Raw command: 0 0 1 0 P
P P 0 where P P P is the pin number.
-16-