📄 serialcomm.h
字号:
// SerialComm.h
#if !defined(AFX_SERIALCOMM_H__DD9EB934_01DE_11D2_AF83_444553540000__INCLUDED_)
#define AFX_SERIALCOMM_H__DD9EB934_01DE_11D2_AF83_444553540000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "IoController.h"
//////////////////////////////////////////////////////////////////////
// CSerialComm class
//
// Implementation CIoController Interface.
// The function for serial communication.
//
// This software can be offered for free and used as necessary to aid
// in your program developments.
//
// RENESAS TECHNOLOGY CORPORATION, RENESAS SOLUTIONS CORPORATION,
// and related original software developers assume no responsibility
// for any damage or infringement of any third-party's rights, originating
// in the use of the following software.
// Please use this software under the agreement and acceptance of these conditions.
//
// Copyright(C)1998(2003) RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION
// ALL RIGHTS RESERVED
//
//
class CSerialComm : public CIoController
{
// Construction/Destruction.
public: CSerialComm();
public: virtual ~CSerialComm();
// open Comm port.
public: virtual BOOL Open(const CString& strDevice);
// read/write.
public: virtual DWORD Write(const void* pBuffer, DWORD dwBytesToWrite);
public: virtual DWORD Read(void* pBuffer, DWORD dwRequestBytes);
// set timeout.
protected: DWORD m_dwTimeout;
public: BOOL SetTimeout(DWORD dwTimeout);
public: DWORD GetTimeout(void) { return m_dwTimeout; }
// check timeout.
protected: BOOL m_bIsTimeout;
public: BOOL IsTimeout(void) { return m_bIsTimeout; }
// device setting.
public: virtual BOOL SetState(const CIoState* pState);
public: virtual BOOL GetState(CIoState* pState);
protected: BOOL IsSerialStateObject(const CIoState* pState);
// erase buffer, clear error status.
public: virtual int CleanUp(void* pParam = NULL);
// Reception thread.
// Struct for Thread function.
protected: typedef struct _EVENT_PROC_INFO
{
IO_EVENT_PROC pEventProc;
CIoController* pClassInstance;
DWORD dwBytesWaitFor;
void* pParam;
} EVENT_PROC_INFO;
// Thread end flag.
protected: BOOL m_bThreadEndFlg;
// Thread create/delete.
public: virtual BOOL CreateRcvThread(IO_EVENT_PROC pEventProc, void* pParam, DWORD dwBytesWaitFor);
public: virtual BOOL DeleteRcvThread();
// thread main function.
protected: static void CommEventThread(EVENT_PROC_INFO* pProcInfo);
// default event handler.
protected: virtual void OnReceive(void* pParam, DWORD dwErrorFlags);
};
//////////////////////////////////////////////////////////////////////
// CSerialCommState class
//
// The class that becomes SetState of CSerialComm (), GetState () of an argument.
// Save information of communication setting.
//
class CSerialCommState : public CIoState
{
friend class CSerialComm;
// Construction/disappearance
public: CSerialCommState() { Clear(); }
public: virtual ~CSerialCommState() {}
// Information of communication setting
public: DWORD m_dwBaudRate; // baudrate
public: BYTE m_byByteSize; // byte size
public: BYTE m_byParity; // parity
public: BYTE m_byStopBits; // stop bit
// Clear
public: void Clear()
{
CIoState::Clear();
m_dwBaudRate = 0;
m_byByteSize = 0;
m_byParity = 0;
m_byStopBits = 0;
}
};
#endif // !defined(AFX_SERIALCOMM_H__DD9EB934_01DE_11D2_AF83_444553540000__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -