vtSerialComm Documentation
vtSerialComm is a generic C++ class for serial communications
using the COM port. It is written in Visual C++ 6.0.
To download, click here.
Reference:
vtSerialComm()
~vtSerialComm
Open()
Close()
Read()
ReadOverlapped()
Write()
WriteOverlapped()
BytesRead()
BytesWritten()
GetLastSystemError()
SetXonChar()
SetXoffChar()
SetXonLim()
SetXoffLim()
AbortRead()
AbortWrite()
FlushWriteBuffer()
General Information:
vtSerialComm can handle overlapped I/O for both reading and
writing. This is the reason why both read and write operations
use their own event and overlapped structure. This makes using
system functions like WaitCommEvent difficult, so the author
decided not to support them in the vtSerialComm wrapper class.
However, if you need this functionality, just extend the code
yourself. Apart from that, all basic functionality is supported.
vtSerialComm():
Constructor. Initializes member variables for Xon/Xoff protocol.
Default values are m_cXonChar = 17, m_cXoffChar = 19, m_nXonLim
= 1024, m_nXoffLim = 1024.
~vtSerialComm():
Destructor. Closes all handles used by vtSerialComm.
Open():
Opens and initializes the serial communications port. When
using Xon/Xoff flow control, you must set the Xon/Xoff characters
and limits before calling Open(). The parameters expected
by Open() are those as defined in the Visual C++ help (see
Platform SDK). Use ‘DCB’ for your index search.
For example, the baud rate expects constants like ‘CBR_115200’
as defined in the DCB structure documentation (DCB = device
control block). The communications port is given as a constant
string like “COM1”, or “COM2”, and
so on.
Close():
Closes all handles used by a vtSerialComm object and thus
the serial communications port. When you call any read or
write function after closing the device, an error will occur.
Read():
Reads the specified number of bytes into the given buffer.
Performs a synchroneous read operation (non-overlapped), which
means that this function will return only if the given number
of bytes has been received. For more information see source
code comments. Do not call Read() until any overlapped read
operation is finished.
ReadOverlapped():
Reads the specified number of bytes into the given buffer.
Performs an asynchroneous read operation (overlapped), which
means that this function will return immediately and allow
the actual read operation to be pwrformed in the background
in parallel to other apllication code. For more information
see source code comments.
Write():
Writes the given number of bytes from the provided buffer
to the serial communications port. Returns after all bytes
have been written to the port (synchroneour or non-overlapped
write operation). For more information see source code comments.
WriteOverlapped():
Writes the given number of bytes from the provided buffer
to the serial communications port. Returns immediately and
lets the write operation be performed in the background thus
giving other code time to be executed in parallel (asynchroneour
or overlapped write operation). For more information see source
code comments.
BytesRead():
Returns the number of bytes read from the serial communications
port since the last call to ReadOverlapped() or Read(). Can
be used to check if an overlapped read operation is complete.
BytesWritten():
Returns the number of bytes written to the serial communications
port since the last call to Write() or WriteOverlapped().
Can be used to determine if an overlapped write operation
is complete.
GetLastSystemError():
Returns the last system error that caused a vtSerialComm
function to fail. Can be used to get more detailed information
on why a function failed. The code number returned is a system
error code as documented in the Platform SDK documentation.
SetXonChar():
Sets the Xon character. Must be called before opening the
port unless the default values shall be used.
SetXoffChar():
Sets the Xoff character. Must be called before opening the
port unless the default values shall be used.
SetXonLim():
Sets the Xon limit. Must be called before opening the port
unless the default values shall be used.
SetXoffLim():
Set the Xoff limit. Must be called before opening the port
unless the default values shall be used.
AbortRead():
Terminates all pending overlapped read operations and/or
clears the input buffer. See comments in source file for more
information.
AbortWrite():
Terminates all pending overlapped write operations and/or
clears the output buffer. See comments in source file for
more information.
FlushWriteBuffer():
Empties the transmit buffer. This is a synchroneous function.
All pending write operations will be completed before this
function returns. See comments in source file for more information.
Go to the download page for vtSerialComm
>>
|