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

📄 ttyview.cpp

📁 串口调试程序源代码
💻 CPP
字号:
// TTYView.cpp : implementation of the CTTYView class
//

#include "stdafx.h"
#include "TTY.h"
#include "SickDld.h"
#include "TTYDoc.h"
#include "TTYView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//CString Path="C:\\sick数据\\sick.txt";

/////////////////////////////////////////////////////////////////////////////
// CTTYView

IMPLEMENT_DYNCREATE(CTTYView, CEditView)

BEGIN_MESSAGE_MAP(CTTYView, CEditView)
	//{{AFX_MSG_MAP(CTTYView)
	ON_COMMAND(ID_API_SICk, OnAPISICk)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
	ON_MESSAGE(WM_COMMNOTIFY, OnCommNotify)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTTYView construction/destruction

CTTYView::CTTYView()
{
	// TODO: add construction code here
	count=0;
	//File_Save.Open(Path, CFile::modeCreate | CFile::modeWrite );

}

CTTYView::~CTTYView()
{
    /*if (File_Save.Open(str1, CFile::modeCreate | CFile::modeWrite))
	
	{
		File_Save.Close();
	}*/	

}

BOOL CTTYView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CTTYView drawing

void CTTYView::OnDraw(CDC* pDC)
{
	CTTYDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CTTYView printing

BOOL CTTYView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CTTYView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CTTYView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CTTYView diagnostics

#ifdef _DEBUG
void CTTYView::AssertValid() const
{
	CEditView::AssertValid();
}

void CTTYView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CTTYDoc* CTTYView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTTYDoc)));
	return (CTTYDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTTYView message handlers

LRESULT CTTYView::OnCommNotify(WPARAM wParam, LPARAM lParam)
{
	
	CSickDld sickdlg;
	char buf[MAXBLOCK*200];
	CString str;
	int nLength, nTextLength;
	CTTYDoc* pDoc=GetDocument();
	
	CEdit& edit=GetEditCtrl();
	
	if(!pDoc->m_bConnected || 	(wParam & EV_RXCHAR)!=EV_RXCHAR) // 是否是EV_RXCHAR事件?
	{
		SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
		return 0L;
	}
	
	nLength=pDoc->ReadComm(buf,2196);
	
	if(nLength)
	{
		nTextLength=edit.GetWindowTextLength();
		edit.SetSel(nTextLength,nTextLength); //移动插入光标到正文末尾
		
		for(int i=0;i<nLength;i++)
		{
			
			//switch(buf[i])
			//{
				
			/*case '\r': // 回车
				if(!pDoc->m_bNewLine) 
					break;/*
				
			case '\n': // 换行
				str+="\r\n";
				break;
				
			case '\b': // 退格
				edit.SetSel(-1, 0);
				edit.ReplaceSel(str);
				nTextLength=edit.GetWindowTextLength();
				edit.SetSel(nTextLength-1,nTextLength);
				edit.ReplaceSel(""); //回退一个字符
				str="";
				break;
				
			case '\a': // 振铃 
				MessageBeep((UINT)-1);
				break;*/
				
			//default : 
				str+=buf[i];
			//}
		}
		
		CTTYDoc *m_App = (CTTYDoc *)AfxGetApp();
		
        if(m_App->View_Checked==TRUE)
		
		{
			edit.SetSel(-1, 0);
		    edit.ReplaceSel(str); // 向编辑视图中插入收到的字符
		}
       
		if(m_App->Save_Checked==TRUE)
			
			//if(m_App->SavePath_Checked==TRUE)
	   {

			//CSickDld *m_Sick=(CSickDld *) AfxGetApp();
			count++;
			CString str1;
			str1.Format("C:\\sick数据\\%d",count);
			str1 += ".txt";
			
			File_Save.Open(str1, CFile::modeCreate | CFile::modeWrite );
			File_Save.Write( str, str.GetLength());
			File_Save.Close();

	   }
	}
	
	SetEvent(pDoc->m_hPostMsgEvent); // 允许发送下一个WM_COMMNOTIFY消息
	return 0L;
}

VOID CTTYView::Clear ()
{
    CEdit& edit=GetEditCtrl();
	edit.SetSel(0, -1);
	edit.Clear ();
}


void CTTYView::OnAPISICk() 
{
	// TODO: Add your command handler code here
	CSickDld SDld;
	SDld.DoModal();
}

⌨️ 快捷键说明

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