home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
gio-201.zip
/
GIO2.DOC
< prev
next >
Wrap
Text File
|
1994-07-06
|
49KB
|
1,744 lines
Gern's 32-bit Multi-Thread Async I/O Routines for OS/2 2.0 (GIO)
Release 2.01
Copyright (c) 1992-1994 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 486-66 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 Mar. 94) 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. If you want more
functions, ASK!
Changes To GIO 2.0
I changed the concept of GIO between version 1.00, and 2.00. GIO
1.00 was a set of com routines which featured input and output ring buffers
with each ring buffer on a separate thread. GIO 1.00 could only be used
on one com port per process.
GIO 2.00 eliminates the threads on the input and output ring buffers. In
fact GIO 2.00 does not use ring buffers! When it comes down to it, the OS/2
comm device driver (ie. COM.SYS, or Ray Gwinn's SIO.SYS) have their own
ring buffers right? Why have TWO ring buffers for input, and two for
output? In my humble opinion, that is redundant, and not multi-tasking
friendly. So in that way GIO 2.00 is no longer multi-threaded. This is not
as bad as it may sound.
GIO 2.00 now has a handle based API. This allows it to be used in multi-
threaded programs. In fact, one process can open any number of com ports
using GIO 2.00. The down side to a handle based API is the fact that the
entire API changed! The 'com port handle' must be passed to every function,
so each call has changed.
GIO 2.00 now does named pipes. You can tell GIO to act as a named pipe
server, or named pipe client. It will do this almost transparently to your
program, so you can use the same logic in your com program for operating on
com ports, and named pipes. You just change the com port name, and a flag
when opening the port.
GIO 2.00 also has several new functions. More on those in the following
documentation. GIO's timers are now based on thousandths of a second rather
than hundredths of a second.
!!!!! SHAREWARE !!!!!
GIO 2.00 is distributed under the shareware concept! You are highly
encouraged to copy and share GIO with others as long as it is copied
in its entirety with no changes!
If you use GIO in your program(s) please send $25 to the address below!
(see REGISTER.DOC)
Your help will ensure future versions of GIO.
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
1718 Woodhaven Ln.
Sparks, NV 89434-0731
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 GIO2.DLL to your \OS2\DLL directory. Put GIO2.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 open a named pipe, remember that named pipe filenames
ALWAYS begin with \PIPE\ A valid pipe name would be: \PIPE\MyPipeName
And then set the appropriate flag when calling ComOpen, either
ISPIPESERVER or ISPIPECLIENT. All of the modem based 'Comxxx' functions
will return without processing in named pipe mode. The only exception is
ComGetDCD. ComGetDCD can be used to determine if a client has opened and
connected to the servers named pipe. (nearly the same concept as looking
for 'Data Carrier Detect' with a modem, so I put it in the same function)
Also, ComGetDCD will let you know when the pipe connection has been cut.
GIO 2.01 automagically detects whether a passed file handle is a com device
oe named pipe. Also fixed a thing or two in the docs here.
Link your object files with GIO2.LIB.
See the two example programs for more information.
#include <gio2.h>
APIRET EXPENTRY ComOpen(PSZ PortName, HFILE PassedHandle,
ULONG BPSRate, BYTE Parity,
SHORT DataBits, SHORT StopBits,
ULONG Flags, PHCOMINFO phComInfo)
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
This is the name of the com port you wish to open. It is not required
if you pass a file handle to ComOpen. If you wish to open a named pipe,
PortName must start with \PIPE\ Put your own filename after \PIPE\
PassedHandle (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.
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
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.
ISPIPESERVER -
Tells GIO to use the 'PortName' as the name of a named pipe, and
to create that named pipe.
ISPIPECLIENT -
Tells GIO to treat the 'PortName' as a named pipe, and opens it
with 'DosOpen'.
phComInfo (PHCOMINFO) - output
On return this is the handle of the open com port. It will be used
by every GIO function.
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_PORT_NAME
0xFF00 + 4 COMERR_NO_HCOMINFO
0xFF00 + 5 COMERR_OPENING_PORT
0xFF00 + 6 COMERR_SETTING_BPS_RATE
0xFF00 + 7 COMERR_SETTING_LINE_CONTROL
0xFF00 + 8 COMERR_CARRIER_DROPPED
0xFF00 + 9 COMERR_NO_CHAR_WAITING
0xFF00 + 10 COMERR_TIMED_CHAR_NOT_RECIEVED
REMARKS
ComOpen is used to open a com port, set BPS rate, and line control.
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.x.
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. GIO will use
any name you pass not just 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'.
EXAMPLE CODE
This example shows a simple call to open COM1 at 19200, No Parity,
8 data bits, and 1 stop bit.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComOpen("COM1", 0, 19200, 'N', 8, 1, 0, &hComInfo);
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;
HCOMINFO hComInfo;
ReturnCode = ComOpen("DIGI2", 0, 38400, 'E', 7, 1, 0, &hComInfo);
if (ReturnCode)
{
printf("Error (%lu) opening COM port\n", ReturnCode);
exit (1);
}
#include <gio2.h>
APIRET EXPENTRY ComClose(HCOMINFO hComInfo)
ComClose shuts down a com port opened using ComOpen.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle to the com port you wish to close. If you told 'ComOpen' to
'LEAVEPORTOPEN' then ComClose will simply clean up and exit without
calling DosClose. (calling DosClose usually drops carrier)
RETURNS
Always returns '0'.
REMARKS
ComClose frees the memory used by the GIO, and optionally 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;
HCOMINFO hComInfo;
ReturnCode = ComOpen("COM1", 0, 19200, 'E', 7, 1, 0, &hComInfo);
if (ReturnCode)
{
printf("Error (%lu) opening com port\n", ReturnCode);
exit (1);
}
ComClose(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComSetBPS(HCOMINFO hComInfo, ULONG BPSRate)
ComSetBPS sets the BPS rate for the port just opened using ComOpen.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
BPSRate (ULONG) - input
BPS rate to set the com port at.
RETURNS
Return code.
ComSetBPS returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
0xFF00 + 1 COMERR_PORT_NOT_OPEN
REMARKS
ComSetBPS 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.
Returns without action in named pipe mode.
EXAMPLE CODE
This examples changes the BPS rate to 19200.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComSetBPS(hComInfo, 19200);
if (ReturnCode)
{
printf("Error (%lu) setting BPS rate\n", ReturnCode);
exit (1);
}
#include <gio2.h>
APIRET EXPENTRY ComSetLineControl(HCOMINFO hComInfo, BYTE Parity,
SHORT DataBits, SHORT StopBits)
ComSetLineControl is used to set the Parity, Data Bits, and Stop Bits
of the current open port.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
Returns without action in named pipe mode.
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 <gio2.h>
APIRET EXPENTRY ComSetFlowControl(HCOMINFO hComInfo)
ComSetFlowControl is used to turn on hardware handshaking, and
hardware timeouts.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
Returns without action in named pipe mode.
EXAMPLE CODE
This examples turns on RTS/CTS hardware flow control.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComSetFlowControl(hComInfo);
if (ReturnCode)
{
printf("Error (%lu) setting flow controls\n", ReturnCode);
exit (1);
}
#include <gio2.h>
APIRET EXPENTRY ComSetDTR(HCOMINFO hComInfo, SHORT DTROn)
ComSetDTR is used to turn the DTR signal on and off.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
Returns without action in named pipe mode.
EXAMPLE CODE
This examples drops the DTR line for 3 seconds, then raises it.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComSetDTR(hComInfo, FALSE);
DosSleep(3000);
ReturnCode = ComSetDTR(hComInfo, TRUE);
#include <gio2.h>
BOOL EXPENTRY ComGetDCD(HCOMINFO hComInfo)
ComGetDCD is used to check for a carrier signal, or a Named Pipe connection.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
TRUE if a carrier signal is detected.
FALSE is no carrier signal is detected.
REMARKS
ComGetDCD is usually used to see if a user has dropped the carrier.
I consider ComGetDCD a 'low level' function. Why? Because in the
real world you should first determine the carrier has been dropped,
wait a couple of seconds, and then check again. If the carrier is
not there the second time, then you can safely assume the connection
is gone.
ComGetDCD will also determine whether or not a Named Pipe connection,
or disconnection has taken place! When creating a named pipe server
you might want to loop around a call to ComGetDCD until TRUE, which
happens when somebody connects to your named pipe.
When you lose a named pipe connection, you should call ComDisConnect
to kill the connection (for OS/2) then call ComConnect to again
'listen' for the next connection.
EXAMPLE CODE
This examples checks to see if a carrier is present.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComGetDCD(hComInfo);
if (! ReturnCode)
printf("User has dropped carrier!\n");
#include <gio2.h>
BOOL EXPENTRY ComGetCTS(HCOMINFO hComInfo)
ComReportCTS reports the status of the CTS line.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
Always returns TRUE in named pipe mode.
EXAMPLE CODE
This examples checks to see if it is okay to send characters to our
modem.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComGetCTS(hComInfo);
if (ReturnCode)
printf("It's okay to send chars! The CTS line is high!\n");
#include <gio2.h>
APIRET EXPENTRY ComXONEnable(HCOMINFO hComInfo)
ComXONEnable is used to enable XON/XOFF style flow control.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
Returns without action in named pipe mode.
EXAMPLE CODE
This examples enables XON/XOFF flow control.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComXONEnable(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComXONDisable(HCOMINFO hComInfo)
ComXONDisable is used to disable XON/XOFF flow control.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
Turns off XON/XOFF flow control if it was enabled with ComXONEnable.
Returns without action in named pipe mode.
EXAMPLE CODE
This examples disables XON/XOFF flow control.
APIRET ReturnCode;
HCOMINFO hComInfo
ReturnCode = ComXONDisable(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComGetDCB(HCOMINFO hComInfo, PDCBINFO DCBInfo)
ComGetDCB returns Device Control Block (DCB) information.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
ComGetDCB returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
You can use ComGetDCB 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 ComGetDCB before calling ComSetDCB. The information
returned should be modified by the application then set using
ComSetDCB.
If a general failure is not returned, then valid information will be
in the DCBInfo structure.
Returns without action in named pipe mode.
EXAMPLE CODE
This example uses ComGetDCB to get the current DCB parameters, it
then modifies them and sets the new DCB parameters.
DCBINFO DCBInfo;
APIRET ReturnCode;
HCOMINFO hComInfo;
ComGetDCB(hComInfo, &DCBInfo);
DCBInfo.usWriteTimeout = 1;
DCBInfo.usReadTimeout = 1;
ReturnCode = ComSetDCB(hComInfo, &DCBInfo);
if (! ReturnCode)
printf("We set new write & read timeouts!\n");
#include <gio2.h>
APIRET EXPENTRY ComSetDCB(HCOMINFO hComInfo, PDCBINFO DCBInfo)
ComSetDCB sets new Device Control Block (DCB) information.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
DCBInfo (PDCBINFO) - input
DCBInfo is a pointer to a DCB structure you have allocated and/or
modified.
RETURNS
Return Code.
ComSetDCB returns the following values:
0 No Errors
31 ERROR_GEN_FAILURE
REMARKS
You can use ComSetDCB 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 ComGetDCB before calling ComSetDCB. The information
returned should be modified by the application then set using
ComSetDCB.
If a general failure is not returned, then you may assume that the
device driver changed the information.
Returns without action in named pipe mode.
EXAMPLE CODE
This example uses ComGetDCB to get the current DCB parameters, it
then modifies them and sets the new DCB parameters.
DCBINFO DCBInfo;
APIRET ReturnCode;
HCOMINFO hComInfo;
ComGetDCB(hComInfo, &DCBInfo);
DCBInfo.fbCtlHndShake = MODE_CTS_HANDSHAKE | MODE_DTR_CONTROL;
ReturnCode = ComSetDCB(hComInfo, &DCBInfo);
if (! ReturnCode)
printf("We set new handshake info!\n");
#include <gio2.h>
APIRET EXPENTRY ComTXPurge(HCOMINFO hComInfo)
ComTXPurge is used to flush the output buffers.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 (No Error)
REMARKS
Use ComTXPurge if you wish to delete all data which were to
be transmitted. This function clears the device driver output buffer.
EXAMPLE CODE
The following short example flushes the output buffer.
HCOMINFO hComInfo;
ComTXPurge(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComTXCharImm(HCOMINFO hComInfo, BYTE Char)
ComTXCharImm transmits a byte immediately.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
In named pipe mode, the transmit buffer is purged, and 'Char' is
sent to the transmit buffer.
EXAMPLE CODE
This examples sends a Ctrl-Q (a typical XON character) to the port.
HCOMINFO hComInfo;
APIRET ReturnCode;
BYTE XONChar = 17;
ReturnCode = ComTXCharImm(hComInfo, XONChar);
#include <gio2.h>
ULONG EXPENTRY ComTXChar(HCOMINFO hComInfo, BYTE Char, BOOL CheckCD)
ComTXChar sends one byte to the communications port.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Char (BYTE) - input
This is the byte to be sent to the communications port.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
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;
HCOMINFO hComInfo;
int KeyIn;
do
{
if (kbhit())
{
KeyIn = getch();
ReturnCode = ComTXChar(hComInfo, (BYTE) KeyIn);
}
} while (1);
#include <gio2.h>
APIRET EXPENTRY ComTXString(HCOMINFO hComInfo, PSZ String, BOOL CheckCD)
ComTXString sends a zero-terminated string to the com port.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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 <gio2.h>
APIRET EXPENTRY ComTXBlock(HCOMINFO hComInfo, PBYTE Buffer,
ULONG Size, BOOL CheckCD)
ComTXBlock sends a buffer of a defined length to the com port.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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;
HCOMINFO hComInfo;
BYTE CharBuffer[128];
memset(CharBuffer, 32, 128); // fill buffer with spaces (' ')
ReturnCode = ComTXBlock(hComInfo, CharBuffer, 128, FALSE);
#include <gio2.h>
BOOL EXPENTRY ComTXEmpty(HCOMINFO hComInfo)
ComTXEmpty determines whether or no the transmit buffers are empty.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
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.
HCOMINFO hComInfo;
while (! ComTXEmpty(hComInfo));
exit();
#include <gio2.h>
VOID EXPENTRY ComTXFlush(HCOMINFO hComInfo, ULONG MaxWait)
ComTXFlush waits until the transmit buffer is empty, or MaxWait
milliseconds, whichever comes first.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
MaxWait (ULONG) - input
Maximum amount of milliseconds to wait for the buffer to empty.
RETURNS
None.
REMARKS
EXAMPLE CODE
This example waits for a five second period or until the transmit buffers
are empty before it exits.
HCOMINFO hComInfo;
ComTXFlush(hComInfo, 5000);
return;
#include <gio2.h>
APIRET EXPENTRY ComTXCount(HCOMINFO hComInfo, PUSHORT Bytes)
ComTXCount returns how many bytes are in the transmit buffer.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Bytes (PUSHORT) - output
Bytes is a pointer to a variable which will receive the number
of bytes in the transmit buffer.
RETURNS
0 No Errors
REMARKS
ComTXCount 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. GIO uses a transmit buffer
(though not a ring buffer) which is 8K in size.
EXAMPLE CODE
This example shows how many bytes are in the transmit buffer.
USHORT Bytes;
HCOMINFO hComInfo;
ComTXCount(hComInfo, &Bytes);
printf("The transmit buffer has %u bytes in it\n", Bytes);
#include <gio2.h>
APIRET EXPENTRY ComTXStart(HCOMINFO hComInfo)
ComTXStart causes the com port to behave as if it has received an XON
character.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
ComTXStart can be used to 'unstick' a transmission that appears to be
'stuck'.
EXAMPLE CODE
This example will attempt to restart transmission.
HCOMINFO hComInfo;
ComTXStart(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComTXStop(HCOMINFO hComInfo)
ComTXStop causes the com port to behave as if it has received an XOFF
character.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
ComTXStop can be used to stop any current transmission of characters.
If you call ComTXStop, you may want to issue a ComTXStart at a later
time!
EXAMPLE CODE
This example will attempt to stop transmission, then restart.
HCOMINFO hComInfo;
ComTXStop(hComInfo);
.
.
.
ComTXStart(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComRXPurge(HCOMINFO hComInfo)
ComRXPurge is used to purge the input buffers.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
ComRXPurge can be used to purge all input from the remote user.
EXAMPLE CODE
The following line purges the input buffer.
HCOMINFO hComInfo;
ComRXPurge(hComInfo);
return;
#include <gio2.h>
APIRET EXPENTRY ComRX(HCOMINFO hComInfo, PSHORT Char, ULONG MaxWait,
BOOL JustPeeking, BOOL CheckCD)
ComRX returns the next available char in the input buffer, if any.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Char (PSHORT) - output
The next available character is stored in Char. If no character is
waiting Char will be -1.
MaxWait (ULONG) - input
Maximum time to wait for a character in milliseconds.
JustPeeking (BOOL) - input
Flag to indicate that we should not remove the character from the
buffer.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
RETURNS
0 No Errors
0xFF00 + 11 COMERR_NO_CHAR_WAITING
REMARKS
ComRX is usually accessed thru one of four different macros (defined
in GIO2.H) They are:
ComRXChar(HCOMINFO hComInfo, PSHORT Char, BOOL CheckCD)
ComRXCharTimed(HCOMINFO hComInfo, PSHORT Char, BOOL CheckCD, ULONG Delay)
ComRXPeek(HCOMINFO hComInfo, PSHORT Char, BOOL CheckCD)
ComRXPeekTimed(HCOMINFO hComInfo, PSHORT Char, BOOL CheckCD, ULONG Delay)
If 'ComRXxxxx' returns with a 0 return code a valid character is
contained in Char. Otherwise Char is -1, and a error code is returned.
If the 'JustPeeking' flag is FALSE, then the character is removed from
the buffer.
EXAMPLE CODE
The follow example uses ComRXCharTimed to receive a character within
a five second time period.
HCOMINFO hComInfo;
SHORT CharIn;
APIRET ReturnCode;
ReturnCode = ComRXCharTimed(hComInfo, &CharIn, TRUE, 5000);
#include <gio2.h>
APIRET EXPENTRY ComRXBlock(HCOMINFO hComInfo, PBYTE Buffer, ULONG BufSize,
ULONG MaxDelay, BOOL CheckCD,
PULONG BytesRead)
ComRXBlock returns a block of characters from the input buffer, if any.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Buffer (PBYTE) - output
The address of the buffer which will contain the bytes received.
BufSize (ULONG) - input
Number of bytes to receive.
MaxDelay (ULONG) - input
Maximum time to wait for any SINGLE character in milliseconds.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
BytesRead (PULONG) - input
Pointer to variable which will receive the number of bytes read.
RETURNS
0 No Errors
0xFF00 + 8 COMERR_CARRIER_DROPPED
0xFF00 + 12 COMERR_BLOCK_TIMEOUT
REMARKS
ComRXBlock reads a block of characters from the com port. It will wait
MaxDelay seconds for any one character. In other words, if a delay
between characters is 'MaxDelay' milliseconds, it will return a timeout.
The timeout period begins at the beginning of the call, and/or after
the last byte that was received (if any). In this manner, this function
may wait longer than 'MaxDelay' milliseconds for a block of characters.
EXAMPLE CODE
The follow example uses ComRXBlock to receive a 1024 characters within
a five second time period.
HCOMINFO hComInfo;
UCHAR MyBuffer[1024];
APIRET ReturnCode;
ULONG BytesRead;
ReturnCode = ComRXBlock(hComInfo, MyBuffer, 1024,
5000, TRUE, &BytesRead);
#include <gio2.h>
APIRET EXPENTRY ComRXString(HCOMINFO hComInfo, PBYTE Buffer, ULONG BufSize,
SHORT Terminator, ULONG MaxDelay, BOOL CheckCD)
ComRXString returns a string of characters from the input buffer, if any.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Buffer (PBYTE) - output
The address of the buffer which will contain the bytes received.
BufSize (ULONG) - input
Number of bytes to receive.
Terminator (SHORT) - input
Character which will terminate the input of the string.
MaxDelay (ULONG) - input
Maximum time to wait for any SINGLE character in milliseconds.
CheckCD (BOOL) - input
This determines whether or not the function checks for a valid carrier
signal.
RETURNS
0 No Errors
0xFF00 + 8 COMERR_CARRIER_DROPPED
0xFF00 + 12 COMERR_BLOCK_TIMEOUT
REMARKS
ComRXString reads in a string from the com port. It will end the input
of the string if a character matching 'Terminator' is read. (The
termination character is returned as well). ComRXString will also
timeout after 'MaxDelay' milliseconds. It will also return if 'BufSize'
bytes are read into 'Buffer'.
EXAMPLE CODE
The follow example uses ComRXString to receive a string within
a sixty second time period.
HCOMINFO hComInfo;
UCHAR MyBuffer[1024];
APIRET ReturnCode;
ULONG BytesRead;
ReturnCode = ComRXString(hComInfo, MyBuffer, 200, '\r', 60000, TRUE);
#include <gio2.h>
BOOL EXPENTRY ComRXEmpty(HCOMINFO hComInfo)
ComRXEmpty determines whether or not the receive buffer is empty.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
TRUE is the receive buffers are empty.
FALSE if any bytes remain in the receive buffers.
REMARKS
ComRXEmpty is usually used to determine if any bytes have been received
and are ready for use.
EXAMPLE CODE
This example waits an indefinate period until the receive buffer has
a character in it.
HCOMINFO hComInfo;
while (ComRXEmpty(hComInfo));
.
.
.
#include <gio2.h>
APIRET EXPENTRY ComRXCount(HCOMINFO hComInfo, PUSHORT Bytes)
ComRXCount returns how many bytes are in the receive buffer.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Bytes (PUSHORT) - output
Bytes is a pointer to a variable which will receive the number
of bytes in the receive buffer.
RETURNS
0 No Errors
REMARKS
ComRXCount is used to determine how many bytes have been received.
EXAMPLE CODE
This example shows how many bytes are in the receive buffer.
USHORT Bytes;
HCOMINFO hComInfo;
ComRXCount(hComInfo, &Bytes);
printf("The receive buffer has %u bytes in it\n", Bytes);
#include <gio2.h>
APIRET EXPENTRY ComPause(HCOMINFO hComInfo)
ComPause resets GIO's transmit buffer.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
This function resets GIO's transmit buffer. Nothing more.
EXAMPLE CODE
This code calls ComPause then ComResume.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComPause(hComInfo); // stop input and output threads.
//
// the program might shell out to another com program here.
//
ReturnCode = ComResume(hComInfo); // restart input and output threads.
//
// the program resumes here.
//
#include <gio2.h>
APIRET EXPENTRY ComResume(HCOMINFO hComInfo)
ComResume resets GIO's transmit buffer.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
This function resets GIO's transmit buffer. Nothing more.
EXAMPLE CODE
This code calls ComPause then ComResume.
APIRET ReturnCode;
HCOMINFO hComInfo;
ReturnCode = ComPause(hComInfo); // stop input and output threads.
//
// the program might shell out to another com program here.
//
ReturnCode = ComResume(hComInfo); // restart input and output threads.
//
// the program resumes here.
//
#include <gio2.h>
APIRET EXPENTRY ComGetHandle(HCOMINFO hComInfo, PULONG Handle)
ComGetHandle returns a copy of the com port handle used by GIO.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
Handle (PULONG) - output
Contains the address of the variable which will contain the copy
of file handle used by GIO. This is either an HFILE or HPIPE,
depending on the open method.
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;
HCOMINFO hComInfo;
HFILE ThisIsTheGIOHandle;
ReturnCode = ComGetHandle(hComInfo, (PULONG) &ThisIsTheGIOHandle);
printf("The file handle in use by GIO is %lu\n", ThisIsTheGIOHandle);
#include <gio2.h>
VOID EXPENTRY ComBreak(HCOMINFO hComInfo, BOOL BreakOn)
ComBreak turns a break signal on or off.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
BreakOn (BOOL) - input
Determines whether or not to turn the break signal on or off.
RETURNS
0 No Errors
REMARKS
ComBreak is used to send a break signal.
EXAMPLE CODE
This example will send a break signal for 2 seconds.
HCOMINFO hComInfo;
ComBreak(hComInfo, TRUE);
DosSleep(2000);
ComBreak(hComInfo, FALSE);
#include <gio2.h>
APIRET EXPENTRY ComConnect(HCOMINFO hComInfo)
ComConnect prepares a named pipe for a client.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
ComConnect is used by a named pipe server to put the named pipe
into a listening state. That is, 'listening' for a named pipe
client to open and use the named pipe.
ComConnect is called by ComOpen when the named pipe is first
opened. This means the named pipe is waiting for a connection
just after it is opened.
When the named pipe connection is to be ended on the server side,
you must call ComDisConnect, and then call ComConnect to put the
named pipe back into listening mode.
See DosConnectNPipe for more information.
EXAMPLE CODE
This example will put a named pipe into a listening state.
HCOMINFO hComInfo;
ComConnect(hComInfo);
#include <gio2.h>
APIRET EXPENTRY ComDisConnect(HCOMINFO hComInfo)
ComDisConnect acknowledges that a client has closed the named pipe.
PARAMETERS
hComInfo (HCOMINFO) - input
Handle of the com port.
RETURNS
0 No Errors
REMARKS
ComDisConnect is used by a named pipe server to acknowledge that
the client has closed the named pipe. The server should then call
ComConnect to put the named pipe into listening mode if it wishes
to connect with another client.
ComDisConnect can also be used to force a named pipe closed (even
before the client has closed their end of the pipe). The nearest
equivalent to ComDisConnect in 'modem terms' would be dropping
the DTR to sever the connection.
See DosDisConnectNPipe for more information.
EXAMPLE CODE
This example will put a named pipe into a listening state.
HCOMINFO hComInfo;
ComConnect(hComInfo);