CSerialPort類解析_第1頁(yè)
CSerialPort類解析_第2頁(yè)
CSerialPort類解析_第3頁(yè)
CSerialPort類解析_第4頁(yè)
CSerialPort類解析_第5頁(yè)
已閱讀5頁(yè),還剩35頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、CSerialPort類解析CSerialPort類的功能及成員函數(shù)介紹CSerialPort類是免費(fèi)提供的串口累,Codeguru是一個(gè)非常不錯(cuò)的源代碼網(wǎng)站CSerialPort類支持線連接(非MODEM)的串口編程操作。CSerialPort類是基于多線程的,其工作流程如下:首先設(shè)置好串口參數(shù),再開(kāi)啟串口檢測(cè)工作線程,串口檢測(cè)工作線程檢測(cè)到串口接收到的數(shù)據(jù)、流控制事件或其他串口事件后,就以消息方式通知主程序,激發(fā)消息處理函數(shù)來(lái)進(jìn)行數(shù)據(jù)處理,這是對(duì)接受數(shù)據(jù)而言的,發(fā)送數(shù)據(jù)可直接向串口發(fā)送。CSerialPort類定義的消息如表消息名稱消息號(hào)功能說(shuō)明WM_COMM_BREAK_DETECTED

2、WM_USER+1檢測(cè)到輸入中斷WM_COMM_CTS_DETECTEDWM_USER+2檢測(cè)到CTS(清除發(fā)送)信號(hào)狀態(tài)改變WM_COMM_DSR_DETECTEDWM_USER+3檢測(cè)到DSR(數(shù)據(jù)設(shè)備準(zhǔn)備就緒)信號(hào)狀態(tài)改變WM_COMM_ERR_DETECTEDWM_USER+4發(fā)生線狀態(tài)錯(cuò)誤(包括CE_FRAME,CE_OVERRUN,和CE_RXPARITY)WM_COMM_RING_DETECTEDWM_USER+5檢測(cè)到響鈴指示信號(hào)WM_COMM_RLSD_DETECTEDWM_USER+6檢測(cè)到RLSD(接收線信號(hào))狀態(tài)改變WM_COMM_RXCHARWM_USER+7接收到一

3、個(gè)字符并已放入接受緩沖區(qū)WM_COMM_RXFLAG_DETECTEDWM_USER+8檢測(cè)到接受到字符(該字符已放入接受緩沖區(qū))事件WM_COMM_TXEMPTY_DETECTEDWM_USER+9檢測(cè)到發(fā)送緩沖區(qū)最后一個(gè)字符已經(jīng)被發(fā)送介紹幾個(gè)經(jīng)常用到的函數(shù):1、串口初始化函數(shù)InitPortBOOL CSerialPort:InitPort(CWnd *pPortOwner,    / the owner (CWnd) of the port (receives

4、 message)                            UINT  portnr,        / portnumber (1.4)   &

5、#160;                        UINT  baud,            / baudrate       &

6、#160;                    char  parity,        / parity               &

7、#160;            UINT  databits,        / databits                      

8、60;     UINT  stopbits,        / stopbits                            DWORD 

9、dwCommEvents,    / EV_RXCHAR, EV_CTS etc                            UINT  writebuffersize)    /

10、 size to the writebuffer      assert(portnr > 0 && portnr < 5);     assert(pPortOwner != NULL);      / if the thread is&#

11、160;alive: Kill     if (m_bThreadAlive)              do                      SetEvent

12、(m_hShutdownEvent);                  while (m_bThreadAlive);         TRACE("Thread endedn");         

13、;  / create events     if (m_ov.hEvent != NULL)         ResetEvent(m_ov.hEvent);     m_ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 

14、60;    if (m_hWriteEvent != NULL)         ResetEvent(m_hWriteEvent);     m_hWriteEvent = CreateEvent(NULL, TRUE, FALSE, NULL);      if 

15、(m_hShutdownEvent != NULL)         ResetEvent(m_hShutdownEvent);     m_hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);      / initialize the ev

16、ent objects     m_hEventArray0 = m_hShutdownEvent;    / highest priority     m_hEventArray1 = m_ov.hEvent;     m_hEventArray2 = m_hWriteEvent;   

17、   / initialize critical section     InitializeCriticalSection(&m_csCommunicationSync);      / set buffersize for writing and save the owner     m

18、_pOwner = pPortOwner;      if (m_szWriteBuffer != NULL)         delete  m_szWriteBuffer;     m_szWriteBuffer = new charwritebuffersize;  

19、60;   m_nPortNr = portnr;      m_nWriteBufferSize = writebuffersize;     m_dwCommEvents = dwCommEvents;      BOOL bResult = FALSE;    &

20、#160;char *szPort = new char50;     char *szBaud = new char50;      / now it critical!     EnterCriticalSection(&m_csCommunicationSync);    &

21、#160; / if the port is already opened: close it     if (m_hComm != NULL)              CloseHandle(m_hComm);      &#

22、160;  m_hComm = NULL;           / prepare port strings     sprintf(szPort, "COM%d", portnr);     sprintf(szBaud, "baud=%d par

23、ity=%c data=%d stop=%d", baud, parity, databits, stopbits);      / get a handle to the port     m_hComm = CreateFile(szPort,       

24、0;                / communication port string (COMX)                        

25、0; GENERIC_READ | GENERIC_WRITE,    / read/write types                          0,       &

26、#160;                        / comm devices must be opened with exclusive access          

27、                NULL,                            / no security at

28、tributes                          OPEN_EXISTING,                    /&

29、#160;comm devices must use OPEN_EXISTING                          FILE_FLAG_OVERLAPPED,          

30、60; / Async I/O                          0);                  

31、60;         / template must be 0 for comm devices      if (m_hComm = INVALID_HANDLE_VALUE)              /

32、 port not found         delete  szPort;         delete  szBaud;          return FALSE;     

33、0;     / set the timeout values     m_CommTimeouts.ReadIntervalTimeout = 1000;     m_CommTimeouts.ReadTotalTimeoutMultiplier = 1000;     m_CommTimeouts.ReadTota

34、lTimeoutConstant = 1000;     m_CommTimeouts.WriteTotalTimeoutMultiplier = 1000;     m_CommTimeouts.WriteTotalTimeoutConstant = 1000;      / configure     if

35、0;(SetCommTimeouts(m_hComm, &m_CommTimeouts)              if (SetCommMask(m_hComm, dwCommEvents)                   &

36、#160;  if (GetCommState(m_hComm, &m_dcb)                              m_dcb.fRtsControl = RTS_CONTROL_ENABLE; &

37、#160;      / set RTS bit high!                 if (BuildCommDCB(szBaud, &m_dcb)            

38、                          if (SetCommState(m_hComm, &m_dcb)                &

39、#160;         / normal operation. continue                     else           &#

40、160;             ProcessErrorMessage("SetCommState()");                            &#

41、160;     else                     ProcessErrorMessage("BuildCommDCB()");              

42、0;           else                 ProcessErrorMessage("GetCommState()");             

43、     else             ProcessErrorMessage("SetCommMask()");          else         ProcessErrorMessage(&qu

44、ot;SetCommTimeouts()");      delete  szPort;     delete  szBaud;      / flush the port     PurgeComm(m_hComm, PURGE_RXCLEAR | PURGE_TXC

45、LEAR | PURGE_RXABORT | PURGE_TXABORT);      / release critical section     LeaveCriticalSection(&m_csCommunicationSync);      TRACE("Initialisation for communica

46、tionport %d completed.nUse Startmonitor to communicate.n", portnr);      return TRUE;  這個(gè)函數(shù)是用來(lái)初始化串口的,即設(shè)置串口的通信參數(shù):需要打開(kāi)的串口號(hào)、波特率、奇偶校驗(yàn)方式、數(shù)據(jù)位、停止位,這里還可 以用來(lái)進(jìn)行事件的設(shè)定。如果串口初始化成功,就返回TRUE,若串口被其他設(shè)備占用、不存在或存在其他股占,就返回FALSE,編程者可以在這兒提示串口操作是

47、否成功。如果在當(dāng)前主串口調(diào)用這個(gè)函數(shù),那么pPortOwner可用this指針表示,串口號(hào)在函數(shù)中做了限制,只能用1,2,3和4四個(gè)串口號(hào),而事實(shí)上在編程時(shí)可能用到更多串口號(hào),可以通過(guò)通過(guò)注釋掉本函數(shù)中的“assert(portur>0&&portnr<5)”語(yǔ)句取消對(duì)串口號(hào)的限制。2、啟動(dòng)串口通信監(jiān)測(cè)線程函數(shù)StartMonitoring()串口初始化成功后,就可以調(diào)用BOOL StartMonitoring()來(lái)啟動(dòng)串口檢測(cè)線程,線程啟動(dòng)成功,發(fā)揮TRUEBOOL CSerialPort:StartMonitoring() 

48、0;if (!(m_Thread = AfxBeginThread(CommThread, this) return FALSE; TRACE("Thread startedn"); return TRUE;  3、暫?;蛲V贡O(jiān)測(cè)線程函數(shù)StopMonitoring()該函數(shù)暫?;蛲V勾跈z測(cè),要注意的是,調(diào)用該函數(shù)后,串口資源仍然被占用/ Suspend the comm thread / BO

49、OL CSerialPort:StopMonitoring()       TRACE("Thread suspendedn");      m_Thread->SuspendThread();      return TRUE;  4、關(guān)閉串口函數(shù)ClosePort()該函數(shù)功能是關(guān)閉串口,釋放串口資源,調(diào)用該函數(shù)后,如果要繼續(xù)使

50、用串口,還需要調(diào)用InitPort()函數(shù)5、通過(guò)串口發(fā)送字符/寫串口函數(shù)WriteToPort()該函數(shù)完成寫串口功能,即向串口發(fā)送字符。/ Write a string to the port void CSerialPort:WriteToPort(char *string) assert(m_hComm != 0); memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer); strc

51、py(m_szWriteBuffer, string);  / set event for write SetEvent(m_hWriteEvent);  以上是常用的函數(shù)介紹,熟悉該類的使用后,可以仔細(xì)看看其他函數(shù),對(duì)上面介紹的函數(shù),在對(duì)串口資源的使用上要記住一下三點(diǎn):l 打開(kāi)串口用調(diào)用InitPort()和StartMonitoring();關(guān)閉串口用StopMonitoring()和ClosePort()而且以上函數(shù)的調(diào)用順序不能亂l 通過(guò)串口發(fā)送字符調(diào)用函數(shù)Write

52、ToPort()l 接受串口收到的字符需要自己編寫WM_COMM_RXCHAR消息處理函數(shù),需要手工添加。操作:首先,需要操作一個(gè)串口,所以只需要定義1個(gè)類對(duì)象就可以了,如要操作多個(gè)串口,則要為每個(gè)串口均定一個(gè)類對(duì)象,這可以通過(guò)數(shù)據(jù)方式來(lái)實(shí)現(xiàn),這里定義的類對(duì)象為m_SerialPort,再定義一個(gè)布爾變量m_bSerialPortOpened用來(lái)標(biāo)志串口是否打開(kāi)。在CserialPort類中有多個(gè)串口事件可以響應(yīng),在一般串口編程中,只需要處理WM_COMM_RXCHAR消息就可以了,該類所有的消息均需要人工添加消息處理函數(shù),將處理函數(shù)名定義為OnComm(),首先在SerialPor

53、tTestDlg.h(頭文件)中添加串口字符接受消息WM_COMM_RXCHAR(串口接受緩沖區(qū)內(nèi)有一個(gè)字符)的響應(yīng)函數(shù)聲明:/Generated message map funnctions /AFX_MSG(CSCportTestView) afx_msg long OnComm(WPARAM ch, LPARAM port); /AFX_MSG  然后在,SerilPortTestDlg.cpp文件中進(jìn)行WM_COMM_RXCHAR消息映射BEGIN_MESS

54、AE_MAP(CSerialPortTestDlg, CDialog)s /AFX_MSG_MAP(CSerialPortTestDlg) ON_MESSAGE(WM_COMM_RXCHAR, OnComm) /AFX_MSG_MAP END_MESSAGE_MAP()  接著,在SerialPortTestDlg.cpp文件中加入函數(shù)OnComm()的實(shí)現(xiàn),并在其中完成對(duì)節(jié)誒受到的字符的處理,將接收到的字符顯示在接受編輯框中:long CSerialPortTestDlg:OnComm(WPARAM&#

55、160;ch, LPARAM port)      m_strEditReceiveMsg += ch;     UpdateData(FLASE);/將接收到的字符顯示在接受編輯框中     returne 0;  說(shuō)明:WPARAM、LPARAM類型是多態(tài)數(shù)據(jù)類型,在WIN32中為32位,支持多種數(shù)據(jù)類型,根據(jù)需要自動(dòng)適應(yīng),這樣,程序有很強(qiáng)的適應(yīng)性,再次,我們可以分貝理解為char和integer類型數(shù)據(jù),每當(dāng)串口接受緩沖

56、區(qū)內(nèi)有一個(gè)字符時(shí),就會(huì)產(chǎn)生一個(gè)WM_COMM_RXCHAR消息,除法OnComm()函數(shù),這時(shí)就可以在函數(shù)中進(jìn)行數(shù)據(jù)處理,所以,這個(gè)消息就是整個(gè)程序的源頭。雖然CSerialPort類是一個(gè)非常好的類,但畢竟只是集中了作者一個(gè)人的智慧和經(jīng)驗(yàn),他也有許多缺陷,n 原類只能發(fā)送字符(ASCII文本)不能處理二進(jìn)制發(fā)送(也就是不能發(fā)送0X00)n 該類不能很好的釋放串口n 存在內(nèi)存泄漏可以進(jìn)行如下改進(jìn)改進(jìn)一、ASCII文本和二進(jìn)制數(shù)據(jù)發(fā)送方式兼容CSerialPort類中只有一個(gè)發(fā)送函數(shù)WriteToPort()/ / Write a

57、60;string to the port / void CSerialPort:WriteToPort(char *string)      assert(m_hComm != 0);      memset(m_szWriteBuffer, 0, sizeof(m_szWriteBuffer);     strcpy(m_szWriteBuffer, string

58、);      / set event for write     SetEvent(m_hWriteEvent);  調(diào)用上面的函數(shù)就只能用字符串方式,而c語(yǔ)言中,空字符(NULL,其中ASCII碼值為0,即通常所說(shuō)的十六禁止0x00字符),是串結(jié)束符,當(dāng)檢測(cè)到NULL字符后,就認(rèn)為該字符串結(jié)束了,所以0x00字符以ASCII文本方式是不能從串口發(fā)送出去的,那么解決這一問(wèn)題的方法就是用二進(jìn)制發(fā)送,其實(shí)這里說(shuō)的二進(jìn)制,只不過(guò)是不以我們通常所說(shuō)的“可見(jiàn)”或“

59、能顯示的字符”發(fā)送,比如,要發(fā)如下的一組值:char chSend5=0x33,0x96,0x00,0x31,0xf1;下面來(lái)對(duì)類做一些改進(jìn),解決這個(gè)問(wèn)題,原理就是用字符數(shù)據(jù)來(lái)發(fā)送數(shù)據(jù),并在發(fā)送時(shí)指定其長(zhǎng)度,這樣,數(shù)據(jù)沒(méi)有發(fā)送完,發(fā)送過(guò)程就不會(huì)停止,CSerialPort類是用API函數(shù)編寫的在,只要在WriteFile()函數(shù)中指定其實(shí)際要發(fā)送的長(zhǎng)度,就可以將數(shù)據(jù)全部發(fā)送出去:實(shí)現(xiàn)步驟如下:1、在SerialPort.h文件中為CSerialPort類添加一個(gè)整形public成員變量,:int m_nWriteSize;用于指定發(fā)送字符數(shù)據(jù)的長(zhǎng)度添加三個(gè)發(fā)送函數(shù)h文件:c

60、pp view plaincopy1. #ifndef _SERIALPORT_H_   2. #define _SERIALPORT_H_   3.    4. #define WM_COMM_BREAK_DETECTED        WM_USER+1    / A break was detected

61、 on input.   5. #define WM_COMM_CTS_DETECTED        WM_USER+2    / The CTS (clear-to-send) signal changed state.    6. #define WM_COMM_DSR_DETECTED &#

62、160;      WM_USER+3    / The DSR (data-set-ready) signal changed state.    7. #define WM_COMM_ERR_DETECTED        WM_USER+4    / A

63、 line-status error occurred. Line-status errors are CE_FRAME, CE_OVERRUN, and CE_RXPARITY.    8. #define WM_COMM_RING_DETECTED        WM_USER+5    / A ring

64、 indicator was detected.    9. #define WM_COMM_RLSD_DETECTED        WM_USER+6    / The RLSD (receive-line-signal-detect) signal changed state.    10.

65、#define WM_COMM_RXCHAR                WM_USER+7    / A character was received and placed in the input buffer.    11. #define&

66、#160;WM_COMM_RXFLAG_DETECTED        WM_USER+8    / The event character was received and placed in the input buffer.     12. #define WM_COMM_TXEMPTY_DETECTE

67、D    WM_USER+9    / The last character in the output buffer was sent.     13.    14.    15. class CSerialPort   16.    17. pu

68、blic:   18.     void ClosePort();   19.     void WriteToPort(LPCTSTR string, int n);   20.     void WriteToPort(LPCTSTR string);   21.  

69、0;  void WriteToPort(char *string, int n);   22.     CSerialPort();   23.     virtual        CSerialPort();   24.     BOOL

70、60;       InitPort(CWnd *pPortOwner,    / the owner (CWnd) of the port (receives message)   25.                

71、;          UINT  portnr,        / portnumber (1.4)   26.                    

72、0;     UINT  baud,            / baudrate   27.                        

73、  char  parity,        / parity   28.                          UINT  databits, &

74、#160;      / databits   29.                          UINT  stopbits,        

75、;/ stopbits   30.                          DWORD dwCommEvents,    / EV_RXCHAR, EV_CTS etc   31. 

76、0;                        UINT  writebuffersize);    / size to the writebuffer   32.    33.  &#

77、160;  BOOL        StartMonitoring();   34.     BOOL        RestartMonitoring();   35.     BOOL       

78、0;StopMonitoring();   36.     DWORD        GetWriteBufferSize();   37.     DWORD        GetCommEvents();   38.     

79、DCB            GetDCB();   39.    40.     void        WriteToPort(char *string);   41.     int m_nWriteSi

80、ze;   42.    43. protected:   44.     / protected memberfunctions   45.     void        ProcessErrorMessage(char *ErrorText);   46

81、.     static UINT    CommThread(LPVOID pParam);   47.     static void    ReceiveChar(CSerialPort *port, COMSTAT comstat);   48.     static&#

82、160;void    WriteChar(CSerialPort *port);   49.    50.     / thread   51.     CWinThread            *m_Thread;  

83、60;52.    53.     / synchronisation objects   54.     CRITICAL_SECTION    m_csCommunicationSync;   55.     BOOL         

84、       m_bThreadAlive;   56.    57.     / handles   58.     HANDLE                m_hShutdownEv

85、ent;   59.     HANDLE                m_hComm;   60.     HANDLE              

86、0; m_hWriteEvent;   61.    62.     / Event array.   63.     / One element is used for each event. There are two event handles for 

87、each port.   64.     / A Write event and a receive character event which is located in the overlapped structure (m_ov.hEvent).   65.     / T

88、here is a general shutdown when the port is closed.   66.     HANDLE                m_hEventArray3;   67.    6

89、8.     / structures   69.     OVERLAPPED            m_ov;   70.     COMMTIMEOUTS        m_CommTimeouts;&#

90、160;  71.     DCB                    m_dcb;   72.    73.     / owner window   74.   &

91、#160; CWnd                *m_pOwner;   75.    76.     / misc   77.     UINT        &#

92、160;       m_nPortNr;   78.     char                *m_szWriteBuffer;   79.     DWORD     

93、           m_dwCommEvents;   80.     DWORD                m_nWriteBufferSize;   81. ;   82.  &#

94、160; 83. #endif _SERIALPORT_H_   cpp文件:cpp view plaincopy1. CSerialPort.cpp   2. /*  3.   4. * FILENAME CSerialPort.cpp  5.   6. *  7.   8. * PURPOSE This class can&

95、#160;read, write and watch one serial port.  9.   10. * It sends messages to its owner when something happends on the port  11.   12. * The class creates&#

96、160;a thread for reading and writing so the main  13.   14. * program is not blocked.  15.   16. *  17.   18. * CREATION DATE 15-09-1997  19.   2

97、0. * LAST MODIFICATION 12-11-1997  21.   22. *  23.   24. * AUTHOR Remon Spekreijse  25.   26. *  27.   28. *  29.   30. */   31.    32. 

98、60;  33. #include "stdafx.h"   34.    35. #include "CSerialPort.h"   36.    37. #include <assert.h>   38.    39.    40. /   41. &

99、#160;  42. / Constructor   43.    44. /   45.    46. CSerialPort:CSerialPort()   47.    48.    49.    50.     m_hComm = NULL; 

100、0; 51.    52.    53.     / initialize overlapped structure members to zero   54.    55.     m_ov.Offset = 0;   56.    57. 

101、60;   m_ov.OffsetHigh = 0;   58.    59.    60.     / create events   61.    62.     m_ov.hEvent = NULL;   63.   

102、60;64.     m_hWriteEvent = NULL;   65.    66.     m_hShutdownEvent = NULL;   67.    68.    69.     m_szWriteBuffer = NULL;  &

103、#160;70.    71.    72.     m_bThreadAlive = FALSE;   73.    74.    75.     m_nWriteSize = 0;   76.    77.    78.  &

104、#160; 79.    80. /   81.    82. / Delete dynamic memory   83.    84. /   85.    86. CSerialPort:CSerialPort()   87.    88.    89.

105、   90.     do   91.    92.        93.    94.         SetEvent(m_hShutdownEvent);   95.    96.    

106、60;   97.     while (m_bThreadAlive);   98.    99.    100.     TRACE("Thread endedn");   101.    102.    103.     d

107、elete  m_szWriteBuffer;   104.    105.    106.    107.    108. /   109.    110. / Initialize the port. This can be port 1 to 4. &#

108、160; 111.    112. /   113.    114. BOOL CSerialPort:InitPort(CWnd *pPortOwner, / the owner (CWnd) of the port (receives message)   115.    116.    

109、60;                       UINT  portnr, / portnumber (1.4)   117.    118.          &#

110、160;                 UINT  baud, / baudrate   119.    120.                  

111、0;         char  parity, / parity   121.    122.                           

112、 UINT  databits, / databits   123.    124.                            UINT  stopbits, / st

113、opbits   125.    126.                            DWORD dwCommEvents, / EV_RXCHAR, EV_CTS etc   

114、127.    128.                            UINT  writebuffersize) / size to the writebuffer   129. 

115、0;  130.    131.    132.     assert(portnr > 0 && portnr < 5);   133.    134.     assert(pPortOwner != NULL);   135. 

116、0;  136.    137.     / if the thread is alive: Kill   138.    139.     if (m_bThreadAlive)   140.    141.      

117、0; 142.    143.         do   144.    145.            146.    147.             Se

118、tEvent(m_hShutdownEvent);   148.    149.            150.         while (m_bThreadAlive);   151.    152.       

119、  TRACE("Thread endedn");   153.    154.        155.    156.    157.     / create events   158.    159.   

120、0; if (m_ov.hEvent != NULL)   160.    161.         ResetEvent(m_ov.hEvent);   162.    163.     else   164.    165.   

121、60;     m_ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);   166.    167.    168.     if (m_hWriteEvent != NULL)   169.    170.   

122、;      ResetEvent(m_hWriteEvent);   171.    172.     else   173.    174.         m_hWriteEvent = CreateEvent(NULL, TRUE, FALSE,

123、60;NULL);   175.    176.    177.     if (m_hShutdownEvent != NULL)   178.    179.         ResetEvent(m_hShutdownEvent);   180.  &#

124、160; 181.     else   182.    183.         m_hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);   184.    185.    186.   &

125、#160; / initialize the event objects   187.    188.     m_hEventArray0 = m_hShutdownEvent; / highest priority   189.    190.     m_hEventArray1 =

126、 m_ov.hEvent;   191.    192.     m_hEventArray2 = m_hWriteEvent;   193.    194.    195.     / initialize critical section   196.   

127、; 197.     InitializeCriticalSection(&m_csCommunicationSync);   198.    199.    200.     / set buffersize for writing and save the owner   201.  &

128、#160; 202.     m_pOwner = pPortOwner;   203.    204.    205.     if (m_szWriteBuffer != NULL)   206.    207.        

129、0;delete  m_szWriteBuffer;   208.    209.     m_szWriteBuffer = new charwritebuffersize;   210.    211.    212.     m_nPortNr = portnr;  

130、60;213.    214.    215.     m_nWriteBufferSize = writebuffersize;   216.    217.     m_dwCommEvents = dwCommEvents;   218.    219.    2

131、20.     BOOL bResult = FALSE;   221.    222.     char *szPort = new char50;   223.    224.     char *szBaud = new char50;   225.    226.    227.     / now it critical!   228.    229.

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論