/*
Module : SerialPort.cpp
Purpose: Implementation for an MFC wrapper class for serial ports
Created: PJN / 31-05-1999
History: PJN / 03-06-1999 1. Fixed problem with code using CancelIo which does not exist on 95.
2. Fixed leaks which can occur in sample app when an exception is thrown
PJN / 16-06-1999 1. Fixed a bug whereby CString::ReleaseBuffer was not being called in
CSerialException::GetErrorMessage
PJN / 29-09-1999 1. Fixed a simple copy and paste bug in CSerialPort::SetDTR
PJN / 08-05-2000 1. Fixed an unreferrenced variable in CSerialPort::GetOverlappedResult in VC 6
PJN / 10-12-2000 1. Made class destructor virtual
PJN / 15-01-2001 1. Attach method now also allows you to specify whether the serial port
is being attached to in overlapped mode
2. Removed some ASSERTs which were unnecessary in some of the functions
3. Updated the Read method which uses OVERLAPPED IO to also return the bytes
read. This allows calls to WriteFile with a zeroed overlapped structure (This
is required when dealing with TAPI and serial communications)
4. Now includes copyright message in the source code and documentation.
PJN / 24-03-2001 1. Added a BytesWaiting method
PJN / 04-04-2001 1. Provided an overriden version of BytesWaiting which specifies a timeout
PJN / 23-04-2001 1. Fixed a memory leak in DataWaiting method
PJN / 01-05-2002 1. Fixed a problem in Open method which was failing to initialize the DCB
structure incorrectly, when calling GetState. Thanks to Ben Newson for this fix.
PJN / 29-05-2002 1. Fixed an problem where the GetProcAddress for CancelIO was using the
wrong calling convention
PJN / 07-08-2002 1. Changed the declaration of CSerialPort::WaitEvent to be consistent with the
rest of the methods in CSerialPort which can operate in "OVERLAPPED" mode. A note
about the usage of this: If the method succeeds then the overlapped operation
has completed synchronously and there is no need to do a WaitForSingle/MultipleObjects.
If any other unexpected error occurs then a CSerialException will be thrown. See
the implementation of the CSerialPort::DataWaiting which has been rewritten to use
this new design pattern. Thanks to Serhiy Pavlov for spotting this inconsistency.
PJN / 20-09-2002 1. Addition of an additional ASSERT in the internal _OnCompletion function.
2. Addition of an optional out parameter to the Write method which operates in
overlapped mode. Thanks to Kevin Pinkerton for this addition.
PJN / 10-04-2006 1. Updated copyright details.
2. Addition of a CSERIALPORT_EXT_CLASS and CSERIALPORT_EXT_API macros which makes
the class easier to use in an extension dll.
3. Removed derivation of CSerialPort from CObject as it was not really needed.
4. Fixed a number of level 4 warnings in the sample app.
5. Reworked the overlapped IO methods to expose the LPOVERLAPPED structure to client
code.
6. Updated the documentation to use the same style as the web site.
7. Did a spell check of the HTML documentation.
8. Updated the documentation on possible blocking in Read/Ex function. Thanks to
D Kerrison for reporting this issue.
9. Fixed a minor issue in the sample app when the code is compiled using /Wp64
PJN / 02-06-2006 1. Removed the bOverlapped as a member variable from the class. There was no
real need for this setting, since the SDK functions will perform their own
checking of how overlapped operations should
2. Fixed a bug in GetOverlappedResult where the code incorrectly checking against
the error ERROR_IO_PENDING instead of ERROR_IO_INCOMPLETE. Thanks to Sasho Darmonski
for reporting this bug.
3. Reviewed all TRACE statements for correctness.
PJN / 05-06-2006 1. Fixed an issue with the creation of the internal event object. It was incorrectly
being created as an auto-reset event object instead of a manual reset event object.
Thanks to Sasho Darmonski for reporting this issue.
PJN / 24-06-2006 1. Fixed some typos in the history list. Thanks to Simon Wong for reporting this.
2. Made the class which handles the construction of function pointers at runtime a
member variable of CSerialPort
3. Made AfxThrowSerialPortException part of the CSerialPort class. Thanks to Simon Wong
for reporting this.
4. Removed the unnecessary CSerialException destructor. Thanks to Simon Wong for
reporting this.
5. Fixed a minor error in the TRACE text in CSerialPort::SetDefaultConfig. Again thanks
to Simon Wong for reporting this.
6. Code now uses new C++ style casts rather than old style C casts where necessary.
Again thanks to Simon Wong for reporting this.
7. CSerialException::GetErrorMessage now uses the strsafe functions. This does mean
that the code now requires the Platform SDK if compiled using VC 6.
PJN / 25-06-2006 1. Combined the functionality of the CSerialPortData class into the main CSerialPort class.
2. Renamed AfxThrowSerialPortException to ThrowSerialPortException and made the method
public.
PJN / 05-11-2006 1. Minor update to stdafx.h of sample app to avoid compiler warnings in VC 2005.
2. Reverted the use of the strsafe.h header file. Instead now the code uses the VC 2005
Safe CRT and if this is not available, then we fail back to the standard CRT.
PJN / 25-01-2007 1. Minor update to remove strsafe.h from stdafx.h of the sample app.
2. Updated copyright details.
PJN / 24-12-2007 1. CSerialException::GetErrorMessage now uses the FORMAT_MESSAGE_IGNORE_INSERTS flag. For more information please see Raymond
Chen's blog at http://blogs.msdn.com/oldnewthing/archive/2007/11/28/6564257.aspx. Thanks to Alexey Kuznetsov for reporting this
issue.
2. Simplified the code in CSerialException::GetErrorMessage somewhat.
3. Optimized the CSerialException constructor code.
4. Code now uses newer C++ style casts instead of C style casts.
5. Reviewed and updated all the TRACE logging in the module
6. Replaced all calls to ZeroMemory with memset
PJN / 30-12-2007 1. Updated the sample app to clean compile on VC 2008
2. CSerialException::GetErrorMessage now uses Checked::tcsncpy_s if compiled using VC 2005 or later.
PJN / 18-05-2008 1. Updated copyright details.
2. Changed the actual
- 1
- 2
前往页