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

📄 dgdevdialog.cpp

📁 郎顿51开发板上位机代码 帮助你快速开发工控程序
💻 CPP
字号:
// DgDevDialog.cpp : implementation file
//

#include "stdafx.h"
#include "dvp.h"
#include "DgDevDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDgDevDialog dialog


CDgDevDialog::CDgDevDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CDgDevDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDgDevDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDgDevDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDgDevDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDgDevDialog, CDialog)
	//{{AFX_MSG_MAP(CDgDevDialog)
	ON_BN_CLICKED(ID_DG_SET_OK, OnDgSetOk)
	ON_BN_CLICKED(ID_DG_GET_OK, OnDgGetOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDgDevDialog message handlers

void CDgDevDialog::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CDgDevDialog::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CString str;
	CEdit * edt = (CEdit *)this->GetDlgItem(IDC_DG_EDIT);
	edt->SetLimitText(6);//时钟数据为6个字节,因为就6个数码管
	
	//设置数码管
	m_DigDevs = new DigitalDevice(this);
	m_DigDevs->DD_SetBits(6);
	m_DigDevs->DD_SetTextStyle(15,30,2,5);
	m_DigDevs->DD_SetSize(130,50);
	m_DigDevs->SetWindowPos(NULL,20,25,1,100,SWP_NOSIZE);
	m_DigDevs->DD_SetCurrentString("");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
//------------------------处理时钟命令----------------------------------

bool CDgDevDialog::DealCmd(const unsigned char *cmd)
{
	char buf[7];
	int j = 0 ;
	for(int i = 8 ; i > 2 ; i--,j++)
		buf[j] = cmd[i] + '0';
	
	buf[6] = 0;

	CString str = buf;
	m_DigDevs->DD_SetCurrentString(str);//显示时钟

	return true;
}

//得到时钟状态
int CDgDevDialog::GetDgDev()
{
	unsigned char buf[] = {0x08,0x03,0x82,0x00,0x00,0x09};
	buf[4] = MakeVerify(&buf[1] , 3);
	return DvpView->SendData(buf , 6);
}

//设置时钟状态
int CDgDevDialog::SetDgDev(unsigned char * data , int len)
{
	unsigned char buf[] = {0x08,0x08,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09};
	int j  = 6;//数据部分从下标为6的地方开始
	if(len < 0 || len > 6)//时钟的数据不能大于6个字节,因为只有6个数码管
		return 0;

	for(int i = len - 1 ; i >= 0 ; i = i - 2,j++)
	{
		buf[j] = 0x0f & data[i];

		//data中存储的是assci码,要转换成bcd码给下位机
		buf[j] = (0xf0 & (data[i - 1] << 4)) | buf[j];
	}

	buf[9] = MakeVerify(&buf[1] , 8); 
	
	return DvpView->SendData(buf , 11);
}

//响应时钟设置事件
void CDgDevDialog::OnDgSetOk() 
{
	unsigned char buff[6];

	CString str;
	CEdit * edt = (CEdit *)this->GetDlgItem(IDC_DG_EDIT);
	edt->GetWindowText(str);
	char *PStr ;
	PStr = str.GetBuffer(0);
	
	for(int i = 0 ; i < str.GetLength() ; i++)
		buff[i] = PStr[i] - '0';
	
//	m_DigDevs->DD_SetCurrentString(str);
	SetDgDev(buff , str.GetLength());
	// TODO: Add your control notification handler code here
	
}

void CDgDevDialog::OnDgGetOk() 
{
		GetDgDev();
}

⌨️ 快捷键说明

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