Initial
This commit is contained in:
BIN
commctrl/Debug/commctrl.lib
Normal file
BIN
commctrl/Debug/commctrl.lib
Normal file
Binary file not shown.
BIN
commctrl/Debug/commctrl.obj
Normal file
BIN
commctrl/Debug/commctrl.obj
Normal file
Binary file not shown.
BIN
commctrl/Debug/commctrl.pch
Normal file
BIN
commctrl/Debug/commctrl.pch
Normal file
Binary file not shown.
BIN
commctrl/Debug/dcb.obj
Normal file
BIN
commctrl/Debug/dcb.obj
Normal file
Binary file not shown.
BIN
commctrl/Debug/fmtlines.obj
Normal file
BIN
commctrl/Debug/fmtlines.obj
Normal file
Binary file not shown.
BIN
commctrl/Debug/vc60.idb
Normal file
BIN
commctrl/Debug/vc60.idb
Normal file
Binary file not shown.
BIN
commctrl/Debug/vc60.pdb
Normal file
BIN
commctrl/Debug/vc60.pdb
Normal file
Binary file not shown.
213
commctrl/commctrl.cpp
Normal file
213
commctrl/commctrl.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
#include <commctrl/commctrl.hpp>
|
||||
#include <commctrl/fmtlines.hpp>
|
||||
|
||||
String CommControl::msCOM1="COM1";
|
||||
String CommControl::msCOM2="COM2";
|
||||
String CommControl::msCOM3="COM3";
|
||||
String CommControl::msCOM4="COM4";
|
||||
|
||||
void CommControl::portToString(CommControl::Port port,String &strPort)
|
||||
{
|
||||
if(port==CommControl::PortCOM1)strPort=msCOM1;
|
||||
else if(port==CommControl::PortCOM2)strPort=msCOM2;
|
||||
else if(port==CommControl::PortCOM3)strPort=msCOM3;
|
||||
else strPort=msCOM4;
|
||||
}
|
||||
|
||||
CommControl::Port CommControl::stringToPort(const String &strPort)
|
||||
{
|
||||
if(strPort==msCOM1)return CommControl::PortCOM1;
|
||||
else if(strPort==msCOM2)return CommControl::PortCOM2;
|
||||
else if(strPort==msCOM3)return CommControl::PortCOM3;
|
||||
else return CommControl::PortCOM4;
|
||||
}
|
||||
|
||||
bool CommControl::readFully(GlobalData<BYTE> &dataBytes)
|
||||
{
|
||||
CommStatus commStatus;
|
||||
DWORD bytesRead=0;
|
||||
DWORD byteCount;
|
||||
DWORD bytesToRead;
|
||||
|
||||
if(!isOkay())return false;
|
||||
clearError(commStatus);
|
||||
byteCount=dataBytes.size();
|
||||
if(!byteCount&&!commStatus.bytesInReceiveQueue())return false;
|
||||
if(!byteCount){byteCount=commStatus.bytesInReceiveQueue();dataBytes.size(byteCount);}
|
||||
return readFully(&dataBytes[0],dataBytes.size());
|
||||
}
|
||||
|
||||
bool CommControl::readFully(BYTE *pBuffer,DWORD byteCount)
|
||||
{
|
||||
CommStatus commStatus;
|
||||
DWORD bytesRead=0;
|
||||
DWORD bytesToRead;
|
||||
|
||||
if(!isOkay())return false;
|
||||
clearError(commStatus);
|
||||
if(!byteCount||!pBuffer)return false;
|
||||
while(bytesRead<byteCount)
|
||||
{
|
||||
if(commStatus.bytesInReceiveQueue())
|
||||
{
|
||||
bytesToRead=bytesRead+commStatus.bytesInReceiveQueue()>byteCount?byteCount-bytesRead:commStatus.bytesInReceiveQueue();
|
||||
read(&pBuffer[bytesRead],bytesToRead);
|
||||
bytesRead+=bytesToRead;
|
||||
}
|
||||
if(bytesRead==byteCount)break;
|
||||
::Sleep(25);
|
||||
clearError(commStatus);
|
||||
}
|
||||
showBytes(pBuffer,byteCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommControl::hasData(void)
|
||||
{
|
||||
CommStatus commStatus;
|
||||
clearError(commStatus);
|
||||
return commStatus.bytesInReceiveQueue()?true:false;
|
||||
}
|
||||
|
||||
bool CommControl::clearReceiveQueue(void)
|
||||
{
|
||||
GlobalData<BYTE> rcvBytes;
|
||||
CommStatus commStatus;
|
||||
|
||||
if(!isOkay())return false;
|
||||
::Sleep(1000);
|
||||
clearError(commStatus);
|
||||
if(!commStatus.bytesInReceiveQueue())return true;
|
||||
::OutputDebugString(String(String("Clearing ")+String().fromInt(commStatus.bytesInReceiveQueue())+String(" bytes from receive queue.\n")).str());
|
||||
rcvBytes.size(commStatus.bytesInReceiveQueue());
|
||||
read(&rcvBytes[0],rcvBytes.size());
|
||||
showBytes(rcvBytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommControl::waitEvent(DWORD &eventMask,DWORD timeout)
|
||||
{
|
||||
BOOL result;
|
||||
DWORD lastError;
|
||||
|
||||
eventMask=0;
|
||||
if(!isOkay())return false;
|
||||
mIOEvent.resetEvent();
|
||||
result=::WaitCommEvent((HANDLE)mCommDevice,&eventMask,&mOverlapped.getOverlapped());
|
||||
if(result)return true;
|
||||
lastError=::GetLastError();
|
||||
if(lastError!=ERROR_IO_PENDING)return false;
|
||||
mIOEvent.waitEvent(timeout);
|
||||
if(!mCommDevice.getOverlappedResult(mOverlapped,false))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CommControl::enumerateDevices(Block<Port> &deviceList)
|
||||
{
|
||||
|
||||
deviceList.remove();
|
||||
if(isOkay())return 0;
|
||||
for(Port port=PortCOM1;port<=PortCOM4;((int&)port)++)
|
||||
{
|
||||
if(mCommDevice.open(mStrPorts[port]))
|
||||
{
|
||||
mCommDevice.close();
|
||||
deviceList.insert(&port);
|
||||
}
|
||||
}
|
||||
return deviceList.size();
|
||||
}
|
||||
|
||||
DWORD CommControl::enumerateDevices(Block<String> &deviceList)
|
||||
{
|
||||
deviceList.remove();
|
||||
if(isOkay())return 0;
|
||||
for(Port port=PortCOM1;port<=PortCOM4;((int&)port)++)
|
||||
{
|
||||
if(mCommDevice.open(mStrPorts[port]))
|
||||
{
|
||||
mCommDevice.close();
|
||||
if(PortCOM1==port)deviceList.insert(&String("COM1"));
|
||||
else if(PortCOM2==port)deviceList.insert(&String("COM2"));
|
||||
else if(PortCOM3==port)deviceList.insert(&String("COM3"));
|
||||
else if(PortCOM4==port)deviceList.insert(&String("COM4"));
|
||||
}
|
||||
}
|
||||
return deviceList.size();
|
||||
}
|
||||
|
||||
DWORD CommControl::read(void *pBuffer,int length,DWORD timeout)
|
||||
{
|
||||
BOOL result;
|
||||
DWORD lastError;
|
||||
|
||||
if(!isOkay())return FALSE;
|
||||
mIOEvent.resetEvent();
|
||||
result=mCommDevice.read((BYTE*)pBuffer,length,mOverlapped);
|
||||
if(result)return TRUE;
|
||||
lastError=::GetLastError();
|
||||
if(lastError!=ERROR_IO_PENDING)return FALSE;
|
||||
mIOEvent.waitEvent(TimeOut);
|
||||
if(!mCommDevice.getOverlappedResult(mOverlapped,FALSE))return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CommControl::isOkay(void)const
|
||||
{
|
||||
return mCommDevice.isOkay();
|
||||
}
|
||||
|
||||
bool CommControl::clearError(CommStatus &commStatus)const
|
||||
{
|
||||
DWORD errorMask(0);
|
||||
bool returnCode(false);
|
||||
|
||||
if(!isOkay())return returnCode;
|
||||
returnCode=::ClearCommError((HANDLE)mCommDevice,&errorMask,&commStatus.getCOMSTAT());
|
||||
showError(errorMask);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
bool CommControl::clearError(void)const
|
||||
{
|
||||
DWORD errorMask(0);
|
||||
bool returnCode(false);
|
||||
|
||||
if(!isOkay())return false;
|
||||
returnCode=::ClearCommError((HANDLE)mCommDevice,&errorMask,0);
|
||||
showError(errorMask);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
void CommControl::showError(DWORD errorMask)const
|
||||
{
|
||||
if(errorMask&CE_BREAK)::OutputDebugString("The hardware detected a break condition.\n");
|
||||
if(errorMask&CE_DNS)::OutputDebugString("Windows 95 and Windows 98: A parallel device is not selected.\n");
|
||||
if(errorMask&CE_FRAME)::OutputDebugString("The hardware detected a framing error.\n");
|
||||
if(errorMask&CE_IOE)::OutputDebugString("An I/O error occurred during communications with the device.\n");
|
||||
if(errorMask&CE_MODE)::OutputDebugString("The requested mode is not supported, or the hFile parameter is invalid. If this value is specified, it is the only valid error.\n");
|
||||
if(errorMask&CE_OOP)::OutputDebugString("Windows 95 and Windows 98: A parallel device signaled that it is out of paper.\n");
|
||||
if(errorMask&CE_OVERRUN)::OutputDebugString("A character-buffer overrun has occurred. The next character is lost.\n");
|
||||
if(errorMask&CE_PTO)::OutputDebugString("Windows 95 and Windows 98: A time-out occurred on a parallel device.\n");
|
||||
if(errorMask&CE_RXOVER)::OutputDebugString("An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.\n");
|
||||
if(errorMask&CE_RXPARITY)::OutputDebugString("The hardware detected a parity error.\n");
|
||||
if(errorMask&CE_TXFULL)::OutputDebugString("The application tried to transmit a character, but the output buffer was full.\n");
|
||||
}
|
||||
|
||||
void CommControl::showBytes(BYTE *pBuffer,DWORD byteCount)
|
||||
{
|
||||
Block<String> strLines;
|
||||
|
||||
::OutputDebugString("\n");
|
||||
FormatLines::hexasciiLines(strLines,pBuffer,byteCount);
|
||||
for(int index=0;index<strLines.size();index++)
|
||||
{
|
||||
::OutputDebugString(strLines[index].str());
|
||||
::OutputDebugString("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void CommControl::showBytes(GlobalData<BYTE> rcvBytes)
|
||||
{
|
||||
showBytes(&rcvBytes[0],rcvBytes.size());
|
||||
}
|
||||
104
commctrl/commctrl.dsp
Normal file
104
commctrl/commctrl.dsp
Normal file
@@ -0,0 +1,104 @@
|
||||
# Microsoft Developer Studio Project File - Name="commctrl" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=commctrl - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "commctrl.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "commctrl.mak" CFG="commctrl - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "commctrl - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "commctrl - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "commctrl - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "commctrl - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "commctrl___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "commctrl___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "commctrl - Win32 Release"
|
||||
# Name "commctrl - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\commctrl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dcb.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\fmtlines.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
29
commctrl/commctrl.dsw
Normal file
29
commctrl/commctrl.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "commctrl"=.\commctrl.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
232
commctrl/commctrl.hpp
Normal file
232
commctrl/commctrl.hpp
Normal file
@@ -0,0 +1,232 @@
|
||||
#ifndef _COMMCTRL_COMMCONTROL_HPP_
|
||||
#define _COMMCTRL_COMMCONTROL_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_OPENFILE_HPP_
|
||||
#include <common/openfile.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_GLOBALDATA_HPP_
|
||||
#include <common/gdata.hpp>
|
||||
#endif
|
||||
#ifndef _COMMCTRL_DEVICECONTROLBLOCK_HPP_
|
||||
#include <commctrl/dcb.hpp>
|
||||
#endif
|
||||
#ifndef _COMMCTRL_COMMSTATUS_HPP_
|
||||
#include <commctrl/commstat.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_EVENT_HPP_
|
||||
#include <thread/event.hpp>
|
||||
#endif
|
||||
|
||||
class CommControl
|
||||
{
|
||||
public:
|
||||
enum {TimeOut=5000};
|
||||
enum Port{PortCOM1,PortCOM2,PortCOM3,PortCOM4};
|
||||
enum EventMask{EventBreak=EV_BREAK,EventCts=EV_CTS,EventDsr=EV_DSR,EventErr=EV_ERR,EventRing=EV_RING,
|
||||
EventRlsd=EV_RLSD,EventRxChar=EV_RXCHAR,EventRxFlag=EV_RXFLAG,EventTxEmpty=EV_TXEMPTY,
|
||||
EventAll=EV_BREAK|EV_CTS|EV_DSR|EV_ERR|EV_RING|EV_RLSD|EV_RXCHAR|EV_RXFLAG|EV_TXEMPTY};
|
||||
CommControl(void);
|
||||
virtual ~CommControl();
|
||||
bool open(Port commPort,BOOL overlappedIO=false);
|
||||
void close();
|
||||
bool getDeviceControlBlock(DeviceControlBlock &deviceControlBlock)const;
|
||||
bool setDeviceControlBlock(const DeviceControlBlock &deviceControlBlock)const;
|
||||
bool setDeviceControlBlock(String strControlBlock)const; // (ie) "baud=1200 parity=N data=8 stop=1"
|
||||
DWORD readLine(String &strLine);
|
||||
DWORD writeLine(const String &strLine)const;
|
||||
DWORD read(void *pBuffer,int length,DWORD timeout=0L);
|
||||
DWORD write(BYTE *pBuffer,int length)const;
|
||||
DWORD write(GlobalData<BYTE> &sndBuffer);
|
||||
DWORD enumerateDevices(Block<Port> &deviceList);
|
||||
DWORD enumerateDevices(Block<String> &deviceList);
|
||||
bool clearError(void)const;
|
||||
bool clearError(CommStatus &commStatus)const;
|
||||
bool clearBreak(void)const;
|
||||
bool clearReceiveQueue(void);
|
||||
bool readFully(GlobalData<BYTE> &dataBytes);
|
||||
bool readFully(BYTE *pBuffer,DWORD byteCount);
|
||||
bool setBreak(void)const;
|
||||
bool waitEvent(DWORD &eventMask,DWORD timeout);
|
||||
bool waitEvent(DWORD timeout=TimeOut);
|
||||
bool waitForBreak(DWORD timeout=TimeOut);
|
||||
bool waitForData(DWORD timeout=TimeOut);
|
||||
bool waitForTransmit(DWORD timeout=TimeOut);
|
||||
bool setEventMask(DWORD eventMask)const;
|
||||
bool hasData(void);
|
||||
bool isOkay(void)const;
|
||||
static void portToString(CommControl::Port port,String &strPort);
|
||||
static CommControl::Port stringToPort(const String &strPort);
|
||||
static void showBytes(GlobalData<BYTE> rcvBytes);
|
||||
static void showBytes(BYTE *pBuffer,DWORD byteCount);
|
||||
private:
|
||||
CommControl(const CommControl &someCommControl);
|
||||
CommControl &operator=(const CommControl &someCommControl);
|
||||
void showError(DWORD errorMask)const;
|
||||
|
||||
FileHandle mCommDevice;
|
||||
Block<String> mStrPorts;
|
||||
CommStatus mCommStatus;
|
||||
Event mIOEvent;
|
||||
Overlapped mOverlapped;
|
||||
static String msCOM1;
|
||||
static String msCOM2;
|
||||
static String msCOM3;
|
||||
static String msCOM4;
|
||||
};
|
||||
|
||||
inline
|
||||
CommControl::CommControl(void)
|
||||
{
|
||||
mOverlapped.event((HANDLE)mIOEvent);
|
||||
mStrPorts.insert(&String("\\.\\COM1"));
|
||||
mStrPorts.insert(&String("\\.\\COM2"));
|
||||
mStrPorts.insert(&String("\\.\\COM3"));
|
||||
mStrPorts.insert(&String("\\.\\COM4"));
|
||||
}
|
||||
|
||||
inline
|
||||
CommControl::CommControl(const CommControl &someCommControl)
|
||||
{ // private implementation
|
||||
*this=someCommControl;
|
||||
}
|
||||
|
||||
inline
|
||||
CommControl::~CommControl()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
inline
|
||||
CommControl &CommControl::operator=(const CommControl &/*someCommControl*/)
|
||||
{ // private implementation
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::open(Port commPort,BOOL overlappedIO)
|
||||
{
|
||||
close();
|
||||
mCommDevice.open(mStrPorts[commPort],FileHandle::ReadWrite,FileHandle::ShareNone,FileHandle::Open,(overlappedIO?FileHandle::FlagOverlapped:FileHandle::Normal));
|
||||
return isOkay();
|
||||
}
|
||||
|
||||
inline
|
||||
void CommControl::close(void)
|
||||
{
|
||||
if(!isOkay())return;
|
||||
mCommDevice.close();
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommControl::readLine(String &strLine)
|
||||
{
|
||||
strLine.reserve(1024);
|
||||
if(!isOkay())return FALSE;
|
||||
clearError(mCommStatus);
|
||||
if(!mCommStatus.bytesInReceiveQueue())return FALSE;
|
||||
return mCommDevice.getLine(strLine);
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommControl::writeLine(const String &strLine)const
|
||||
{
|
||||
if(!isOkay()||strLine.isNull())return FALSE;
|
||||
return mCommDevice.writeLine(strLine);
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommControl::write(GlobalData<BYTE> &sndBuffer)
|
||||
{
|
||||
if(!isOkay()||!sndBuffer.size())return 0;
|
||||
return write(&sndBuffer[0],sndBuffer.size());
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommControl::write(BYTE *pBuffer,int length)const
|
||||
{
|
||||
if(!isOkay()||!pBuffer||!length)return 0;
|
||||
return mCommDevice.write(pBuffer,length);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::setBreak(void)const
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
return ::SetCommBreak((HANDLE)mCommDevice);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::clearBreak(void)const
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
return ::ClearCommBreak((HANDLE)mCommDevice);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::getDeviceControlBlock(DeviceControlBlock &deviceControlBlock)const
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
return ::GetCommState((HANDLE)mCommDevice,&((DeviceControlBlock&)deviceControlBlock).getDCB());
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::setDeviceControlBlock(const DeviceControlBlock &deviceControlBlock)const
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
return ::SetCommState((HANDLE)mCommDevice,&((DeviceControlBlock&)deviceControlBlock).getDCB());
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::setDeviceControlBlock(String strControlBlock)const // (ie) "baud=1200 parity=N data=8 stop=1"
|
||||
{
|
||||
DeviceControlBlock deviceControlBlock;
|
||||
if(!::BuildCommDCB(strControlBlock.str(),&((DeviceControlBlock&)deviceControlBlock).getDCB()))return false;
|
||||
return ::SetCommState((HANDLE)mCommDevice,&((DeviceControlBlock&)deviceControlBlock).getDCB());
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::setEventMask(DWORD eventMask)const
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
return ::SetCommMask((HANDLE)mCommDevice,eventMask);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::waitEvent(DWORD timeout)
|
||||
{
|
||||
DWORD eventMask;
|
||||
return waitEvent(eventMask,timeout);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::waitForBreak(DWORD timeout)
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
setEventMask(EventBreak);
|
||||
return waitEvent(timeout);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::waitForData(DWORD timeout)
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
setEventMask(EventRxChar);
|
||||
return waitEvent(timeout);
|
||||
}
|
||||
|
||||
inline
|
||||
bool CommControl::waitForTransmit(DWORD timeout)
|
||||
{
|
||||
if(!isOkay())return false;
|
||||
setEventMask(EventTxEmpty);
|
||||
return waitEvent(timeout);
|
||||
}
|
||||
#endif
|
||||
BIN
commctrl/commctrl.opt
Normal file
BIN
commctrl/commctrl.opt
Normal file
Binary file not shown.
16
commctrl/commctrl.plg
Normal file
16
commctrl/commctrl.plg
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: commctrl - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
commctrl.lib - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
213
commctrl/commstat.hpp
Normal file
213
commctrl/commstat.hpp
Normal file
@@ -0,0 +1,213 @@
|
||||
#ifndef _M68HC11_COMMSTATUS_HPP_
|
||||
#define _M68HC11_COMMSTATUS_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
|
||||
class CommStatus : private _COMSTAT
|
||||
{
|
||||
public:
|
||||
CommStatus(void);
|
||||
CommStatus(const CommStatus &someCommStatus);
|
||||
virtual ~CommStatus();
|
||||
CommStatus &operator=(const CommStatus &someCommStatus);
|
||||
BOOL operator==(const CommStatus &someCommStatus)const;
|
||||
BOOL waitingForCts(void)const;
|
||||
BOOL waitingForDsr(void)const;
|
||||
BOOL waitingForRlsd(void)const;
|
||||
BOOL waitingRcvdXOff(void)const;
|
||||
BOOL waitingSentXOff(void)const;
|
||||
BOOL waitingRcvdEof(void)const;
|
||||
BOOL waitingForTx(void)const;
|
||||
DWORD bytesInReceiveQueue(void)const;
|
||||
DWORD bytesInSendQueue(void)const;
|
||||
_COMSTAT &getCOMSTAT(void);
|
||||
private:
|
||||
void waitingForCts(BOOL waitingForCts);
|
||||
void waitingForDsr(BOOL waitingForDsr);
|
||||
void waitingForRlsd(BOOL waitingForRlsd);
|
||||
void waitingRcvdXOff(BOOL waitingRcvdXOff);
|
||||
void waitingSentXOff(BOOL waitingSentXOff);
|
||||
void waitingRcvdEof(BOOL waitingRcvdEof);
|
||||
void waitingForTx(BOOL waitingForTx);
|
||||
void bytesInReceiveQueue(DWORD bytesInReceiveQueue);
|
||||
void bytesInSendQueue(DWORD bytesInSendQueue);
|
||||
void setZero(void);
|
||||
};
|
||||
|
||||
inline
|
||||
CommStatus::CommStatus(void)
|
||||
{
|
||||
setZero();
|
||||
}
|
||||
|
||||
inline
|
||||
CommStatus::CommStatus(const CommStatus &someCommStatus)
|
||||
{
|
||||
*this=someCommStatus;
|
||||
}
|
||||
|
||||
inline
|
||||
CommStatus::~CommStatus()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
CommStatus &CommStatus::operator=(const CommStatus &someCommStatus)
|
||||
{
|
||||
waitingForCts(someCommStatus.waitingForCts());
|
||||
waitingForDsr(someCommStatus.waitingForDsr());
|
||||
waitingForRlsd(someCommStatus.waitingForRlsd());
|
||||
waitingRcvdXOff(someCommStatus.waitingRcvdXOff());
|
||||
waitingSentXOff(someCommStatus.waitingSentXOff());
|
||||
waitingRcvdEof(someCommStatus.waitingRcvdEof());
|
||||
waitingForTx(someCommStatus.waitingForTx());
|
||||
bytesInReceiveQueue(someCommStatus.bytesInReceiveQueue());
|
||||
bytesInSendQueue(someCommStatus.bytesInSendQueue());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::operator==(const CommStatus &someCommStatus)const
|
||||
{
|
||||
return (waitingForCts()==someCommStatus.waitingForCts()&&
|
||||
waitingForDsr()==someCommStatus.waitingForDsr()&&
|
||||
waitingForRlsd()==someCommStatus.waitingForRlsd()&&
|
||||
waitingRcvdXOff()==someCommStatus.waitingRcvdXOff()&&
|
||||
waitingSentXOff()==someCommStatus.waitingSentXOff()&&
|
||||
waitingRcvdEof()==someCommStatus.waitingRcvdEof()&&
|
||||
waitingForTx()==someCommStatus.waitingForTx()&&
|
||||
bytesInReceiveQueue()==someCommStatus.bytesInReceiveQueue()&&
|
||||
bytesInSendQueue()==someCommStatus.bytesInSendQueue());
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingForCts(void)const
|
||||
{
|
||||
return _COMSTAT::fCtsHold;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingForCts(BOOL waitingForCts)
|
||||
{
|
||||
_COMSTAT::fCtsHold=waitingForCts;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingForDsr(void)const
|
||||
{
|
||||
return _COMSTAT::fDsrHold;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingForDsr(BOOL waitingForDsr)
|
||||
{
|
||||
_COMSTAT::fDsrHold=waitingForDsr;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingForRlsd(void)const
|
||||
{
|
||||
return _COMSTAT::fRlsdHold;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingForRlsd(BOOL waitingForRlsd)
|
||||
{
|
||||
_COMSTAT::fRlsdHold=waitingForRlsd;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingRcvdXOff(void)const
|
||||
{
|
||||
return _COMSTAT::fXoffHold;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingRcvdXOff(BOOL waitingRcvdXOff)
|
||||
{
|
||||
_COMSTAT::fXoffHold=waitingRcvdXOff;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingSentXOff(void)const
|
||||
{
|
||||
return _COMSTAT::fXoffSent;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingSentXOff(BOOL waitingSentXOff)
|
||||
{
|
||||
_COMSTAT::fXoffSent=waitingSentXOff;
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingRcvdEof(void)const
|
||||
{
|
||||
return _COMSTAT::fEof;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingRcvdEof(BOOL waitingRcvdEof)
|
||||
{
|
||||
_COMSTAT::fEof=waitingRcvdEof;
|
||||
|
||||
}
|
||||
|
||||
inline
|
||||
BOOL CommStatus::waitingForTx(void)const
|
||||
{
|
||||
return _COMSTAT::fTxim;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::waitingForTx(BOOL waitingForTx)
|
||||
{
|
||||
_COMSTAT::fTxim=waitingForTx;
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommStatus::bytesInReceiveQueue(void)const
|
||||
{
|
||||
return _COMSTAT::cbInQue;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::bytesInReceiveQueue(DWORD bytesInReceiveQueue)
|
||||
{
|
||||
_COMSTAT::cbInQue=bytesInReceiveQueue;
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD CommStatus::bytesInSendQueue(void)const
|
||||
{
|
||||
return _COMSTAT::cbOutQue;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::bytesInSendQueue(DWORD bytesInSendQueue)
|
||||
{
|
||||
_COMSTAT::cbOutQue=bytesInSendQueue;
|
||||
}
|
||||
|
||||
inline
|
||||
_COMSTAT &CommStatus::getCOMSTAT(void)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
void CommStatus::setZero(void)
|
||||
{
|
||||
_COMSTAT::fCtsHold=0;
|
||||
_COMSTAT::fDsrHold=0;
|
||||
_COMSTAT::fRlsdHold=0;
|
||||
_COMSTAT::fXoffHold=0;
|
||||
_COMSTAT::fXoffSent=0;
|
||||
_COMSTAT::fEof=0;
|
||||
_COMSTAT::fTxim=0;
|
||||
_COMSTAT::fReserved=0;
|
||||
_COMSTAT::cbInQue=0;
|
||||
_COMSTAT::cbOutQue=0;
|
||||
}
|
||||
#endif
|
||||
365
commctrl/dcb.cpp
Normal file
365
commctrl/dcb.cpp
Normal file
@@ -0,0 +1,365 @@
|
||||
#include <commctrl/dcb.hpp>
|
||||
|
||||
DeviceControlBlock::DeviceControlBlock(void)
|
||||
{
|
||||
setZero();
|
||||
}
|
||||
|
||||
DeviceControlBlock::DeviceControlBlock(const DeviceControlBlock &someDeviceControlBlock)
|
||||
{
|
||||
*this=someDeviceControlBlock;
|
||||
}
|
||||
|
||||
DeviceControlBlock::~DeviceControlBlock()
|
||||
{
|
||||
}
|
||||
|
||||
DeviceControlBlock &DeviceControlBlock::operator=(const DeviceControlBlock &someDeviceControlBlock)
|
||||
{
|
||||
baudRate(someDeviceControlBlock.baudRate());
|
||||
binaryEnabled(someDeviceControlBlock.binaryEnabled());
|
||||
enableParity(someDeviceControlBlock.enableParity());
|
||||
ctsFlowControlOutMonitor(someDeviceControlBlock.ctsFlowControlOutMonitor());
|
||||
dsrFlowControlOutMonitor(someDeviceControlBlock.dsrFlowControlOutMonitor());
|
||||
dtrControl(someDeviceControlBlock.dtrControl());
|
||||
dsrSensitivityEnable(someDeviceControlBlock.dsrSensitivityEnable());
|
||||
continueOnXOff(someDeviceControlBlock.continueOnXOff());
|
||||
xonXOffEnableTransmit(someDeviceControlBlock.xonXOffEnableTransmit());
|
||||
xonXOffEnableReceive(someDeviceControlBlock.xonXOffEnableReceive());
|
||||
errorCharEnable(someDeviceControlBlock.errorCharEnable());
|
||||
discardNullEnable(someDeviceControlBlock.discardNullEnable());
|
||||
rtsControl(someDeviceControlBlock.rtsControl());
|
||||
abortOnErrorEnable(someDeviceControlBlock.abortOnErrorEnable());
|
||||
xonLimit(someDeviceControlBlock.xonLimit());
|
||||
xoffLimit(someDeviceControlBlock.xoffLimit());
|
||||
dataBits(someDeviceControlBlock.dataBits());
|
||||
parity(someDeviceControlBlock.parity());
|
||||
stopBits(someDeviceControlBlock.stopBits());
|
||||
xonChar(someDeviceControlBlock.xonChar());
|
||||
xoffChar(someDeviceControlBlock.xoffChar());
|
||||
errorChar(someDeviceControlBlock.errorChar());
|
||||
eofChar(someDeviceControlBlock.eofChar());
|
||||
evtChar(someDeviceControlBlock.evtChar());
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::operator==(const DeviceControlBlock &someDeviceControlBlock)
|
||||
{
|
||||
return(baudRate()==someDeviceControlBlock.baudRate()&&
|
||||
binaryEnabled()==someDeviceControlBlock.binaryEnabled()&&
|
||||
enableParity()==someDeviceControlBlock.enableParity()&&
|
||||
ctsFlowControlOutMonitor()==someDeviceControlBlock.ctsFlowControlOutMonitor()&&
|
||||
dsrFlowControlOutMonitor()==someDeviceControlBlock.dsrFlowControlOutMonitor()&&
|
||||
dtrControl()==someDeviceControlBlock.dtrControl()&&
|
||||
dsrSensitivityEnable()==someDeviceControlBlock.dsrSensitivityEnable()&&
|
||||
continueOnXOff()==someDeviceControlBlock.continueOnXOff()&&
|
||||
xonXOffEnableTransmit()==someDeviceControlBlock.xonXOffEnableTransmit()&&
|
||||
xonXOffEnableReceive()==someDeviceControlBlock.xonXOffEnableReceive()&&
|
||||
errorCharEnable()==someDeviceControlBlock.errorCharEnable()&&
|
||||
discardNullEnable()==someDeviceControlBlock.discardNullEnable()&&
|
||||
rtsControl()==someDeviceControlBlock.rtsControl()&&
|
||||
abortOnErrorEnable()==someDeviceControlBlock.abortOnErrorEnable()&&
|
||||
xonLimit()==someDeviceControlBlock.xonLimit()&&
|
||||
xoffLimit()==someDeviceControlBlock.xoffLimit()&&
|
||||
dataBits()==someDeviceControlBlock.dataBits()&&
|
||||
parity()==someDeviceControlBlock.parity()&&
|
||||
stopBits()==someDeviceControlBlock.stopBits()&&
|
||||
xonChar()==someDeviceControlBlock.xonChar()&&
|
||||
xoffChar()==someDeviceControlBlock.xoffChar()&&
|
||||
errorChar()==someDeviceControlBlock.errorChar()&&
|
||||
eofChar()==someDeviceControlBlock.eofChar()&&
|
||||
evtChar()==someDeviceControlBlock.evtChar());
|
||||
}
|
||||
|
||||
DWORD DeviceControlBlock::baudRate(void)const
|
||||
{
|
||||
return _DCB::BaudRate;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::baudRate(DWORD baudRate)
|
||||
{
|
||||
_DCB::BaudRate=baudRate;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::binaryEnabled(void)const
|
||||
{
|
||||
return _DCB::fBinary;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::binaryEnabled(BOOL binaryEnabled)
|
||||
{
|
||||
_DCB::fBinary=binaryEnabled;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::enableParity(void)const
|
||||
{
|
||||
return _DCB::fParity;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::enableParity(BOOL parity)
|
||||
{
|
||||
_DCB::fParity=parity;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::ctsFlowControlOutMonitor(void)const
|
||||
{
|
||||
return _DCB::fOutxCtsFlow;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::ctsFlowControlOutMonitor(BOOL ctsFlowControlOut)
|
||||
{
|
||||
_DCB::fOutxCtsFlow=ctsFlowControlOut;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::dsrFlowControlOutMonitor(void)const
|
||||
{
|
||||
return _DCB::fOutxDsrFlow;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::dsrFlowControlOutMonitor(BOOL dsrFlowControlOut)
|
||||
{
|
||||
_DCB::fOutxDsrFlow=dsrFlowControlOut;
|
||||
}
|
||||
|
||||
DeviceControlBlock::DtrControl DeviceControlBlock::dtrControl(void)const
|
||||
{
|
||||
return DtrControl(_DCB::fDtrControl);
|
||||
}
|
||||
|
||||
void DeviceControlBlock::dtrControl(DtrControl dtrControl)
|
||||
{
|
||||
_DCB::fDtrControl=(DWORD)dtrControl;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::dsrSensitivityEnable(void)const
|
||||
{
|
||||
return _DCB::fDsrSensitivity;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::dsrSensitivityEnable(BOOL dsrSensitivityEnable)
|
||||
{
|
||||
_DCB::fDsrSensitivity=dsrSensitivityEnable;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::continueOnXOff(void)const
|
||||
{
|
||||
return _DCB::fTXContinueOnXoff;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::continueOnXOff(BOOL continueOnXOff)
|
||||
{
|
||||
_DCB::fTXContinueOnXoff=continueOnXOff;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::xonXOffEnableTransmit(void)const
|
||||
{
|
||||
return _DCB::fOutX;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xonXOffEnableTransmit(BOOL xonXOffEnable)
|
||||
{
|
||||
_DCB::fOutX=xonXOffEnable;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::xonXOffEnableReceive(void)const
|
||||
{
|
||||
return _DCB::fInX;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xonXOffEnableReceive(BOOL xonXOffEnable)
|
||||
{
|
||||
_DCB::fInX=xonXOffEnable;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::errorCharEnable(void)const
|
||||
{
|
||||
return _DCB::fErrorChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::errorCharEnable(BOOL errorCharEnable)
|
||||
{
|
||||
_DCB::fErrorChar=errorCharEnable;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::discardNullEnable(void)const
|
||||
{
|
||||
return _DCB::fNull;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::discardNullEnable(BOOL discardNullEnable)
|
||||
{
|
||||
_DCB::fNull=discardNullEnable;
|
||||
}
|
||||
|
||||
DeviceControlBlock::RtsControl DeviceControlBlock::rtsControl(void)const
|
||||
{
|
||||
return RtsControl(_DCB::fRtsControl);
|
||||
}
|
||||
|
||||
void DeviceControlBlock::rtsControl(RtsControl rtsControl)
|
||||
{
|
||||
_DCB::fRtsControl=(DWORD)rtsControl;
|
||||
}
|
||||
|
||||
BOOL DeviceControlBlock::abortOnErrorEnable(void)const
|
||||
{
|
||||
return _DCB::fAbortOnError;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::abortOnErrorEnable(BOOL abortOnError)
|
||||
{
|
||||
_DCB::fAbortOnError=abortOnError;
|
||||
}
|
||||
|
||||
WORD DeviceControlBlock::xonLimit(void)const
|
||||
{
|
||||
return _DCB::XonLim;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xonLimit(WORD xonLimit)
|
||||
{
|
||||
_DCB::XonLim=xonLimit;
|
||||
}
|
||||
|
||||
WORD DeviceControlBlock::xoffLimit(void)const
|
||||
{
|
||||
return _DCB::XoffLim;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xoffLimit(WORD xoffLimit)
|
||||
{
|
||||
_DCB::XoffLim=xoffLimit;
|
||||
}
|
||||
|
||||
BYTE DeviceControlBlock::dataBits(void)const
|
||||
{
|
||||
return _DCB::ByteSize;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::dataBits(BYTE dataBits)
|
||||
{
|
||||
_DCB::ByteSize=dataBits;
|
||||
}
|
||||
|
||||
DeviceControlBlock::Parity DeviceControlBlock::parity(void)const
|
||||
{
|
||||
return Parity(_DCB::Parity);
|
||||
}
|
||||
|
||||
void DeviceControlBlock::parity(Parity parity)
|
||||
{
|
||||
_DCB::Parity=BYTE(parity);
|
||||
}
|
||||
|
||||
BYTE DeviceControlBlock::stopBits(void)const
|
||||
{
|
||||
return _DCB::StopBits;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::stopBits(BYTE stopBits)
|
||||
{
|
||||
_DCB::StopBits=stopBits;
|
||||
}
|
||||
|
||||
char DeviceControlBlock::xonChar(void)const
|
||||
{
|
||||
return _DCB::XonChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xonChar(char xonChar)
|
||||
{
|
||||
_DCB::XonChar=xonChar;
|
||||
}
|
||||
|
||||
char DeviceControlBlock::xoffChar(void)const
|
||||
{
|
||||
return _DCB::XoffChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::xoffChar(char xoffChar)
|
||||
{
|
||||
_DCB::XoffChar=xoffChar;
|
||||
}
|
||||
|
||||
char DeviceControlBlock::errorChar(void)const
|
||||
{
|
||||
return _DCB::ErrorChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::errorChar(char errorChar)
|
||||
{
|
||||
_DCB::ErrorChar=errorChar;
|
||||
}
|
||||
|
||||
char DeviceControlBlock::eofChar(void)const
|
||||
{
|
||||
return _DCB::EofChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::eofChar(char eofChar)
|
||||
{
|
||||
_DCB::EofChar;
|
||||
}
|
||||
|
||||
char DeviceControlBlock::evtChar(void)const
|
||||
{
|
||||
return _DCB::EvtChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::evtChar(char evtChar)
|
||||
{
|
||||
_DCB::EvtChar=evtChar;
|
||||
}
|
||||
|
||||
void DeviceControlBlock::setZero(void)
|
||||
{
|
||||
::memset(&(_DCB&)*this,0,sizeof(_DCB));
|
||||
_DCB::DCBlength=sizeof(_DCB);
|
||||
}
|
||||
|
||||
String DeviceControlBlock::toString(void)const
|
||||
{
|
||||
String str="DCB:";
|
||||
String crlf="\r\n";
|
||||
str+=String("Baud:")+String().fromInt(baudRate())+crlf;
|
||||
str+=String("Binary enabled: ")+String().fromBool(binaryEnabled())+crlf;
|
||||
str+=String("Parity enabled: ")+String().fromBool(enableParity())+crlf;
|
||||
str+=String("CTS flow control out monitor: ")+String().fromBool(ctsFlowControlOutMonitor())+crlf;
|
||||
str+=String("DSR flow control out monitor: ")+String().fromBool(dsrFlowControlOutMonitor())+crlf;
|
||||
str+=String("DTR control: ");
|
||||
DtrControl dtrControl=this->dtrControl();
|
||||
if(dtrControl==DtrControlDisable)str+="DTR disabled";
|
||||
else if(dtrControl==DtrControlEnable)str+="DTR enabled";
|
||||
else str+="DTR handshake";
|
||||
str+=crlf;
|
||||
str+=String("DSR sensitivity enable: ")+String().fromBool(dsrSensitivityEnable())+crlf;
|
||||
str+=String("Continue on Xoff: ")+String().fromBool(continueOnXOff())+crlf;
|
||||
str+=String("Xon/Xoff enable xmit: ")+String().fromBool(xonXOffEnableTransmit())+crlf;
|
||||
str+=String("Xon/Xoff enable rcv: ")+String().fromBool(xonXOffEnableReceive())+crlf;
|
||||
str+=String("Error char enable: ")+String().fromBool(errorCharEnable())+crlf;
|
||||
str+=String("Discard null enable: ")+String().fromBool(discardNullEnable())+crlf;
|
||||
str+=String("RTS control: ");
|
||||
RtsControl rtsControl=this->rtsControl();
|
||||
if(rtsControl==RtsControlDisable)str+="RTS disabled";
|
||||
else if(rtsControl==RtsControlEnable)str+="RTS enabled";
|
||||
else str+="RTS handshake";
|
||||
str+=crlf;
|
||||
str+=String("Abort on error enable: ")+String().fromBool(abortOnErrorEnable())+crlf;
|
||||
str+=String("Xon limit: ")+String().fromInt(xonLimit())+crlf;
|
||||
str+=String("Xoff limit: ")+String().fromInt(xoffLimit())+crlf;
|
||||
str+=String("Data bits: ")+String().fromInt(dataBits())+crlf;
|
||||
str+=String("Parity: ");
|
||||
Parity parity=this->parity();
|
||||
if(ParityNone==parity)str+="NONE";
|
||||
else if(ParityOdd==parity)str+="ODD";
|
||||
else if(ParityEven==parity)str+="EVEN";
|
||||
else str+="MARK";
|
||||
str+=crlf;
|
||||
str+=String("Stop bits: ")+String().fromInt(stopBits())+crlf;
|
||||
str+=String("Xon char: '")+String(xonChar())+String("'")+crlf;
|
||||
str+=String("Xoff char: '")+String(xoffChar())+String("'")+crlf;
|
||||
str+=String("Error char: '")+String(errorChar())+String("'")+crlf;
|
||||
str+=String("Eof char: '")+String(eofChar())+String("'")+crlf;
|
||||
str+=String("Evt char: '")+String(evtChar())+String("'")+crlf;
|
||||
return str;
|
||||
}
|
||||
83
commctrl/dcb.hpp
Normal file
83
commctrl/dcb.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef _COMMCTRL_DEVICECONTROLBLOCK_HPP_
|
||||
#define _COMMCTRL_DEVICECONTROLBLOCK_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STDLIB_HPP_
|
||||
#include <common/stdlib.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class DeviceControlBlock : private _DCB
|
||||
{
|
||||
public:
|
||||
enum DtrControl{DtrControlDisable=DTR_CONTROL_DISABLE,DtrControlEnable=DTR_CONTROL_ENABLE,DtrControlHandshake=DTR_CONTROL_HANDSHAKE};
|
||||
enum RtsControl{RtsControlDisable=RTS_CONTROL_DISABLE,RtsControlEnable=RTS_CONTROL_ENABLE,RtsControlHandshake=RTS_CONTROL_HANDSHAKE,RtsControlToggle=RTS_CONTROL_TOGGLE};
|
||||
enum Parity{ParityNone,ParityOdd,ParityEven,ParityMark};
|
||||
DeviceControlBlock(void);
|
||||
DeviceControlBlock(const DeviceControlBlock &someDeviceControlBlock);
|
||||
virtual ~DeviceControlBlock();
|
||||
DeviceControlBlock &operator=(const DeviceControlBlock &someDeviceControlBlock);
|
||||
BOOL operator==(const DeviceControlBlock &someDeviceControlBlock);
|
||||
DWORD baudRate(void)const;
|
||||
void baudRate(DWORD baudRate);
|
||||
BOOL binaryEnabled(void)const;
|
||||
void binaryEnabled(BOOL binaryEnabled);
|
||||
BOOL enableParity(void)const;
|
||||
void enableParity(BOOL parity);
|
||||
BOOL ctsFlowControlOutMonitor(void)const;
|
||||
void ctsFlowControlOutMonitor(BOOL ctsFlowControlOut);
|
||||
BOOL dsrFlowControlOutMonitor(void)const;
|
||||
void dsrFlowControlOutMonitor(BOOL dsrFlowControlOut);
|
||||
DtrControl dtrControl(void)const;
|
||||
void dtrControl(DtrControl dtrControl);
|
||||
BOOL dsrSensitivityEnable(void)const;
|
||||
void dsrSensitivityEnable(BOOL dsrSensitivityEnable);
|
||||
BOOL continueOnXOff(void)const;
|
||||
void continueOnXOff(BOOL continueOnXOff);
|
||||
BOOL xonXOffEnableTransmit(void)const;
|
||||
void xonXOffEnableTransmit(BOOL xonXOffEnable);
|
||||
BOOL xonXOffEnableReceive(void)const;
|
||||
void xonXOffEnableReceive(BOOL xonXOffEnable);
|
||||
BOOL errorCharEnable(void)const;
|
||||
void errorCharEnable(BOOL errorCharEnable);
|
||||
BOOL discardNullEnable(void)const;
|
||||
void discardNullEnable(BOOL discardNullEnable);
|
||||
RtsControl rtsControl(void)const;
|
||||
void rtsControl(RtsControl rtsControl);
|
||||
BOOL abortOnErrorEnable(void)const;
|
||||
void abortOnErrorEnable(BOOL abortOnError);
|
||||
WORD xonLimit(void)const;
|
||||
void xonLimit(WORD xonLimit);
|
||||
WORD xoffLimit(void)const;
|
||||
void xoffLimit(WORD xoffLimit);
|
||||
BYTE dataBits(void)const;
|
||||
void dataBits(BYTE dataBits);
|
||||
Parity parity(void)const;
|
||||
void parity(Parity parity);
|
||||
BYTE stopBits(void)const;
|
||||
void stopBits(BYTE stopBits);
|
||||
char xonChar(void)const;
|
||||
void xonChar(char xonChar);
|
||||
char xoffChar(void)const;
|
||||
void xoffChar(char xoffChar);
|
||||
char errorChar(void)const;
|
||||
void errorChar(char errorChar);
|
||||
char eofChar(void)const;
|
||||
void eofChar(char eofChar);
|
||||
char evtChar(void)const;
|
||||
void evtChar(char evtChar);
|
||||
_DCB &getDCB(void);
|
||||
String toString(void)const;
|
||||
private:
|
||||
void setZero(void);
|
||||
};
|
||||
|
||||
inline
|
||||
_DCB &DeviceControlBlock::getDCB(void)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
120
commctrl/fmtlines.cpp
Normal file
120
commctrl/fmtlines.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include <stdio.h>
|
||||
#include <commctrl/fmtlines.hpp>
|
||||
|
||||
DWORD FormatLines::hexasciiLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData)
|
||||
{
|
||||
return hexasciiLines(lineStrings,&globalData[0],globalData.size());
|
||||
}
|
||||
|
||||
DWORD FormatLines::hexasciiLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount)
|
||||
{
|
||||
Block<String> asciiLines;
|
||||
Block<String> hexLines;
|
||||
String tmpString;
|
||||
DWORD lineCount;
|
||||
|
||||
formatLines(asciiLines,pBuffer,byteCount,HexCharsPerLine,ASCIILine);
|
||||
formatLines(hexLines,pBuffer,byteCount,HexCharsPerLine,HexLine);
|
||||
lineCount=asciiLines.size();
|
||||
for(DWORD itemIndex=0;itemIndex<lineCount;itemIndex++)
|
||||
{
|
||||
tmpString=hexLines[itemIndex]+asciiLines[itemIndex];
|
||||
lineStrings.insert(&tmpString);
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
|
||||
DWORD FormatLines::formatLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD charsPerLine,LineType lineType)
|
||||
{
|
||||
WORD charCount;
|
||||
String charString;
|
||||
String charLine;
|
||||
BYTE charByte;
|
||||
BYTE prevByte;
|
||||
|
||||
if(!byteCount||!pBuffer)return byteCount;
|
||||
charCount=0;
|
||||
for(DWORD itemIndex=0;itemIndex<byteCount;itemIndex++)
|
||||
{
|
||||
charByte=pBuffer[itemIndex];
|
||||
if(itemIndex&&(!(itemIndex%charsPerLine)))
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
*((char*)charLine)=0;
|
||||
charCount=0;
|
||||
}
|
||||
if(HexLine==lineType)::sprintf(charString,"%02x",charByte);
|
||||
else
|
||||
{
|
||||
if(isprint(charByte))::sprintf(charString,"%c",charByte);
|
||||
else charString=".";
|
||||
}
|
||||
charCount++;
|
||||
charLine+=charString;
|
||||
if(HexLine==lineType)charLine+=" ";
|
||||
}
|
||||
while(charCount<charsPerLine)
|
||||
{
|
||||
if(HexLine==lineType)charLine+="?? ";
|
||||
else charLine+="?";
|
||||
charCount++;
|
||||
}
|
||||
if(charLine.length())
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
}
|
||||
return lineStrings.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*DWORD FormatLines::formatLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData,WORD charsPerLine,LineType lineType)
|
||||
{
|
||||
DWORD byteCount(globalData.size());
|
||||
WORD charCount;
|
||||
String charString;
|
||||
String charLine;
|
||||
BYTE charByte;
|
||||
BYTE prevByte;
|
||||
|
||||
if(!byteCount)return byteCount;
|
||||
charCount=0;
|
||||
for(DWORD itemIndex=0;itemIndex<byteCount;itemIndex++)
|
||||
{
|
||||
charByte=globalData[itemIndex];
|
||||
if(itemIndex&&(!(itemIndex%charsPerLine)))
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
*((char*)charLine)=0;
|
||||
charCount=0;
|
||||
}
|
||||
if(HexLine==lineType)::sprintf(charString,"%02x",charByte);
|
||||
else
|
||||
{
|
||||
if(isprint(charByte))::sprintf(charString,"%c",charByte);
|
||||
else charString=".";
|
||||
}
|
||||
charCount++;
|
||||
charLine+=charString;
|
||||
if(HexLine==lineType)charLine+=" ";
|
||||
}
|
||||
while(charCount<charsPerLine)
|
||||
{
|
||||
if(HexLine==lineType)charLine+="?? ";
|
||||
else charLine+="?";
|
||||
charCount++;
|
||||
}
|
||||
if(charLine.length())
|
||||
{
|
||||
if(HexLine==lineType)charLine.upper();
|
||||
lineStrings.insert(&charLine);
|
||||
}
|
||||
return lineStrings.size();
|
||||
}*/
|
||||
60
commctrl/fmtlines.hpp
Normal file
60
commctrl/fmtlines.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef _COMMCTRL_FORMATLINES_HPP_
|
||||
#define _COMMCTRL_FORMATLINES_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_GLOBALDATA_HPP_
|
||||
#include <common/gdata.hpp>
|
||||
#endif
|
||||
|
||||
class FormatLines
|
||||
{
|
||||
public:
|
||||
enum{HexCharsPerLine=0x10,ASCIICharsPerLine=0x20};
|
||||
FormatLines(void);
|
||||
~FormatLines();
|
||||
static DWORD hexLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD hexCharsPerLine=HexCharsPerLine);
|
||||
static DWORD hexLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData,WORD hexCharsPerLine=HexCharsPerLine);
|
||||
static DWORD asciiLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD asciiCharsPerLine=ASCIICharsPerLine);
|
||||
static DWORD asciiLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData,WORD asciiCharsPerLine=ASCIICharsPerLine);
|
||||
static DWORD hexasciiLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount);
|
||||
static DWORD hexasciiLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData);
|
||||
private:
|
||||
enum LineType{HexLine,ASCIILine};
|
||||
static DWORD formatLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD charsPerLine,LineType lineType);
|
||||
};
|
||||
|
||||
inline
|
||||
FormatLines::FormatLines(void)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
FormatLines::~FormatLines()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD FormatLines::hexLines(Block<String> &lineStrings,GlobalData<BYTE> &globalData,WORD hexCharsPerLine)
|
||||
{
|
||||
return formatLines(lineStrings,&globalData[0],globalData.size(),hexCharsPerLine,HexLine);
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD FormatLines::hexLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD hexCharsPerLine)
|
||||
{
|
||||
return formatLines(lineStrings,pBuffer,byteCount,hexCharsPerLine,HexLine);
|
||||
}
|
||||
|
||||
inline
|
||||
DWORD FormatLines::asciiLines(Block<String> &lineStrings,BYTE *pBuffer,DWORD byteCount,WORD asciiCharsPerLine)
|
||||
{
|
||||
return formatLines(lineStrings,pBuffer,byteCount,asciiCharsPerLine,ASCIILine);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user