home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR24
/
OTHL_100.ZIP
/
GIO-100.ZIP
/
GIO.DOC
< prev
next >
Wrap
Text File
|
1993-05-29
|
42KB
|
1,472 lines
Gern's 32-bit Multi-Thread Async I/O Routines for OS/2 2.0 (GIO)
Release 1.00
Copyright (c) 1992-1993 by John Morris All Rights Reserved
OS/2 is a trademark of the IBM corporation.
First, some background. What's a Gern? Well Gern is the 386-40 that
I do most of my programming on. The name Gern comes from a Steve Martin
comedy album from the late 70's.. Learn with Gern.. Ya gotta love that
guy! Gern's I/O routines then turned into 'GIO'.
When I started using a beta version of OS/2 2.0 I became fascinated
with the prospect of creating 32-bit programs. I went and bought the
Watcom C9.0/386 compiler.. Unfortunately this was some months before
I was able to obtain the official GA toolkit. Meanwhile I wanted to
get some IO routines written so I could start porting over some of the
doors I had written to OS/2. I started GIO using 16-bit MS C6 compiler.
I got it running pretty well with some mini comm applications I wrote
to test it. When I finally receive the GA toolkit I ported it over to
C9.0, and was amazed at how many of the functions calls had changed..
whew.. the port took a while longer than I had expected.
What GIO is intended to do is take some of the tedious programming out
of the equation. Using GIO you don't have to deal with file handles,
or terminally confusing calls to DosDevIOCtl. You just tell GIO what
you need it to do.
You need to have some experience with programming for OS/2, and you
might also get the OS/2 Physical Device Driver Reference for more
information on the data structures used in the asynchronous I/O
department. A copy of the IBM OS/2 toolkit is a must also. It is
a very good source of imformation! Get It!
At this point (late Sept. 92) GIO is not completed.. it may never be!
It may need more added functions, and/or more thorough docs, though I
hope I explained the functions well enough. What I am looking for is
feedback as to what needs to be added, or changed.
I am currently _not_ running OS/2 on my BBS as I am waiting till I
complete my 32-bit BBS program, and not until I can port some more
doors over to OS/2.. but I'm working on it. I need you folks to help
me test it. Beat it to death, etc.
You can reach me through the Fidonet at 1:213/760 or 761. RBBSNet at
8:919/1 or 2. But it is easiest to reach me via my BBS or voice phone:
John Morris
Tradewars Software
The Abandoned Land
702.359.1138 V32
702.359.0629 HST
702.359.1303 Voice Weekday Days, or Weekends.. I work evenings.
Your feedback will be greatly appreciated.
Hints on using GIO.
Copy GIO.DLL to your \OS2\DLL directory. Put GIO.LIB in the path
to your library files.
Programming.
To start, call ComOpen first. Even if you are passing it the
file handle of an already opened com port, GIO needs to set up its own
internal buffers, and variables.
If you wish to use GIO's debug mode dialog box, your program must
be a PM program (creates a message queue, and has a window). You must
call 'ComSetDebug(TRUE)' before calling ComOpen. Also, you may call
'ComSetDebugIdentity' with an identity string so you may distinguish
between multiple GIO infobox's.
Start up two threads in addition to the main program thread. Your
main program thread might be used to simply handle the windows message
queue, while two comm threads handle the input and output respectively.
Link your object files with GIO.LIB.
See the two example programs for more information.
#include <gio.h>
APIRET EXPENTRY ComOpen(PSZ PortName, SHORT PortNumber,
ULONG BPSRate, BYTE Parity,
SHORT DataBits, SHORT StopBits,
USHORT InBufSize, USHORT OutBufSize,
HFILE ValidHandle,ULONG OpenFLags)
ComOpen opens a com port, sets the BPS rate, line control, allocates
input and output buffers, and starts the threads that control the buffers.
PARAMETERS
PortName (PSZ) - input (added 10/7/92)
This is the name of the com port you wish to open. Use this to open
a port which does not used the standard 'COMx' filename.
PortNumber (SHORT) - input
This is the number of the com port you wish to open. For instance
to open COM1 this variable would be 1.
BPSRate (ULONG) - input
This is the BPS rate you wish to open the port at. Valid rates are
10 - 345600.
Parity (BYTE) - input
Determines if a parity bit should exist. The values of this field
may be as folows:
Value Definition
----- ----------
'O' Odd parity
'E' Even Parity
'M' Mark Parity (parity bit always 1)
'S' Space Parity (parity bit always 0)
'N' No Parity
DataBits (SHORT) - input
The number of bits contained in each character transmitted, or
received by way of the communications port. Valid values are:
Value Definition
----- ----------
5 5 data bits
6 6 data bits
7 7 data bits
8 8 data bits
StopBits (SHORT) - input
The number of stop bits associated with each character transmitted,
or received by way of the communications port. Valid values are:
Value Definition
----- ----------
0 This sets default stop bits. For a setting of 5 data bits,
The default is 1.5 stop bits. For 6, 7, or 8 data bits,
the default is 1 stop bit.
1 1 stop bit
2 2 stop bits
InBufSize (USHORT) - input
This determines the size of the input buffer GIO should create.
Valid sizes are 64 to 32000 bytes.
OutBufSize (USHORT) - input
This determines the size of the output buffer GIO should create.
Valid sizes are 64 to 32000 bytes.
ValidHandle (HFILE) - input
The handle of a currently open com port. If GIO is given a valid
handle, it will not attempt to use 'DosOpen' to open the port.
Use this if the program will be inheritting an already open port.
A value of '0' will cause GIO to use 'DosOpen' to open the port.
OpenFlags (ULONG) - input
LEAVEPORTOPEN -
If an error occurs while opening the port, this flag will tell
GIO whether or not to use 'DosClose' to close the com port. Using
DosClose will cause the carrier to be dropped, and if you don't
want this to happen, then turn this switch on.
OPENPORTSHARED -
Opens the port in 'OPEN_SHARE_DENYNONE' mode. If this bit it not set,
then the port is opened using 'OPEN_SHARE_DENYREADWRITE' mode.
OPENWRITETHROUGH -
When this flag is set, the open mode flag 'OPEN_WRITE_THROUGH' is used
when opening the port.
RETURNS
Return code.
ComOpen returns the following values:
0 No Errors
1 ERROR_INVALID_FUNCTION
6 ERROR_INVALID_HANDLE
31 ERROR_GEN_FAILURE
87 ERROR_INVALID_PARAMETER
111 ERROR_BUFFER_OVERFLOW
115 ERROR_PROTECTION_VIOLATION
117 ERROR_INVALID_CATEGORY
119 ERROR_BAD_DRIVER_LEVEL
163 ERROR_UNCERTAIN_MEDIA
165 ERROR_MONITORS_NOT_SUPPORTED
0xFF00 + 1 COMERR_PORT_NOT_OPEN
0xFF00 + 2 COMERR_INVALID_BUFFER_SIZES
0xFF00 + 3 COMERR_INPUT_BUFFER_ALLOCATION
0xFF00 + 4 COMERR_OUTPUT_BUFFER_ALLOCATION
0xFF00 + 5 COMERR_STARTING_INPUT_THREAD
0xFF00 + 6 COMERR_STARTING_OUTPUT_THREAD
0xFF00 + 7 COMERR_OPENING_PORT
0xFF00 + 8 COMERR_SETTING_BPS_RATE
0xFF00 + 9 COMERR_SETTING_LINE_CONTROL
0xFF00 + 10 COMERR_CARRIER_DROPPED
0xFF00 + 11 COMERR_NO_CHAR_WAITING
0xFF00 + 12 COMERR_TIMED_CHAR_NOT_RECIEVED
REMARKS
ComOpen is used to open a com port, set BPS rate, and line control.
This process also includes starting to 'threads' which control the
input and output buffers.
It can accept a file handle of an already open port, and simply use
that port, its current BPS rate, and line control settings. All GIO
will do in this case is allocate its own input and output buffers,
start the threads, and return.
If you wish to keep GIO from using 'DosClose' when shutting down
(in 'ComOpen' shutting down always means an error) then set the
'LEAVEPORTOPEN' flag in 'OpenFlags' to TRUE. 'DosClose' will usually
drop the carrier (if one is present), and the 'LEAVEPORTOPEN' switch
is used to control the dropping of the carrier.
To allow sharing of the com port, use the 'OPENPORTSHARED' flag.
ComOpen uses the Extended Set Bit Rate function found in OS/2 2.0.
This allows BPS rates of up to 345600! Using the extended com port
functions is not fully implemented in GIO, yet. You need DMA com port
hardware (found on some PS/2's) to use BPS rates above 57600 reliably.
On normal com port hardware the upper BPS limit will be 57600.
You can also tell GIO to use non-standard port names. If you pass
a string as a 'PortName' then GIO will use that name instead of
the regular "COM + PortNumber" combination. An example, Digiboards
allow you to set the name of each port. Lets say the first port
is 'DIGI1' You pass 'DIGI1' as the 'PortName'. In that case,
GIO will ignore 'PortNumber'. If you don't wish to use this feature,
set PortName to NULL, and GIO will use the regular "COMx" filename.
EXAMPLE CODE
This example shows a simple call to open COM1 at 19200, No Parity,
8 data bits, and 1 stop bit.
APIRET ReturnCode;
ReturnCode = ComOpen(NULL, 1, 19200, 'N', 8, 1, 1024, 1024, 0, 0);
if (ReturnCode)
{
printf("Error (%lu) opening COM port\n", ReturnCode);
exit (1);
}
This example shows a simple to open DIGI2 as the com port at 38400,
Even Parity, 7 data bits, and 1 stop bit.
APIRET ReturnCode;
ReturnCode = ComOpen("DIGI2", 0, 38400, 'E', 7, 1, 1024, 1024, 0, 0);
if (ReturnCode)
{
printf("Error (%lu) opening COM port\n", ReturnCode);
exit (1);
}
#include <gio.h>
APIRET EXPENTRY ComClose(BOOL LeavePortOpen)
ComClose shuts down a com port opened using ComOpen.
PARAMETERS
LeavePortOpen (BOOL) - input
Setting this parameter to TRUE will keep GIO from using 'DosClose'
when shutting down. 'DosClose' will usually drop the carrier (if
one is present) and this switch allows you to control whether or
not the carrier is dropped.
RETURNS
Always returns '0'.
REMARKS
ComClose is used to shut down the input and output buffer control
threads, frees the memory used by the buffers, and optional uses
'DosClose' to close the port.
EXAMPLE CODE
This example shows a simple call to open COM1 at 38400, Even Parity,
7 data bits, and 1 stop bit. Then immediately closes the port.
APIRET ReturnCode;
ReturnCode = ComOpen(NULL, 1, 19200, 'E', 7, 1, 1024, 1024, 0, FALSE);
if (ReturnCode)
{
printf("Error (%lu) opening com port\n", ReturnCode);
exit (1);
}
ComClose(FALSE);
#include <gio.h>
APIRET EXPENTRY ComSetBPSRate(ULONG BPSRate)
ComSetBPSRate sets the BPS rate for the port just opened using ComOpen.
PARAMETERS
BPSRate (ULONG) - input
BPS rate to set the com port at.
RETURNS
Return code.
ComSetBPSRate returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
0xFF00 + 1 COMERR_PORT_NOT_OPEN
REMARKS
ComSetBPSRate uses the set extended bit rate option of the DosDevIOCtl
function. Normally ComOpen sets this for you, so you do not need to
use this function.
If you do not receive a general failure error, the BPS rate was set as
defined.
EXAMPLE CODE
This examples changes the BPS rate to 19200.
APIRET ReturnCode;
ReturnCode = ComSetBPSRate(19200);
if (ReturnCode)
{
printf("Error (%lu) setting BPS rate\n", ReturnCode);
exit (1);
}
#include <gio.h>
APIRET EXPENTRY ComSetLineControl(BYTE Parity, SHORT DataBits,
SHORT StopBits)
ComSetLineControl is used to set the Parity, Data Bits, and Stop Bits
of the current open port.
PARAMETERS
Parity (BYTE) - input
Determines if a parity bit should exist. The values of this field
may be as folows:
Value Definition
----- ----------
'O' Odd parity
'E' Even Parity
'M' Mark Parity (parity bit always 1)
'S' Space Parity (parity bit always 0)
'N' No Parity
DataBits (SHORT) - input
The number of bits contained in each character transmitted, or
received by way of the communications port. Valid values are:
Value Definition
----- ----------
5 5 data bits
6 6 data bits
7 7 data bits
8 8 data bits
StopBits (SHORT) - input
The number of stop bits associated with each character transmitted,
or received by way of the communications port. Valid values are:
Value Definition
----- ----------
0 This sets default stop bits. For a setting of 5 data bits,
The default is 1.5 stop bits. For 6, 7, or 8 data bits,
the default is 1 stop bit.
1 1 stop bit
2 2 stop bits
RETURNS
Return code.
ComSetLineControl returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
0xFF00 + 1 COMERR_PORT_NOT_OPEN
REMARKS
ComSetLineControl is set when you used ComOpen, so in most cases you
will not need to use this function.
If you do not receive a general failure error, you can assume that the
line control was set as defined.
EXAMPLE CODE
This examples changes the line characteristics to Even Parity, 7 Data
Bits, and 1 Stop Bit.
APIRET ReturnCode;
ReturnCode = ComSetLineControl('E', 7, 1);
if (ReturnCode)
{
printf("Error (%lu) setting line controls\n", ReturnCode);
exit (1);
}
#include <gio.h>
APIRET EXPENTRY ComSetFlowControl(VOID)
ComSetFlowControl is used to turn on hardware handshaking, and
hardware timeouts.
PARAMETERS
None.
RETURNS
Return Code.
ComSetFlowControl returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
ComSetLineControl turns on RTS/CTS hardware flow control, and also
set hardware transmit and receive timeouts. It also enables DTR
control. Flow control is also set by ComOpen, so you may not have
to use this function.
If you do not receive a general failure error, you can assume that flow
control was set.
EXAMPLE CODE
This examples turns on RTS/CTS hardware flow control.
APIRET ReturnCode;
ReturnCode = ComSetFlowControl();
if (ReturnCode)
{
printf("Error (%lu) setting flow controls\n", ReturnCode);
exit (1);
}
#include <gio.h>
APIRET EXPENTRY ComSetDTR(SHORT DTROn)
ComSetDTR is used to turn the DTR signal on and off.
PARAMETERS
DTROn (SHORT) - input
If DTROn is TRUE, then the DTR signal is raised. If FALSE, then
the DTR signal is lowered.
RETURNS
Return Code.
ComSetDTR returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
Toggling the DTR line is usually used to drop carrier and/or reset
the modem. The DTR is lowered for a couple of seconds, then raised
in order for the modem to receive commands.
If you do not receive a general failure error, you can assume the DTR
signal was changed.
EXAMPLE CODE
This examples drops the DTR line for 3 seconds, then raises it.
APIRET ReturnCode;
ReturnCode = ComSetDTR(FALSE);
DosSleep(3000);
ReturnCode = ComSetDTR(TRUE);
#include <gio.h>
BOOL EXPENTRY ComReportDCD(VOID)
ComReportDCD is used to check for a carrier signal.
PARAMETERS
None.
RETURNS
TRUE if a carrier signal is detected.
FALSE is no carrier signal is detected.
REMARKS
ComReportDCD is usually used to see if a user has dropped the carrier.
EXAMPLE CODE
This examples checks to see if a carrier is present.
APIRET ReturnCode;
ReturnCode = ComReportDCD();
if (! ReturnCode)
printf("User has dropped carrier!\n");
#include <gio.h>
BOOL EXPENTRY ComReportCTS(VOID)
ComReportCTS reports the status of the CTS line.
PARAMETERS
None.
RETURNS
TRUE if CTS line is raised.
FALSE if CTS line is lowered.
REMARKS
The CTS line is usually used to determine if the remote users modem
is ready to receive characters. If the other modem is not ready to
receive characters the CTS line goes low.
EXAMPLE CODE
This examples checks to see if it is okay to send characters to our
modem.
APIRET ReturnCode;
ReturnCode = ComReportCTS();
if (ReturnCode)
printf("It's okay to send chars! The CTS line is high!\n");
#include <gio.h>
APIRET EXPENTRY ComXONEnable(VOID)
ComXONEnable is used to enable XON/XOFF style flow control.
PARAMETERS
None.
RETURNS
0 No Errors
REMARKS
When XON/XOFF flow control is enabled, the device driver transmits an
XOFF character when the receive queue is almost full, and an XON when
the receive queue is about half full.
EXAMPLE CODE
This examples enables XON/XOFF flow control.
APIRET ReturnCode;
ReturnCode = ComXONEnable();
#include <gio.h>
APIRET EXPENTRY ComXONDisable(VOID)
ComXONDisable is used to disable XON/XOFF flow control.
PARAMETERS
None.
RETURNS
0 No Errors
REMARKS
Turns off XON/XOFF flow control if it was enabled with ComXONEnable.
EXAMPLE CODE
This examples disables XON/XOFF flow control.
APIRET ReturnCode;
ReturnCode = ComXONDisable();
#include <gio.h>
APIRET EXPENTRY ComGetDCBInfo(PDCBINFO DCBInfo)
ComGetDCBInfo returns Device Control Block (DCB) information.
PARAMETERS
DCBInfo (PDCBINFO) - input/output
DCBInfo is a pointer to a DCB structure you have allocated. When the
function returns, the current DCB information will be in the structure
pointed to by DCBInfo.
RETURNS
Return Code.
ComGetDCBInfo returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
You can use ComGetDCBInfo to receive information on the following
items.
1. Transmit flow control using XON/XOFF.
2. Receive flow control using XON/XOFF.
3. Determine what the XON/XOFF characters are.
4. DTR Control mode.
5. RTS Control mode.
6. Transmit handshaking using CTS/DSR/DCD.
7. Reception of data using DSR.
8. Error replacement character and processing.
9. Break replacement character and processing.
10. Null stripping.
11. Transmit/Receive timeouts.
12. Extended hardware buffering info.
See the IBM Physical Device Driver Reference for more information.
ALWAYS call ComGetDCBInfo before calling ComSetDCBInfo. The information
returned should be modified by the application then set using
ComSetDCBInfo.
If a general failure is not returned, then valid information will be
in the DCBInfo structure.
EXAMPLE CODE
This example uses ComGetDCBInfo to get the current DCB parameters, it
then modifies them and sets the new DCB parameters.
DCBINFO DCBInfo;
APIRET ReturnCode;
ComGetDCBInfo(&DCBInfo);
DCBInfo.usWriteTimeout = 1;
DCBInfo.usReadTimeout = 1;
ReturnCode = ComSetDCBInfo(&DCBInfo);
if (! ReturnCode)
printf("We set new write & read timeouts!\n");
#include <gio.h>
APIRET EXPENTRY ComSetDCBInfo(PDCBINFO DCBInfo)
ComSetDCBInfo sets new Device Control Block (DCB) information.
PARAMETERS
DCBInfo (PDCBINFO) - input
DCBInfo is a pointer to a DCB structure you have allocated and/or
modified.
RETURNS
Return Code.
ComSetDCBInfo returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
You can use ComSetDCBInfo to set the following items.
1. Transmit flow control using XON/XOFF.
2. Receive flow control using XON/XOFF.
3. Determine what the XON/XOFF characters are.
4. DTR Control mode.
5. RTS Control mode.
6. Transmit handshaking using CTS/DSR/DCD.
7. Reception of data using DSR.
8. Error replacement character and processing.
9. Break replacement character and processing.
10. Null stripping.
11. Transmit/Receive timeouts.
12. Extended hardware buffering info.
See the IBM Physical Device Driver Reference for more information.
ALWAYS call ComGetDCBInfo before calling ComSetDCBInfo. The information
returned should be modified by the application then set using
ComSetDCBInfo.
If a general failure is not returned, then you may assume that the
device driver changed the information.
EXAMPLE CODE
This example uses ComGetDCBInfo to get the current DCB parameters, it
then modifies them and sets the new DCB parameters.
DCBINFO DCBInfo;
APIRET ReturnCode;
ComGetDCBInfo(&DCBInfo);
DCBInfo.fbCtlHndShake = MODE_CTS_HANDSHAKE | MODE_DTR_CONTROL;
ReturnCode = ComSetDCBInfo(&DCBInfo);
if (! ReturnCode)
printf("We set new handshake info!\n");
#include <gio.h>
APIRET EXPENTRY ComPurgeTXBuffer(VOID)
ComPurgeTXBuffer is used to flush the output buffers.
PARAMETERS
None.
RETURNS
0 (No Error)
REMARKS
Use ComPurgeTXBuffer if you wish to flush all data which were to
be transmitted. This function clears the GIO output buffer as well
as the device driver output buffer.
EXAMPLE CODE
The following short example flushes the output buffer.
ComPurgeTXBuffer();
#include <gio.h>
APIRET EXPENTRY ComTXCharImm(BYTE Char)
ComTXCharImm transmits a byte immediately.
PARAMETERS
Char (BYTE) - input
This is the character you wished to be transmitted immediately.
RETURNS
Return Code.
ComTXCharImm returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
If a general failure is not returned then the character was transmitted.
ComTXCharImm always returns immediately (before the character is actually
transmitted). If you already have sent one character using this function
and it has not been sent, then this function will return a general
failure.
If there are already bytes waiting in the buffer to be transmitted, then
the byte goes to the 'front' of the buffer, and will be the next
character transmitted.
The byte is not transmitted if flow control is currently not allowing
any data to be transmitted.
ComTXCharImm is generally used to send XON and XOFF characters.
Purging the transmit buffers does not purge a byte sent using
ComTXCharImm.
EXAMPLE CODE
This examples sends a Ctrl-Q (a typical XON character) to the port.
APIRET ReturnCode;
BYTE XONChar = 17;
ReturnCode = ComTXCharImm(XONChar);
#include <gio.h>
ULONG EXPENTRY ComTXChar(BYTE Char)
ComTXChar sends one byte to the communications port.
PARAMETERS
Char (BYTE) - input
This is the byte to be sent to the communications port.
RETURNS
0 (No Error)
REMARKS
The char to be transfered is placed in the next available spot in
the transmit buffers. And is sent out as soon as possible.
EXAMPLE CODE
This examples sends a character from the keyboard to the com port.
APIRET ReturnCode;
int KeyIn;
do
{
if (kbhit())
{
KeyIn = getch();
ReturnCode = ComTXChar((BYTE) KeyIn);
}
} while (1);
#include <gio.h>
APIRET EXPENTRY ComTXString(PSZ String, BOOL CheckCD)
ComTXString sends a zero-terminated string to the com port.
PARAMETERS
String (PSZ) - input
This is the string to be sent to the comm port. It must be zero-
terminated.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
RETURNS
0 No Errors
0xFF00 + 10 COMERR_CARRIER_DROPPED
REMARKS
If you ask the function not to check for a valid carrier signal, then it
will always return 0 (No Errors).
The string is placed in the transmit buffers character by character, and
these chars are sent out as soon as possible.
EXAMPLE CODE
This examples sends a string to the com port, and checks for a dropped
carrier:
APIRET ReturnCode;
PSZ StringOut = "This is a test of the ComTXString function\n\r";
ReturnCode = ComTXString(StringOut, TRUE);
if (ReturnCode)
printf("The remote user dropped the carrier!\n");
#include <gio.h>
APIRET EXPENTRY ComTXBuffer(PBYTE Buffer, ULONG Size, BOOL CheckCD)
ComTXBuffer sends a buffer of a defined length to the com port.
PARAMETERS
Buffer (PBYTE) - input
This is a pointer to the data to be transmitted.
Size (ULONG) - input
This is the amount of bytes to be transmitted.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
RETURNS
0 No Errors
0xFF00 + 10 COMERR_CARRIER_DROPPED
REMARKS
If you ask the function not to check for a valid carrier signal, then it
will always return 0 (No Errors).
The string is placed in the transmit buffers character by character, and
these chars are sent out as soon as possible.
EXAMPLE CODE
This examples sends a buffer of data to the com port, and doesn't check
for carrier:
APIRET ReturnCode;
BYTE CharBuffer[128];
memset(CharBuffer, 32, 128); // fill buffer with spaces (' ')
ReturnCode = ComTXBuffer(StringOut, 128, FALSE);
#include <gio.h>
APIRET EXPENTRY ComTXEmpty(VOID)
ComTXEmpty determines whether or no the transmite buffers are empty.
PARAMETERS
None.
RETURNS
TRUE is the transmit buffers are empty.
FALSE if any bytes remain in the transmit buffers.
REMARKS
ComTXEmpty is usually used to determine if all bytes have been sent
out the com port before a program ends, which will destroy the data
in the buffers.
EXAMPLE CODE
This example waits an indefinate period until the transmit buffers
are empty before it exits.
while (! ComTXEmpty());
exit();
#include <gio.h>
APIRET EXPENTRY ComTXFull(VOID)
ComTXFull determines whether or not the transmit buffers are full.
PARAMETERS
None.
RETURNS
TRUE is the transmit buffers are full.
FALSE if no bytes remain in the transmit buffers.
REMARKS
EXAMPLE CODE
This example shows whether or not the transmit buffers are full.
APIRET ReturnCode;
if (ComTXFull())
printf("The transmit buffer is full\n");
#include <gio.h>
APIRET EXPENTRY ComTXFree(PUSHORT BytesFree)
ComTXFree returns how many free bytes are in the transmit buffer.
PARAMETERS
BytesFree (PUSHORT) - output
BytesFree is a pointer to a variable which will receive the number
of bytes free in the transmit buffer.
RETURNS
0 No Errors
REMARKS
ComTXFree is usually used to determine if there is enough room in the
buffers for the data you are about so send. This sort of anticipates
a condition where flow control takes over.
EXAMPLE CODE
This example shows how many bytes are free in the transmit buffer.
USHORT BytesFree;
ComTXFree(&BytesFree);
printf("The transmit buffer has %u bytes free\n", BytesFree);
#include <gio.h>
VOID EXPENTRY ComWaitTillTXEmpty(ULONG Delay)
ComWaitTillTXEmpty returns when the transmit buffer is empty, or a delay
period has expired.
PARAMETERS
Delay (ULONG) - input
Maximum time to wait for the transmit buffer to empty in hundredths
of a second.
RETURNS
None.
REMARKS
ComWaitTillTXEmpty returns when the transmit buffer is empty, or the
time delay period expires, whichever comes first.
The delay time is in hundredths of a second rather than thousands of
a second associated with the 'DosSleep' function.
EXAMPLE CODE
This example waits five seconds or until the transmit buffer is empty.
ComWaitTillTXEmpty(500);
printf("The transmit buffer is empty.. ending program\n");
exit();
#include <gio.h>
APIRET EXPENTRY ComPurgeRXBuffer(VOID)
ComPurgeRXBuffer is used to purge the input buffers.
PARAMETERS
None.
RETURNS
0 No Errors
REMARKS
ComPurgeRXBuffer can be used to purge all input from the remote user.
EXAMPLE CODE
The following line purges the input buffers.
ComPurgeRXBuffer();
return;
#include <gio.h>
APIRET EXPENTRY ComRXChar(PSHORT Char)
ComRXChar returns the next available char in the input buffer, if any.
PARAMETERS
Char (PSHORT) - output
The next available character is stored in Char. If no character is
waiting Char will be -1.
RETURNS
0 No Errors
0xFF00 + 11 COMERR_NO_CHAR_WAITING
REMARKS
If ComRXChar returns with a 0 return code a valid character is contained
in Char. Otherwise Char is -1, and a error code is returned.
After ComRXChar has read in the next character it is removed from the
buffer.
For best results, use ComRXChar after you have determined whether or
not a character is waiting using ComRXCharWaiting.
EXAMPLE CODE
The follow example uses ComRXCharWaiting to determine is a character is
waiting then uses ComRXChar to retrieve the character.
SHORT CharIn;
APIRET ReturnCode;
if (ComRXCharWaiting())
ReturnCode = ComRXChar(&CharIn);
#include <gio.h>
APIRET EXPENTRY ComRXPeek(PSHORT Char)
ComRXPeek retrieves the next character from the input buffer without
removing it from the buffer.
PARAMETERS
Char (PSHORT) - output
The next available character is stored in Char. If no character is
waiting Char will be -1.
RETURNS
0 No Errors
0xFF00 + 11 COMERR_NO_CHAR_WAITING
REMARKS
If ComRXPeek returns with a 0 return code a valid character is contained
in Char. Otherwise Char is -1, and a error code is returned.
Use ComRXPeek to determine what the next character is without removing
it from the input buffer.
For best results, use ComRXPeek after you have determined whether or
not a character is waiting using ComRXCharWaiting.
EXAMPLE CODE
The follow example uses ComRXPeek to determine is a character is
waiting then uses ComRXChar to retrieve the character.
SHORT CharIn;
APIRET ReturnCode;
if (ComRXCharWaiting())
ReturnCode = ComRXChar(&CharIn);
#include <gio.h>
APIRET EXPENTRY ComRXCharWaiting(VOID)
ComRXCharWaiting is used to determine whether or not a character is
available in the input buffer.
PARAMETERS
None.
RETURNS
TRUE if a character is waiting.
FALSE if no character is waiting.
REMARKS
Use ComRXCharWaiting to see if there are any pending characters before
you make a call to ComRXChar or ComRXPeek.
EXAMPLE CODE
The follow example uses ComRXCharWaiting to determine is a character is
waiting then uses ComRXChar to retrieve the character.
SHORT CharIn;
APIRET ReturnCode;
if (ComRXCharWaiting())
ReturnCode = ComRXChar(&CharIn);
#include <gio.h>
APIRET EXPENTRY ComRXCharTimed(PSHORT Char, ULONG Delay)
ComRXCharTimed is used to wait a certain amount of time for an expected
character.
PARAMETERS
Char (PSHORT) - output
The next available character is stored in Char. If no character is
waiting Char will be -1.
Delay (ULONG) - input
Maximum time to wait for expected character in hundredths of a
second.
RETURNS
0 No Errors
0xFF00 + 12 COMERR_TIMED_CHAR_NOT_RECEIVED
REMARKS
ComRXCharTimed is used to receive an expected character within a
certain time period. If the character is received within the specified
time period then the return code is zero (0). Otherwise you will
receive the COMERR_TIMED_CHAR_NOT_RECEIVED error.
This function is useful in protocol situations where characters are
expected within certain time frames.
The delay time is in hundredths of a second rather than thousands of
a second associated with the 'DosSleep' function.
EXAMPLE CODE
The following example waits 2.5 seconds for an expected character.
SHORT CharIn;
APIRET ReturnCode;
ReturnCode = ComRXCharTimed(&CharIn, 250);
if (ReturnCode)
printf("Expected character not received!\n");
#include <gio.h>
VOID EXPENTRY ComSetDebug(BOOL Mode)
ComSetDebug is used to start up GIO's 'Infobox' dialog window which shows
information on GIO.
PARAMETERS
Mode (BOOL) - input
FALSE - turns debug mode off.
TRUE - turns debug mode, and GIO dialog box on.
RETURNS
None.
REMARKS
Calling ComSetDebug starts up two more threads within GIO. One is a
thread which opens a message queue and pops up a dialog box which
will contain information on the current copy of GIO. The other thread
updates some of the data in the dialog, so you don't have to.
If you wish to use the GIO Infobox (as the dialog is called) call
ComSetDebug(TRUE) before calling ComOpen. This assures that all data
will be up-to-date on your local screen. If you wish to uniquely
indentify each GIO Infobox, call ComSetDebugIdentity with an identity
string (see ComSetDebugIdentity).
Currently the infobox will show the status of several modem lines such
as DTR, CTS, and DCD. It also shows RTS, but the RTS box is currently
not implemented. The DTR box is not updated unless you call ComSetDTR.
The program wishing to create the dialog box must be a PM based
program. If the program is not PM based, you will here a very short
beep which occurs when GIO can't create the dialog box.
EXAMPLE CODE
The following turns debug mode on, sets a unique identity, and then
calls ComOpen.
APIRET ReturnCode;
ComSetDebug(TRUE); // turn debug mode on
sprintf(sTempString, "TW/2 - Node %d", sNode);
ComSetDebugIdentity(sTempString); // unique identifier
ReturnCode = ComOpen(NULL, 1, 19200, 'N', 8, 1, 1024, 1024, 0, FALSE);
#include <gio.h>
APIRET EXPENTRY ComPause(VOID)
Used to temporarily stop GIO's input and output threads. For instance, if
your com program must shell out to another com program, you might want to
stop GIO's threads from continually grabbing characters from the port.
PARAMETERS
None.
RETURNS
0 No Errors
REMARKS
This function grabs the input and output semaphores, and doesn't let them
go. It effectively stops the input and output threads.
To start the threads back up, use ComResume. It releases the semaphores
grabbed by ComPause.
EXAMPLE CODE
This code calls ComPause then ComResume.
APIRET ReturnCode;
ReturnCode = ComPause(); // stop input and output threads.
//
// the program might shell out to another com program here.
//
ReturnCode = ComResume(); // restart input and output threads.
//
// the program resumes here.
//
#include <gio.h>
APIRET EXPENTRY ComResume(VOID)
ComResume is used to restart the input and output threads which were stopped
by ComPause.
PARAMETERS
None.
RETURNS
0 No Errors
REMARKS
This function releases the input and output thread semaphores grabbed by
ComPause.
EXAMPLE CODE
This code calls ComPause then ComResume.
APIRET ReturnCode;
ReturnCode = ComPause(); // stop input and output threads.
//
// the program might shell out to another com program here.
//
ReturnCode = ComResume(); // restart input and output threads.
//
// the program resumes here.
//
#include <gio.h>
APIRET EXPENTRY ComQueryHandle(PHFILE Handle)
ComQueryHandle returns a copy of the com port handle used by GIO.
PARAMETERS
Handle (PHFILE) - output
Contains the address of the variable which will contain the copy
of file handle used by GIO.
RETURNS
0 No Errors
REMARKS
This function is provided as a convenience only. It will return a copy
of the file handle used by GIO for the current com port. Be very
careful what you do with this copy of the handle, as you might cause
GIO to malfunction.
It should be used to pass on the handle to any child programs which may
need access to the com port.
EXAMPLE CODE
This example retrieves a copy of GIO's file handle.
APIRET ReturnCode;
HFILE ThisIsTheGIOHandle;
ReturnCode = ComQueryHandle(&ThisIsTheGIOHandle);
printf("The file handle in use by GIO is %lu\n", ThisIsTheGIOHandle);
#include <gio.h>
APIRET EXPENTRY ComSetInfoboxHwnd(ULONG Type, HWND Hwnd)
This function is to used parent and/or owner window of the GIO Infobox
dialog window.
PARAMETERS
Type (ULONG) - input
COM_SETINFOBOXPARENT - This will cause the HWND contained in the
second parameter to become the parent window
of the GIO Infobox.
COM_SETINFOBOXOWNER - This will cause the HWND contained in the
second paramter to become the owner window
of the GIO Infobox.
Hwnd (HWND) - input
This is the parent or owner window handle as specified by the 'Type'.
RETURNS
0 No Errors
REMARKS
The default parent and owner of the GIO Infobox dialog is the desktop.
You can change the parent and/or the owner of the Infobox using the
call.
If you wish to set the owner, and the parent, you must make two separate
calls to ComSetInfoboxHwnd.
EXAMPLE CODE
This example sets the parent of the GIO Infobox.
APIRET ReturnCode;
HWND MyHwnd; // set by your code
ReturnCode = ComSetInfoboxHwnd(COM_SETINFOBOXPARENT, MyHwnd);
#include <gio.h>
VOID EXPENTRY ComSetDebugIdentity(PSZ Identity)
This function is used to uniquely identify each GIO Infobox with a string
of your choice.
PARAMETERS
Identity (PSZ) - input
A pointer to the string you wish to use to identify the GIO Infobox.
RETURNS
None.
REMARKS
You may identify each GIO Infobox with a string up to 20 characters in
length. If you string is longer than 20 characters, GIO will use only
the first 20 characters.
This string is shown in the dialog box when it is visible, and in
the dialog title when the dialog box is minimized.
EXAMPLE CODE
PSZ = MyIdentifier = "Unique Identifier";
ComSetDebugIdentity(MyIdentifyier);