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

📄 leddialog.cpp

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

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

#include "LedDialog.h"



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

//extern CDvpView * DvpView;
//#include "dvpView.h"


/////////////////////////////////////////////////////////////////////////////
// CLedDialog dialog


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

}


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


BEGIN_MESSAGE_MAP(CLedDialog, CDialog)
	//{{AFX_MSG_MAP(CLedDialog)
	ON_BN_CLICKED(ID_LED_SET_OK, OnLedSetOk)
	ON_WM_PAINT()
	ON_BN_CLICKED(ID_LED_GET_OK, OnLedGetOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLedDialog message handlers

BOOL CLedDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//设置LED灯的显示
	m_Lamps = new LampArray(this);
	m_Lamps->LA_SetArraySize(1,8);
	m_Lamps->LA_SetLampSpace(13,15);
	m_Lamps->LA_SetTextOffset(0,15);
	m_Lamps->LA_SetLampSize(15,15);
	m_Lamps->LA_SetLampStyle(LA_RECTANGLE);
	m_Lamps->LA_SetBkColor(0X0);
	m_Lamps->LA_SetText(" 1, 2, 3, 4, 5, 6, 7, 8");
	m_Lamps->LA_SetSize(240,40);
	m_Lamps->SetWindowPos(NULL,40,35,1,100,SWP_NOSIZE);
	m_LedData = 0;
	return TRUE;
}

//处理LED命令
bool CLedDialog::DealCmd(const unsigned char * cmd)
{
	unsigned char data = cmd[3];
	unsigned char tmp = 1;
	
	if(cmd[0] < 4)
		return false;

	for(int i = 0 ; i < 8 ; i++)
	{
		if(tmp == (unsigned char)(data & tmp))
		   m_Lamps->LA_SetLampStatus(i , 1);
		else
			m_Lamps->LA_SetLampStatus(i , 0);
		tmp =tmp << 1;
	}
	return true;
} 


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

//响应LED灯设置的事件
void CLedDialog::OnLedSetOk() 
{
	char data = 0;
	char tmp = 1;
	CButton * ChkBox;

	for(int i = 0 ; i < 8 ; i++)
	{
		ChkBox =(CButton * )this->GetDlgItem(IDC_LED_CHECK1 + i);
		if(ChkBox->GetCheck())
			data = data | (tmp << i);	
	}

	SetLed(data);
}

//得到LED灯状态
int CLedDialog::GetLed()
{
	unsigned char buf[] = {0x08,0x03,0x82,0x05,0x00,0x09};
	buf[4] = MakeVerify(&buf[1] , 3);
	return DvpView->SendData(buf , 6);
}
//设置LED灯状态
int CLedDialog::SetLed(unsigned char data)
{
	unsigned char buf[] = {0x08,0x04,0x81,0x05,0x00,0x00,0x09};//LED设备号为5
	
	buf[4] = data; //LED状态数据1为亮,0为灭
	buf[5] = MakeVerify(&buf[1] , 4);
	
	return DvpView->SendData(buf , 7);
}

void CLedDialog::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
   
}

void CLedDialog::OnLedGetOk() 
{

	GetLed();
}

⌨️ 快捷键说明

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