Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cSerialPort Class Reference

#include <cSerialPort.h>

Inheritance diagram for GrayLib::cSerialPort:
Gray::cOSHandle Gray::cStream Gray::cNonCopyable Gray::cStreamInput Gray::cStreamOutput Gray::cStreamBase Gray::cStreamBase

Public Member Functions

 cSerialPort ()
 
virtual ~cSerialPort ()
 
HRESULT Open (const FILECHAR_t *pszPortName, bool bOverlapped=false)
 
void Close ()
 
void AttachSerial (HANDLE hComm)
 
virtual HRESULT ReadX (void *pData, size_t nDataSize) override
 
virtual HRESULT WriteX (const void *pData, size_t nDataSize) override
 
HRESULT SetTimeouts0 ()
 
 UNITTEST2_PREDEF (cSerialPort)
 
- Public Member Functions inherited from Gray::cOSHandle
 cOSHandle (HANDLE h=INVALID_HANDLE_VALUE) noexcept
 
 cOSHandle (const cOSHandle &Handle) noexcept
 
cOSHandleoperator= (const cOSHandle &Handle)
 
 ~cOSHandle ()
 
 operator HANDLE () const noexcept
 
HANDLE get_Handle () const noexcept
 
HANDLE & ref_Handle () noexcept
 
bool isValidHandle () const noexcept
 
void CloseHandle () noexcept
 
void AttachHandle (HANDLE h) noexcept
 
HANDLE DetachHandle () noexcept
 
HRESULT WriteX (const void *pData, size_t nDataSize) const
 
HRESULT ReadX (void *pData, size_t nDataSize) const
 
HRESULT FlushX () const
 
STREAM_SEEKRET_t Seek (STREAM_OFFSET_t lOffset, SEEK_ORIGIN_TYPE eSeekOrigin) const
 
HRESULT WaitForSingleObject (TIMESYSD_t dwMilliseconds) const
 
- Public Member Functions inherited from Gray::cStream
virtual STREAM_SEEKRET_t Seek (STREAM_OFFSET_t iOffset, SEEK_ORIGIN_TYPE eSeekOrigin=SEEK_Set) override
 Disambiguate Seek for cStreamBase to cStreamInput for stupid compiler. More...
 
virtual STREAM_POS_t GetPosition () const override
 
virtual STREAM_POS_t GetLength () const override
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
- Public Member Functions inherited from Gray::cStreamInput
 cStreamInput () noexcept
 
virtual ~cStreamInput ()
 
virtual size_t SetSeekSizeMin (size_t nSizeMin=k_FILE_BLOCK_SIZE)
 
virtual HRESULT ReadX (OUT void *pData, size_t nDataSize)
 
HRESULT ReadAll (OUT cHeapBlock &block, size_t nSizeExtra=0)
 
virtual HRESULT ReadStringLine (OUT char *pszBuffer, StrLen_t iSizeMax)
 
virtual HRESULT ReadStringLine (OUT wchar_t *pszBuffer, StrLen_t iSizeMax)
 
HRESULT ReadT (OUT void *pVal, size_t nSize)
 
template<typename TYPE >
HRESULT ReadT (OUT TYPE &val)
 
template<typename TYPE >
HRESULT ReadTN (OUT TYPE &val)
 
HRESULT ReadSize (OUT size_t &nSize)
 
template<typename TYPE >
HRESULT ReadSizeT (OUT TYPE &n)
 
HRESULT ReadHashCode (OUT UINT32 &nHashCode)
 
HRESULT ReadHashCode (OUT UINT64 &nHashCode)
 
HRESULT ReadN (OUT BYTE *pBuffer, size_t nSizeMax)
 
template<typename _CH >
HRESULT ReadStringN (OUT _CH *pszStr, StrLen_t iSizeMax)
 
virtual HRESULT ReadPeek (void *pData, size_t nDataSize)
 
- Public Member Functions inherited from Gray::cStreamBase
virtual ~cStreamBase ()
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
- Public Member Functions inherited from Gray::cStreamOutput
 cStreamOutput () noexcept
 
virtual ~cStreamOutput ()
 
HRESULT WriteT (const void *pVal, size_t nDataSize)
 
template<typename TYPE >
HRESULT WriteT (TYPE val)
 
HRESULT WriteSize (size_t nSize)
 
HRESULT WriteHashCode (HASHCODE_t nHashCode)
 
HRESULT WriteN (const void *pBuffer, size_t nSize)
 
template<typename _CH >
HRESULT WriteStringN (const _CH *pszStr)
 
template<typename _CH >
HRESULT WriteCharRepeat (_CH nChar, int nCount=1)
 
virtual HRESULT WriteString (const char *pszStr)
 
virtual HRESULT WriteString (const wchar_t *pszStr)
 
StrLen_t VPrintf (const char *pszFormat, va_list args)
 
StrLen_t VPrintf (const wchar_t *pszFormat, va_list args)
 
StrLen_t _cdecl Printf (const char *pszFormat,...)
 
StrLen_t _cdecl Printf (const wchar_t *pszFormat,...)
 
HRESULT WriteStream (cStreamInput &sInp, STREAM_POS_t nSizeMax=k_FILE_BLOCK_SIZE, IStreamProgressCallback *pProgress=nullptr, TIMESYSD_t nTimeout=0)
 Copy cStreamInput to this stream. More...
 
virtual HRESULT FlushX ()
 

Static Public Member Functions

static HRESULT GRAYCALL GetAllSerialPorts (OUT cArrayString< FILECHAR_t > &a)
 
- Static Public Member Functions inherited from Gray::cOSHandle
static bool IsValidHandle (HANDLE h) noexcept
 
static bool CloseHandle (HANDLE h) noexcept
 

Additional Inherited Members

- Public Attributes inherited from Gray::cOSHandle
HANDLE m_h
 
- Static Public Attributes inherited from Gray::cStreamBase
static const BYTE k_SIZE_MASK = 0x80
 Used for WriteSize() More...
 
static const size_t k_FILE_BLOCK_SIZE = (32 * 1024)
 default arbitrary transfer block size. more than this is NOT more efficient. More...
 
- Protected Member Functions inherited from Gray::cOSHandle
void CloseHandleLast () noexcept
 
- Protected Member Functions inherited from Gray::cNonCopyable
 cNonCopyable () noexcept
 Force the use of Factory creation via protected constructor. More...
 
 ~cNonCopyable () noexcept
 

Detailed Description

Similar to CFile but different in some pretty important ways. Assume all COM ports are N81 by default ?

Constructor & Destructor Documentation

◆ cSerialPort()

GrayLib::cSerialPort::cSerialPort ( )

◆ ~cSerialPort()

GrayLib::cSerialPort::~cSerialPort ( )
virtual

Member Function Documentation

◆ AttachSerial()

void GrayLib::cSerialPort::AttachSerial ( HANDLE  hComm)

◆ Close()

void GrayLib::cSerialPort::Close ( void  )

◆ GetAllSerialPorts()

HRESULT GRAYCALL GrayLib::cSerialPort::GetAllSerialPorts ( OUT cArrayString< FILECHAR_t > &  a)
static

Enumerate my serial ports for _WIN32 or linux Maybe we can just allow assumed fake names that might exist?

Returns
number of ports. SetupDi ??

◆ Open()

HRESULT GrayLib::cSerialPort::Open ( const FILECHAR_t pszPortName,
bool  bOverlapped = false 
)

Call CreateFile to open up the COM port

  • bOverlapped = will use cOverlappedIO On Linux a port might be "/dev/ttyUSB1" for FTDI USB serial device. use the command lsusb to see all of the USB devices. On _WIN32 we usually add "\\\\.\\" in from of the name.

◆ ReadX()

HRESULT GrayLib::cSerialPort::ReadX ( void *  pData,
size_t  nDataSize 
)
overridevirtual

◆ SetTimeouts0()

HRESULT GrayLib::cSerialPort::SetTimeouts0 ( )

Clear all timeouts. Non blocking reads and writes. This should be default but it is not !

◆ UNITTEST2_PREDEF()

GrayLib::cSerialPort::UNITTEST2_PREDEF ( cSerialPort  )

◆ WriteX()

HRESULT GrayLib::cSerialPort::WriteX ( const void *  pData,
size_t  nDataSize 
)
overridevirtual

Reimplemented from Gray::cStreamOutput.


The documentation for this class was generated from the following files: