Re: Strange serial port error
I attach my serial class:
MySerial.hpp
#if !
defined(AFX_MYSERIAL_H__E367B2BF_8CAD_4EA8_9588_6E907734BBCD__INCLUDED_)
#define
AFX_MYSERIAL_H__E367B2BF_8CAD_4EA8_9588_6E907734BBCD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MySerial.h : header file
//
//Mensajes que emite esta clase
static UINT UWM_MYSERIAL_DATA_READ
= ::RegisterWindowMessage(_T("UWM_MYSERIAL_DATA_READ-{CC871902-
DB13-4330-9E43-C03C6B8CBE45}") ); //!< Message sent at data readed
static UINT UWM_MYSERIAL_DATA_WRITTED
= ::RegisterWindowMessage(_T("UWM_MYSERIAL_DATA_WRITTED-{CC871902-
DB13-4330-9E43-C03C6B8CBE45}") ); //!< Message sent at data writed
static UINT UWM_MYSERIAL_ERROR
= ::RegisterWindowMessage(_T("UWM_MYSERIAL_ERROR-{CC871902-
DB13-4330-9E43-C03C6B8CBE45}") ); //!< Message sent at error
/////////////////////////////////////////////////////////////////////////////
// MySerial thread
/*! \brief Handles serial communication.
*/
class MySerial : public CWinThread
{
DECLARE_DYNCREATE(MySerial)
protected:
DCB dcb; //!< Struct with port configuration
MySerial(); //!< Protected constructor used by dynamic
creation
// Attributes
public:
BOOL opened; //!< Port opened.
BOOL init; //!< Port init.
HANDLE ShutdownEvent;
HANDLE WriteEvent;
HANDLE ReadEvent;
HANDLE ReaderStoped;
HANDLE WriterStoped;
HANDLE hComm;
OVERLAPPED ovReader, ovWriter;
CWinThread* pReaderThread;
HANDLE phReaderThread;
CWnd* notificador; //Main app's window pointer
// Operations
public:
virtual ~MySerial();
void configure( CWnd* w );
BOOL MySerial::openPort( int port );
void MySerial::closePort( WPARAM wparam, LPARAM lparam );
void MySerial::Kill();
BOOL MySerial::isOpen();
BOOL MySerial::isInit();
afx_msg void MySerial::OnWriteData( WPARAM wParam, LPARAM );
//afx_msg void MySerial::OnReadData( WPARAM wParam, LPARAM lParam );
void Stop();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(MySerial)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
virtual BOOL OnIdle(LONG lCount);
virtual int Run();
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(MySerial)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
immediately before the previous line.
#endif // !
defined(AFX_MYSERIAL_H__E367B2BF_8CAD_4EA8_9588_6E907734BBCD__INCLUDED_)