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

📄 plcdlg.cpp

📁 作者自己编写的应用计算机串口同三菱fx系列plc通信的源程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// PLCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PLC.h"
#include "PLCDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About


//实时通信的问题

//以下为PLC通信的指令设备地址为1.

//开启--Flag:9
unsigned char Plc_Run[]={0X05,0X30,0X31,0X46,0X46,0X52,0X52,0X30};	
//从停止状态下转到运行状态所需的时间非常长。执行该命令会影响紧跟的三四个命令

//关闭--Flag:10
unsigned char Plc_Stp[]={0X05,0X30,0X31,0X46,0X46,0X52,0X53,0X30};	

//Y输出1
//0-7对应Y000-Y007
//8-15对应Y010-017
//Flag:11
unsigned char YOpen[][16]={
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X30,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X31,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X32,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X33,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X34,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X35,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X36,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X37,0X30,0X31,0X31},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X30,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X31,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X32,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X33,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X34,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X35,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X36,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X37,0X30,0X31,0X31},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X30,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X31,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X32,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X33,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X34,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X35,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X36,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X37,0X30,0X31,0X31},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X30,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X31,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X32,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X33,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X34,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X35,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X36,0X30,0X31,0X31},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X37,0X30,0X31,0X31}
};
//Y输出0,关闭
//0-7对应Y000-Y007
//8-15对应Y010-017
//Flag:12
unsigned char YClose[][16]={
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X30,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X31,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X32,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X33,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X34,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X35,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X36,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X30,0X37,0X30,0X31,0X30},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X30,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X31,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X32,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X33,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X34,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X35,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X36,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X31,0X37,0X30,0X31,0X30},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X30,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X31,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X32,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X33,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X34,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X35,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X36,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X32,0X37,0X30,0X31,0X30},

		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X30,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X31,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X32,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X33,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X34,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X35,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X36,0X30,0X31,0X30},
		{0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,0X59,0X30,0X30,0X33,0X37,0X30,0X31,0X30}

};

//Plc接通指令,原封不动的返回,用来测试PLc和在程序中充数,产生较长的延时.
//Flag:14
unsigned char Plc_TT[]={0X05,0X30,0X31,0X46,0X46,0X54,0X54,0X30,0X30,0X36,0X41,0X42,0X43,0X44,0X45,0X46};

//读取状态
//Flag:15
unsigned char Command_Status_Plc_X[]={0X05,0X30,0X31,0X46,0X46,0X42,0X52,0X41,0X58,0X30,0X30,0X30,0X30,0X32,0X34};
//Flag:16
unsigned char Command_Status_Plc_Y[]={0X05,0X30,0X31,0X46,0X46,0X42,0X52,0X41,0X59,0X30,0X30,0X30,0X30,0X33,0X32};


unsigned char RecData_Plc[]={0X06,0X30,0X31,0X46,0X46};	//PLC正确执行后应收到的数据
unsigned char RecDataLength_Plc=5;

//Flag:17
unsigned char Command_OpenAll[]={	0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,
									0X59,0X30,0X30,0X30,0X30,0X31,0X30,0X31,
									0X31,0X31,0X31,0X31,0X31,0X31,0X31,0X31,
									0X31,0X31,0X31,0X31,0X31,0X31,0X31};

//Flag:18
unsigned char Command_CloseAll[]={	0X05,0X30,0X31,0X46,0X46,0X42,0X57,0X30,
									0X59,0X30,0X30,0X30,0X30,0X31,0X30,0X30,
									0X30,0X30,0X30,0X30,0X30,0X30,0X30,0X30,
									0X30,0X30,0X30,0X30,0X30,0X30,0X30};






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()

/////////////////////////////////////////////////////////////////////////////
// CPLCDlg dialog

CPLCDlg::CPLCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPLCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPLCDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	ErrorNum_PlcRun=0;
	ErrorNum_PlcStp=0;
	ErrorNum_PlcTT=0;
	ErrorNum_Status_Y=0;
	ErrorNum_Status_X=0;

	Status_Plc=false;

	for(int i=0;i<32;i++)
	{
		ErrorNum_YOpen[i]=0;
		ErrorNum_YClose[i]=0;				
		Status_Plc_X[i]=0;
		Status_Plc_Y[i]=0;
	}
	for(i=0;i<4;i++)
	{
		CommandArr_Pre[i].RemoveAll();
		CommandLengthArr_Pre[i].RemoveAll();		
		CommandFlag_Pre[i].RemoveAll();
		RecDataLengthArr_Pre[i].RemoveAll();

		CommandArr_Cur[i].RemoveAll();
		CommandLengthArr_Cur[i].RemoveAll();		
		CommandFlag_Cur[i].RemoveAll();
		RecDataLengthArr_Cur[i].RemoveAll();

		iFrame[i]	=	0;
		iCommand[i]	=	0;
		iRecData[i]	=	0;
	}

	iRun=false;

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPLCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPLCDlg)
	DDX_Control(pDX, IDC_SHUNXU, m_ShunXu);
	DDX_Control(pDX, IDC_RUN, m_Run);
	DDX_Control(pDX, IDCANCEL, m_Exit);
	DDX_Control(pDX, IDC_CLOSEALL, m_CloseAll);
	DDX_Control(pDX, IDC_OPENALL, m_OpenAll);
	DDX_Control(pDX, IDC_Y00, m_Y00);
	DDX_Control(pDX, IDC_Y01, m_Y01);
	DDX_Control(pDX, IDC_Y02, m_Y02);
	DDX_Control(pDX, IDC_Y03, m_Y03);
	DDX_Control(pDX, IDC_Y04, m_Y04);
	DDX_Control(pDX, IDC_Y05, m_Y05);
	DDX_Control(pDX, IDC_Y06, m_Y06);
	DDX_Control(pDX, IDC_Y07, m_Y07);
	DDX_Control(pDX, IDC_Y10, m_Y10);
	DDX_Control(pDX, IDC_Y11, m_Y11);
	DDX_Control(pDX, IDC_Y12, m_Y12);
	DDX_Control(pDX, IDC_Y13, m_Y13);
	DDX_Control(pDX, IDC_Y14, m_Y14);
	DDX_Control(pDX, IDC_Y15, m_Y15);
	DDX_Control(pDX, IDC_Y16, m_Y16);
	DDX_Control(pDX, IDC_Y17, m_Y17);
	DDX_Control(pDX, IDC_X00, m_X00);
	DDX_Control(pDX, IDC_X01, m_X01);
	DDX_Control(pDX, IDC_X02, m_X02);
	DDX_Control(pDX, IDC_X03, m_X03);
	DDX_Control(pDX, IDC_X04, m_X04);
	DDX_Control(pDX, IDC_X05, m_X05);
	DDX_Control(pDX, IDC_X06, m_X06);
	DDX_Control(pDX, IDC_X07, m_X07);
	DDX_Control(pDX, IDC_X10, m_X10);
	DDX_Control(pDX, IDC_X11, m_X11);
	DDX_Control(pDX, IDC_X12, m_X12);
	DDX_Control(pDX, IDC_X13, m_X13);
	DDX_Control(pDX, IDC_X14, m_X14);
	DDX_Control(pDX, IDC_X15, m_X15);
	DDX_Control(pDX, IDC_X16, m_X16);
	DDX_Control(pDX, IDC_X17, m_X17);
	DDX_Control(pDX, IDC_X20, m_X20);
	DDX_Control(pDX, IDC_X21, m_X21);
	DDX_Control(pDX, IDC_X22, m_X22);
	DDX_Control(pDX, IDC_X23, m_X23);
	DDX_Control(pDX, IDC_X24, m_X24);
	DDX_Control(pDX, IDC_X25, m_X25);
	DDX_Control(pDX, IDC_X26, m_X26);
	DDX_Control(pDX, IDC_X27, m_X27);
	DDX_Control(pDX, IDC_FLAG_COMM1, m_Flag_Comm1);
	DDX_Control(pDX, IDC_FLAG_COMM2, m_Flag_Comm2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPLCDlg, CDialog)
	//{{AFX_MSG_MAP(CPLCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
	ON_WM_TIMER()
	ON_WM_LBUTTONDBLCLK()
	ON_BN_CLICKED(IDC_CLOSEALL, OnCloseall)
	ON_BN_CLICKED(IDC_OPENALL, OnOpenall)
	ON_BN_CLICKED(IDC_RUN, OnRun)
	ON_BN_CLICKED(IDC_BTN_Y00, OnBtnY00)
	ON_BN_CLICKED(IDC_BTN_Y01, OnBtnY01)
	ON_BN_CLICKED(IDC_BTN_Y02, OnBtnY02)
	ON_BN_CLICKED(IDC_BTN_Y03, OnBtnY03)
	ON_BN_CLICKED(IDC_BTN_Y04, OnBtnY04)
	ON_BN_CLICKED(IDC_BTN_Y05, OnBtnY05)
	ON_BN_CLICKED(IDC_BTN_Y06, OnBtnY06)
	ON_BN_CLICKED(IDC_BTN_Y07, OnBtnY07)
	ON_BN_CLICKED(IDC_BTN_Y10, OnBtnY10)
	ON_BN_CLICKED(IDC_BTN_Y11, OnBtnY11)
	ON_BN_CLICKED(IDC_BTN_Y12, OnBtnY12)
	ON_BN_CLICKED(IDC_BTN_Y13, OnBtnY13)
	ON_BN_CLICKED(IDC_BTN_Y14, OnBtnY14)
	ON_BN_CLICKED(IDC_BTN_Y15, OnBtnY15)
	ON_BN_CLICKED(IDC_BTN_Y16, OnBtnY16)
	ON_BN_CLICKED(IDC_BTN_Y17, OnBtnY17)
	ON_BN_CLICKED(IDC_SHUNXU, OnShunxu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPLCDlg message handlers

BOOL CPLCDlg::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
	
	m_Flag_Comm1.SetLed(CLed::LED_COLOR_GREEN,CLed::LED_OFF,CLed::LED_ROUND);
	m_Flag_Comm2.SetLed(CLed::LED_COLOR_GREEN,CLed::LED_OFF,CLed::LED_ROUND);
	
	InitBtn();
	InitLabel();
	InitCommand();

	port1.InitPort(this,1,9600);
	BOOL Result=port1.StartMonitoring();
	//长时间的测试证明COM1设为100ms比较合适。
	SetTimer(1,200,NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPLCDlg::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 CPLCDlg::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
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPLCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

LONG CPLCDlg::OnCommunication(WPARAM ch, LPARAM port)
{
	if(port==1)//串口1接收到数据
	{
		RecData[0][iRecData[0]]=ch;
		iRecData[0]++;
		
		int VV=iRecData[0]%7;
		if(VV==0)
			m_Flag_Comm1.Ping(40);
	}
	return 0;

}
int iii0=0;
int iii1=0;
int iDisTime=0;
int ArrLength0=0;
int ArrLength1=0;

int iii_WriteRunningData=0;

void CPLCDlg::OnTimer(UINT nIDEvent) 
{

	if(nIDEvent==1)//100ms的定时器,用于串口1
	{


		if(iii0==0)					//保证了每一帧开始时才加入。
			ArrLength0=DealCommandArr(0);

	//获取前一个命令和Flag	
		
		if(SendCommand(iii0,0)==1)		//发送数据
		{
			m_Flag_Comm2.Ping(40);
			int RecDataLength=RecDataLengthArr_Cur[0].GetAt(iii0);
			{
				DisposeData(RecData[0],iRecData[0],PreCommand[0],PreFlag[0]);
				iRecData[0]=0;

				iii0++;
			}
		}

		if(iii0==ArrLength0&&iii0!=0)
		{
			iFrame[0]++;					//命令帧的数目加一
//			GetIndicateLightStatus();		//获取各个指示灯的状态
			iii0=0;
		}
	}
	DisplayLabel(Status_Plc_X,Status_Plc_Y);
	CDialog::OnTimer(nIDEvent);
}

void CPLCDlg::InitLabel()
{
	
	m_X00.SetBitmap(IDB_NORMAL);
	m_X01.SetBitmap(IDB_NORMAL);
	m_X02.SetBitmap(IDB_NORMAL);
	m_X03.SetBitmap(IDB_NORMAL);
	m_X04.SetBitmap(IDB_NORMAL);
	m_X05.SetBitmap(IDB_NORMAL);
	m_X06.SetBitmap(IDB_NORMAL);
	m_X07.SetBitmap(IDB_NORMAL);
	m_X10.SetBitmap(IDB_NORMAL);
	m_X11.SetBitmap(IDB_NORMAL);
	m_X12.SetBitmap(IDB_NORMAL);
	m_X13.SetBitmap(IDB_NORMAL);
	m_X14.SetBitmap(IDB_NORMAL);
	m_X15.SetBitmap(IDB_NORMAL);
	m_X16.SetBitmap(IDB_NORMAL);
	m_X17.SetBitmap(IDB_NORMAL);
	m_X20.SetBitmap(IDB_NORMAL);
	m_X21.SetBitmap(IDB_NORMAL);
	m_X22.SetBitmap(IDB_NORMAL);
	m_X23.SetBitmap(IDB_NORMAL);
	m_X24.SetBitmap(IDB_NORMAL);
	m_X25.SetBitmap(IDB_NORMAL);
	m_X26.SetBitmap(IDB_NORMAL);
	m_X27.SetBitmap(IDB_NORMAL);
	
	
	m_Y00.SetBitmap(IDB_NORMAL);
	m_Y01.SetBitmap(IDB_NORMAL);
	m_Y02.SetBitmap(IDB_NORMAL);
	m_Y03.SetBitmap(IDB_NORMAL);
	m_Y04.SetBitmap(IDB_NORMAL);
	m_Y05.SetBitmap(IDB_NORMAL);
	m_Y06.SetBitmap(IDB_NORMAL);
	m_Y07.SetBitmap(IDB_NORMAL);
	m_Y10.SetBitmap(IDB_NORMAL);
	m_Y11.SetBitmap(IDB_NORMAL);
	m_Y12.SetBitmap(IDB_NORMAL);
	m_Y13.SetBitmap(IDB_NORMAL);
	m_Y14.SetBitmap(IDB_NORMAL);
	m_Y15.SetBitmap(IDB_NORMAL);
	m_Y16.SetBitmap(IDB_NORMAL);
	m_Y17.SetBitmap(IDB_NORMAL);

	RECT rec;
	rec.bottom=158;
	rec.top=117;
	rec.left=406;
	rec.right=304;
	InvalidateRect(&rec,FALSE);

}
void CPLCDlg::DisplayLabel(unsigned char X[],unsigned char Y[])
{
	if(X[0]==0)

⌨️ 快捷键说明

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