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

📄 mascdriverdlg.cpp

📁 mobitex 网络的终端采用的串口通信程序。目前正在使用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// mascdriverDlg.cpp : implementation file



#include "stdafx.h"
#include "mascdriver.h"
#include "SendInfoDlg.h"
#include "mascdriverDlg.h"
#include "SetupCommPortDlg.h"
#include <math.h>
#include "string.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//CList <CString,int> ;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

extern 	CMascdriverDlg*  pMascDlg;

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message Handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMascdriverDlg dialog

CMascdriverDlg::CMascdriverDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMascdriverDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMascdriverDlg)
	m_CommPortNum = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMascdriverDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMascdriverDlg)
	DDX_Control(pDX, IDC_DBG_EDIT, m_dbg_edit);
	DDX_Control(pDX, IDC_INFO_EDIT, m_msg_edit);
	DDX_Control(pDX, IDC_MY_EDIT, m_masc_edit);
	DDX_Control(pDX, IDC_COMBOX_SENDCOMMAND, m_comboxSendCommand);
	DDX_Control(pDX, IDC_MSCOMM1, m_mscomm);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMascdriverDlg, CDialog)
	//{{AFX_MSG_MAP(CMascdriverDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON14, OnButton14)
	ON_BN_CLICKED(IDC_RADIOINFO, OnRadioinfo)
	ON_BN_CLICKED(IDC_CHANGE_COMMPARA, OnChangeCommpara)
	ON_BN_CLICKED(IDC_BUTTON17, OnChangeCommPara)
	ON_BN_CLICKED(IDC_BUTTON21, OnButton21)
	ON_BN_CLICKED(IDC_BUTTON22, OnButton22)
	ON_BN_CLICKED(IDC_STOP_ROLL, OnStopRoll)
	ON_BN_CLICKED(IDC_ROLL, OnRoll)
	ON_CBN_KILLFOCUS(IDC_COMBOX_SENDCOMMAND, OnKillfocusComboxSendcommand)
	ON_COMMAND(PORT_OPEN_AND_MASC_START, OnOpenAndMascStart)
	ON_COMMAND(PORT_CLOSE, OnClose)
	ON_COMMAND(RECORD_LOG, OnLog)
	ON_CBN_DBLCLK(IDC_COMBOX_SENDCOMMAND, OnDblclkComboxSendcommand)
	ON_COMMAND(MASC_COMMAND, OnCommand)
	ON_COMMAND(SEND_MESSAGE, OnSendMpakMessage)
	ON_WM_CREATE()
	ON_COMMAND(SETUP_COMM_PORT, OnCommPort)
	ON_WM_MOVE()
	ON_LBN_SETFOCUS(IDC_LIST3, OnSetfocusList3)
	ON_LBN_KILLFOCUS(IDC_LIST3, OnKillfocusList3)
	ON_COMMAND(START_ROLL, OnRoll)
	ON_COMMAND(STOP_ROLL, OnStopRoll)
	ON_COMMAND(ID_MENUITEM32795, OnMenuitem32795)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMascdriverDlg message Handlers

BOOL CMascdriverDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// Add "About..." menu item to system menu.
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	// TODO: Add extra initialization here
	iOneTime = 5;
	iMaxTime = 5000;
	iDisconnTime = 0;

	port = 1; //将串口号设置成为 1;之后可以通过设置的方式改变。
	
	
	Roll=TRUE;			//开始时滚动
	
	fBegin=false;		//当时没有发送

	ReadMascFromFile(); //将各种MASC 命令读入到列表框。

	m_shouldSend= 0;
	m_sended = 0;
	m_received = 0;
	inNormalNo = 0;
	m_RecRssi = 0;
	iDisconnTime = 0;
	m_notSended = 0;
	iLocalMAN = 1;

	mascCommandId = 1;
	//  not detect masc head nor detect masc tail
	bMascTailDetect = FALSE;
	bMascHeadDetect	= FALSE; 
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMascdriverDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMascdriverDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		RECT rect;
		GetClientRect(&rect) ;
		m_comboxSendCommand.SetWindowPos(&wndBottom, rect.left, rect.bottom- (rect.bottom-rect.top)/2 , (rect.right-rect.left)/3, (rect.bottom-rect.top)/2, SWP_SHOWWINDOW );
		m_dbg_edit.SetWindowPos(&wndBottom, rect.left+(rect.right-rect.left)/3, rect.bottom- (rect.bottom-rect.top)/2 , (rect.right-rect.left)*2/3, (rect.bottom-rect.top)/2, SWP_SHOWWINDOW );
		m_masc_edit.SetWindowPos(&wndBottom, rect.left, rect.top , rect.right-rect.left, (rect.bottom-rect.top)/4 , SWP_SHOWWINDOW );
		m_msg_edit.SetWindowPos(&wndBottom, rect.left, rect.bottom- 3*(rect.bottom-rect.top)/4 , rect.right-rect.left, (rect.bottom-rect.top)/4, SWP_SHOWWINDOW );
		CDialog::OnPaint();

	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMascdriverDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//初始化串口
void CMascdriverDlg::InitComm() //gg
{
	 
	if(m_mscomm.GetPortOpen())
	 {
		 m_mscomm.SetPortOpen(FALSE);      //  /*打开串口
		 Sleep(3000);                        //硬件延时,因为在关闭串口时需要时间
	 }            
	 m_mscomm.SetSettings("9600,e,7,1");  ///*串口参数设置  ,这种设置是参照MASC协议的
	 
	 m_mscomm.SetInputMode(0);            ///*设置TEXT缓冲区输入方式
	 
	 m_mscomm.SetInputLen(1); 	         //每次读取一个字符
	 
	 m_mscomm.SetRThreshold(1);           ///*每接收一个字符则激发OnComm()事件
	 
	 m_mscomm.SetPortOpen(TRUE); 
	 
	 m_mscomm.SetDTREnable(true);
}

BEGIN_EVENTSINK_MAP(CMascdriverDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMascdriverDlg)
	ON_EVENT(CMascdriverDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMascdriverDlg::OnOnCommMscomm1() //gg
{
	if (m_mscomm.GetCommEvent()==2 )  //事件值为2表示接收缓冲区内有字符
    {
        V1=m_mscomm.GetInput();  //读入字符
		m_V1=(V1).bstrVal; 
		if (*m_V1!=13)           //若读入字符为回车(DEC为13)即表示一帧接收完毕,否则继续读入下一个字符. 
		{
			if (*m_V1=='^')
			{
				inFrame="";
				bMascHeadDetect = TRUE;
			}
			if (bMascHeadDetect == TRUE)
			{
				inFrame=inFrame+m_V1;

				VariantClear(&V1);
				return;
			}
		}
		else
		{
			if (bMascHeadDetect == TRUE)
			{	
				bMascTailDetect = TRUE;
				inFrame	= inFrame+m_V1;      //INFRAME为存放接收到的帧的一个变量.每接收一个字符,在其尾部填加一个字符. 
				MascFrameReceived(inFrame);
				CTime t = CTime::GetCurrentTime();
				CString timeStr;
				timeStr = t.Format( "%Y%m%d %H:%M:%S--" );
				timeStr = timeStr + "modem-->pc";
				timeStr = timeStr + inFrame;
				AddMsgToEdit(m_masc_edit,timeStr);
				CString tmpMsgFileName;
				if(100>=iLocalMAN)
					iLocalMAN=1000+m_mscomm.GetCommPort(); 
				tmpMsgFileName.Format("c:\\%d_MASC_MSG.txt",iLocalMAN);
				LoginFile(tmpMsgFileName,timeStr);
				inFrame="";
				bMascHeadDetect = FALSE;
				bMascTailDetect = FALSE;
				iMascFinshedOnly = 0;
				VariantClear(&V1);
				return;
			}
		}
		// debug msg display
		if ((!bMascHeadDetect)&& (!bMascTailDetect ))
		{
			CString tmpMsgFileName;
			if(100>=iLocalMAN)
					iLocalMAN=1000+m_mscomm.GetCommPort();
			tmpMsgFileName.Format("c:\\%d_DEBUG_MSG.txt",iLocalMAN);

			if (iMascFinshedOnly != 3)
			{
				iMascFinshedOnly++;
				if((*m_V1!=10)&&(*m_V1!=13))
				{
					AddMsgToDbgEdit(m_dbg_edit,strDebugInfo);
					if(bWriteToDbglogFileTimer==TRUE)
					{
						strDebugInfo+=m_V1;
						AddMsgToDbgEdit(m_dbg_edit,strDebugInfo);

						LoginFile(tmpMsgFileName,strDebugInfo);
						bWriteToDbglogFileTimer=FALSE;
						strDebugInfo = "";
					}else
					{
						strDebugInfo+=m_V1;
					}
				}
			}else
			{
				if(bWriteToDbglogFileTimer==TRUE)
					{
						strDebugInfo+=m_V1;
						AddMsgToDbgEdit(m_dbg_edit,strDebugInfo);
						LoginFile(tmpMsgFileName,strDebugInfo);
						bWriteToDbglogFileTimer=FALSE;
						strDebugInfo = "";
					}else
					{
						strDebugInfo+=m_V1;
					}

			}
		}
	}
	VariantClear(&V1);

⌨️ 快捷键说明

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