⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comportdlg.h

📁   本实例实现在VC下如何编写串口(com port)实例(与串口通信), 对初学者弄懂串口的实现过程是很好的一个实例.以及现实将串口读到的数据记录到一个testlog目录中,以做备份
💻 H
字号:
// ComPortDlg.h : header file
//

#if !defined(AFX_COMPORTDLG_H__6027E439_886B_4358_9307_2144A88D2FEC__INCLUDED_)
#define AFX_COMPORTDLG_H__6027E439_886B_4358_9307_2144A88D2FEC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CComPortDlg dialog

#include "edtlog.h"
#include "Logrecord.h"
//#include "Test.h"


#define MAXBLOCK 4096
#define XON 0x11
#define XOFF 0x13

DWORD WINAPI Fun1Proc(LPVOID lpParameter);

UINT comopenfunc(LPVOID lParam);


class CComPortDlg : public CDialog
{
// Construction
public:
	void thiscomclose();
	CWinThread* pcomopen;
	BOOL testfindstr(char* input, CString output, int itime);
	BOOL starttest;

	BOOL testthread();
	BOOL m_bexpectonetime;     //控制在调用 expectstring function 时, 只在调用的第一次设定开始时间
	BOOL m_bcallexpectstring;   //控制是否调用expectstring function.
	BOOL expectstring(CString expectstring, int itime); //

	BOOL m_bsendonetime;     //控制在调用 testfindstring function时, 只在调用的第一次设定开始时间及Buffer的清除
	BOOL testfindstring(char* input, CString output, int itime);
	CString m_testfindstring;
	BOOL m_bcalltestfindstring;
	int waittime;
	CTime starttime, endtime;

	HANDLE threading1;
	CString m_strtestbuffer;
	BOOL testreadthread();	
	BOOL m_bisonchar;
	BOOL m_bbufferopen;
	CString m_strbuffer;
	CString m_stronchar;
	BOOL getcomportbuffer(CString str);
	CString m_strrecordlog_temp;
	BOOL recordlog(CString str,BOOL lastrecord = 0);
	BOOL recordlog(char buf[], int length);
	void ComClose();
	DWORD SendCom(char* buf, DWORD dwLength);
	BOOL ComOpen();
	BOOL comconfig();
	BOOL m_bConnected;
	char DataBuffer[1024];
	CWinThread* m_pThread;
	CWinThread* m_testreadthread;
	CWinThread* m_testthread;
	LogRecord log;
	int m_nFlowCtrl;
	int m_nStopBits;
	int m_nBaud;
	int m_nParity;
	int m_nDataBits;

	
	
	OVERLAPPED m_osWrite;
	OVERLAPPED m_osRead;
	DWORD ReadCom(char *buf, DWORD dwLength);
	LRESULT OnCom(WPARAM wParam, LPARAM lParam);
	volatile HANDLE m_hPostMsgEvent;
	HANDLE m_hCom;

	CComPortDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CComPortDlg)
	enum { IDD = IDD_COMPORT_DIALOG };
	Cedtlog	m_edtlog;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CComPortDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;
	CString m_strPort;
	

	// Generated message map functions
	//{{AFX_MSG(CComPortDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnbtnOpen();
	afx_msg void OnbtnClosed();
	afx_msg void OnbtnSetting();
	afx_msg void OnbtnShowLog();
	afx_msg void Onbtnlastlog();
	afx_msg void Onbtnsendcommand();
	afx_msg void Onbtngetbuffer();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	
	
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_COMPORTDLG_H__6027E439_886B_4358_9307_2144A88D2FEC__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -