91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-12
  • 語言: C/C++
  • 標簽: MFC??串口類??第三方??

資源簡介

第三方串口類,用于擴展MFC的串口功能,下面是這個類的英文描述: This class can read, write and watch one serial port. It sends messages to its owner when something happends on the port. The class creates a thread for reading and writing so the main program is not blocked.

資源截圖

代碼片段和文件信息

/*
** FILENAME CSerialPort.cpp
**
** PURPOSE This?class?can?read?write?and?watch?one?serial?port.
** It?sends?messages?to?its?owner?when?something?happends?on?the?port
** The?class?creates?a?thread?for?reading?and?writing?so?the?main
** program?is?not?blocked.
**
** CREATION?DATE 15-09-1997
** LAST?MODIFICATION 12-11-1997
**
** AUTHOR Remon?Spekreijse
**
**
*/

#include?“stdafx.h“
#include?“SerialPort.h“

#include?
?
//
//?Constructor
//
CSerialPort::CSerialPort()
{
m_hComm?=?NULL;

//?initialize?overlapped?structure?members?to?zero
m_ov.Offset?=?0;
m_ov.OffsetHigh?=?0;

//?create?events
m_ov.hEvent?=?NULL;
m_hWriteEvent?=?NULL;
m_hShutdownEvent?=?NULL;

m_szWriteBuffer?=?NULL;

m_bThreadAlive?=?FALSE;
m_nWriteSize?=?1;
}

//
//?Delete?dynamic?memory
//
CSerialPort::~CSerialPort()
{
do
{
SetEvent(m_hShutdownEvent);
}?while?(m_bThreadAlive);

if?(m_hComm?!=?NULL)
{
CloseHandle(m_hComm);
m_hComm?=?NULL;
}
//?Close?Handles??
if(m_hShutdownEvent!=NULL)
CloseHandle(?m_hShutdownEvent);?
if(m_ov.hEvent!=NULL)
CloseHandle(?m_ov.hEvent?);?
if(m_hWriteEvent!=NULL)
CloseHandle(?m_hWriteEvent?);?

TRACE(“Thread?ended\n“);

delete?[]?m_szWriteBuffer;
}

//
//?Initialize?the?port.?This?can?be?port?1?to?4.
//
//
//parity:
//??n=none
//??e=even
//??o=odd
//??m=mark
//??s=space
//data:
//??5678
//stop:
//??11.52?
//
BOOL?CSerialPort::InitPort(CWnd*?pPortOwner //?the?owner?(CWnd)?of?the?port?(receives?message)
???UINT??portnr //?portnumber?(1..4)
???UINT??baud //?baudrate
???char??parity //?parity?
???UINT??databits //?databits?
???UINT??stopbits //?stopbits?
???DWORD?dwCommEvents //?EV_RXCHAR?EV_CTS?etc
???UINT??writebuffersize//?size?to?the?writebuffer
???
???DWORD???ReadIntervalTimeout
???DWORD???ReadTotalTimeoutMultiplier
???DWORD???ReadTotalTimeoutConstant
???DWORD???WriteTotalTimeoutMultiplier
???DWORD???WriteTotalTimeoutConstant?)

{
assert(portnr?>?0?&&?portnr? assert(pPortOwner?!=?NULL);

//?if?the?thread?is?alive:?Kill
if?(m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
}?while?(m_bThreadAlive);
TRACE(“Thread?ended\n“);
}

//?create?events
if?(m_ov.hEvent?!=?NULL)
ResetEvent(m_ov.hEvent);
else
m_ov.hEvent?=?CreateEvent(NULL?TRUE?FALSE?NULL);

if?(m_hWriteEvent?!=?NULL)
ResetEvent(m_hWriteEvent);
else
m_hWriteEvent?=?CreateEvent(NULL?TRUE?FALSE?NULL);

if?(m_hShutdownEvent?!=?NULL)
ResetEvent(m_hShutdownEvent);
else
m_hShutdownEvent?=?CreateEvent(NULL?TRUE?FALSE?NULL);

//?initialize?the?event?objects
m_hEventArray[0]?=?m_hShutdownEvent; //?highest?priority
m_hEventArray[1]?=?m_ov.hEvent;
m_hEventArray[2]?=?m_hWriteEvent;

//?initialize?critical?section
InitializeCriticalSection(&m_csCommuni

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????21522??2014-10-02?15:55??SerialPort.cpp
?????文件????????4222??2014-10-02?13:22??SerialPort.h

評論

共有 條評論