00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
#if !defined(AFX_BERNSTEINMSG_H__59CA0FD5_5A85_11D5_8643_0050BAC0C1BE__INCLUDED_)
00044
#define AFX_BERNSTEINMSG_H__59CA0FD5_5A85_11D5_8643_0050BAC0C1BE__INCLUDED_
00045
00046
#if _MSC_VER > 1000
00047
#pragma once
00048
#endif // _MSC_VER > 1000
00049
00050
#include "TraceObject.h"
00051
00056 class CBernsteinMsg :
virtual public CTraceObject
00057 {
00058
public:
00059
00068
CBernsteinMsg(
const char *cCOMPort,
00069
const int nBaudRate,
00070
const int nByteSize,
00071
const int nParity,
00072
const int nStopBits,
00073
bool bAutoStart =
true );
00074
00075
00077
virtual ~CBernsteinMsg();
00078
00083
void SendRS232(
const char * pData,
int nDataLen );
00084
00089
static DWORD WINAPI
ReceiveThread( LPVOID pArgs );
00090
00091
00096
virtual void ReceiveRS232(
const char *pData,
00097
long DataLen );
00098
bool IsOpen(
void )
const;
00099
const std::string & GetLastErrorMsg(
void )
const {
return m_sLastErrorMsg; }
00100
00101
const std::string & GetPort(
void )
const {
return m_sCOMPort; }
00102
void SetPort(
const std::string & sCOMPort ) {
m_sCOMPort = sCOMPort; }
00103
00107
bool IOStart(
void );
00108
00109
protected:
00112
CBernsteinMsg(
void );
00113
00115
void ReceiveCOM();
00116
00120
bool IOStop(
void );
00121
00122
00131
bool InitRS232(
const char *cCOMPort,
00132
const int nBaudRate,
00133
const int nByteSize,
00134
const int nParity,
00135
const int nStopBits);
00136
00137
private:
00138
00142
bool SetComParameter(
void );
00143
00147
bool OpenPort(
void );
00148
00150
void ClosePort(
void );
00151
00153 int m_nLastRS232Error;
00155 OVERLAPPED
m_oOverlappedRead;
00157 OVERLAPPED
m_oOverlappedWrite;
00158
00160 std::string
m_sCOMPort;
00161 std::string m_sLastErrorMsg;
00162
00165 DCB
m_oPortDCB;
00166
00168 HANDLE
m_hCOMPort;
00170 HANDLE
m_hReceiveThreadHandle;
00171
00173 DWORD
m_dwBytesWritten;
00175 DWORD
m_dwBytesRead;
00177 DWORD
m_dwRecThreadID;
00178
00179 };
00180
00181
#endif // !defined(AFX_BERNSTEINMSG_H__59CA0FD5_5A85_11D5_8643_0050BAC0C1BE__INCLUDED_)