
// IODlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "IO.h"
#include "IODlg.h"
#include "afxdialogex.h"
#include"MC_dll.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

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

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CIODlg 对话框



CIODlg::CIODlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_IO_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	reuseIoIndex = 0;
	reuseAxisOrIoIndex = 0;

	mapAxisOrIoIndex = 0;
}

void CIODlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);

	DDX_Text(pDX, IDC_EDIT1, reuseIoIndex);
	DDX_Text(pDX, IDC_EDIT2, reuseAxisOrIoIndex);
	DDX_Text(pDX, IDC_EDIT4, mapAxisOrIoIndex);

	DDX_Control(pDX, IDC_COMBO1, ioReuseType);
	DDX_Control(pDX, IDC_COMBO3, axisIoType);
	DDX_Control(pDX, IDC_COMBO2, ioMapType);
	DDX_Control(pDX, IDC_OUTPUT0, output0);
}

BEGIN_MESSAGE_MAP(CIODlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON13, &CIODlg::OnBnClickedButton13)
	ON_BN_CLICKED(IDC_BUTTON14, &CIODlg::OnBnClickedButton14)
	ON_BN_CLICKED(IDC_BUTTON15, &CIODlg::OnBnClickedButton15)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, &CIODlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON1, &CIODlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CIODlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CIODlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CIODlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CIODlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CIODlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CIODlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CIODlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CIODlg::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON10, &CIODlg::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON11, &CIODlg::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON12, &CIODlg::OnBnClickedButton12)
END_MESSAGE_MAP()


// CIODlg 消息处理程序

BOOL CIODlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
#pragma region 开卡
	WORD pciNum = 0; //用于接收开卡成功的卡数
	WORD pcieIndex[12];
	DWORD functionReturn = 0; //函数返回值

	functionReturn = MC_Open(0, CONNECTION_PCI, "", &pciNum, pcieIndex);
	if (functionReturn == 0)//函数成功执行
	{
		if (pciNum > 0)//至少一张卡被成功开卡
		{
			cardConnectNo = pcieIndex[0]; //如果有多卡的情况下这里也只用卡1演示

#pragma region 获取卡信息
			//--------------------------获取卡信息------------------------------------------------------------------------
			WORD totalAxisNum = 0; //用于获取卡的轴数
			WORD linerNum = 0;//用于获取卡的插补系个数
			WORD totalInNum = 0;//用于获取卡的输入口数量
			WORD totalOutNum = 0;//用于获取卡的输出口数量
			WORD totalPWMNum = 0;//用于获取卡的PWM通道数量
			functionReturn = MC_GetTotalAxesAndIONum(cardConnectNo, &totalAxisNum, &linerNum, &totalInNum, &totalOutNum, &totalPWMNum);
			
			ioReuseType.AddString(L"负限位");
			ioReuseType.AddString(L"正限位");
			ioReuseType.AddString(L"原点");
			ioReuseType.AddString(L"伺服到位");
			ioReuseType.AddString(L"急停信号");
			ioReuseType.AddString(L"伺服报警");
			ioReuseType.AddString(L"伺服准备");
			ioReuseType.AddString(L"减速信号");
			ioReuseType.AddString(L"通用IO信号");
			ioReuseType.SetCurSel(0);

			axisIoType.AddString(L"负限位");
			axisIoType.AddString(L"正限位");
			axisIoType.AddString(L"原点");
			axisIoType.AddString(L"伺服到位");
			axisIoType.AddString(L"急停信号");
			axisIoType.AddString(L"伺服报警");
			axisIoType.AddString(L"伺服准备");
			axisIoType.AddString(L"减速信号");
			axisIoType.SetCurSel(0);

			ioMapType.AddString(L"负限位");
			ioMapType.AddString(L"正限位");
			ioMapType.AddString(L"原点");
			ioMapType.AddString(L"伺服到位");
			ioMapType.AddString(L"急停信号");
			ioMapType.AddString(L"伺服报警");
			ioMapType.AddString(L"伺服准备");
			ioMapType.AddString(L"减速信号");
			ioMapType.AddString(L"通用IO信号");
			ioMapType.SetCurSel(8);

			//------------------------------------------------------------------------------------------------------------
#pragma endregion
			SetTimer(1, 200, NULL);//启动界面监控定时器

		}
		else
		{
			MessageBox(L"未找到卡!");
		}
	}
	else
	{
		MessageBox(L"开卡失败!");
	}
#pragma endregion
	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

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

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CIODlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CIODlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


/// <summary>
/// 界面上SetReuse按钮点击事件
/// </summary>
void CIODlg::OnBnClickedButton13()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);

	int map_io_type = ioReuseType.GetCurSel();
	if (map_io_type == 8) map_io_type = 9;//map_io_type = 9时为通用IO信号
	MC_SetReuseIoMap(cardConnectNo, reuseIoIndex, map_io_type, reuseAxisOrIoIndex);

	UpdateData(false);
}

/// <summary>
/// 获取虚拟IO状态按钮点击
/// </summary>
void CIODlg::OnBnClickedButton14()
{
	// TODO: 在此添加控件通知处理程序代码
	byte ioState = 0;
	MC_GetReuseInIoBit(cardConnectNo, reuseIoIndex, &ioState);

	CString ioStateStr;
	ioStateStr.Format(_T("%d"), ioState);
	GetDlgItem(IDC_EDIT3)->SetWindowTextW(ioStateStr);
}

/// <summary>
/// SetMap按钮点击事件
/// </summary>
void CIODlg::OnBnClickedButton15()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);

	WORD axis_io_type = axisIoType.GetCurSel();
	WORD map_io_type = ioMapType.GetCurSel();

	//默认界面上参数时将轴0的负限位映射到通用输入0;
	MC_SetAxisInIoMap(cardConnectNo, 0, axis_io_type, map_io_type, mapAxisOrIoIndex);

	UpdateData(false);
}


void CIODlg::OnDestroy()
{
	CDialogEx::OnDestroy();

	// TODO: 在此处添加消息处理程序代码
	KillTimer(1);
	MC_Close(cardConnectNo); //关卡释放资源
}


void CIODlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

#pragma region 通用输入
	const int GetinputIOType = 0; //获取通用输入有三种写法
	DWORD inputState_uint = 0;
	unsigned long long inputState_ulong = 0;
	switch (GetinputIOType)
	{
	case 0:
		for (DWORD inputIndex = 0; inputIndex < 12; inputIndex++)
		{
			byte inputState_byte = 0;
			MC_GetInIoBit(cardConnectNo, inputIndex, &inputState_byte);//按位获取通用输入口的状态，一次读一位
			BitSetPictureBoxState(inputIndex, inputState_byte);
		}
		break;
		
	case 1:
		
		MC_GetInIoPort(cardConnectNo, 0, &inputState_uint); //按端口获取通用输入，一次获取32位
		PortSetPictureBoxState(inputState_uint);
		break;
	case 2:
		MC_GetInIoPtr(cardConnectNo, 0, 12, &inputState_ulong);//获取通用输入口状态，输入起始索引和需要获取的个数，最多一次获取64bit
		PtrSetPictureBoxState(0, 12, inputState_ulong);
		break;
	default:
		break;
	}
#pragma endregion

#pragma region 通用输出
	const int GetOutputIOType = 0;//获取通用输出的状态也有三种写法
	DWORD outputIOState_uint = 0;
	unsigned long long  outputIOState_ulong = 0;
	switch (GetOutputIOType)
	{
	case 0:
		for (DWORD outputIndex = 0; outputIndex < 12; outputIndex++)
		{
			byte outputState_byte = 0;
			MC_GetOutIoBit(cardConnectNo, outputIndex, &outputState_byte);//按位获取通用输出口的状态，一次读一位
			BitSetOutputState(outputIndex, outputState_byte);
		}
		break;
	case 1:		
		MC_GetOutIoPort(cardConnectNo, 0, &outputIOState_uint);//按端口获取通用输出，一次获取32位
		PortSetOutputState(outputIOState_uint);
		break;
	case 2:		
		MC_GetOutIoPtr(cardConnectNo, 0, 12, &outputIOState_ulong);//获取通用输出口状态，输入起始索引和需要获取的个数，最多一次获取64bit
		PtrSetOutputState(0, 12, outputIOState_ulong);
		break;
	default:
		break;
	}
#pragma endregion

#pragma region 轴0专用信号
	DWORD inIoState = 0;
	MC_GetAxisInIoState(cardConnectNo, 0, &inIoState);
	//负限位
	bool state = false;
	state = (inIoState & (DWORD)0x1) > 0 ? true : false;
	if (state)((CStatic*)GetDlgItem(IDC_ELN))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_ELN))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//正限位
	state = ((inIoState >> 1) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_ELP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_ELP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//原点
	state = ((inIoState >> 2) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_ORG))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_ORG))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//伺服到位
	state = ((inIoState >> 3) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_INP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_INP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//报警(ALM)
	state = ((inIoState >> 5) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_ALM))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_ALM))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//伺服准备
	state = ((inIoState >> 6) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_RDY))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_RDY))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//软限位 负
	state = ((inIoState >> 9) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_SLN))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_SLN))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//软限位 正
	state = ((inIoState >> 10) & (DWORD)0x1) > 0 ? true : false;
	if (state) ((CStatic*)GetDlgItem(IDC_SLP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_SLP))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//SERVON
	WORD _servon = 0;
	MC_GetAxisOutIo(cardConnectNo, 0, 0, &_servon);
	if (_servon == 1) ((CStatic*)GetDlgItem(IDC_SERVON))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_SERVON))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));

	//ERC
	WORD _erc = 0;
	MC_GetAxisOutIo(cardConnectNo, 0, 1, &_erc);
	if (_erc == 1) ((CStatic*)GetDlgItem(IDC_ERC))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
	else ((CStatic*)GetDlgItem(IDC_ERC))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
#pragma endregion

	CDialogEx::OnTimer(nIDEvent);
}

/// <summary>
/// 按bit设置界面中的通用输入状态
/// </summary>
void CIODlg::BitSetPictureBoxState(DWORD inputIndex, byte state)
{
	int useImage = 0;
	if (state == 0)
	{
		useImage = IDI_ICONGREEN;
	}
	else
	{
		useImage = IDI_ICONRED;
	}
	switch (inputIndex)
	{
	case 0:
		((CStatic*)GetDlgItem(IDC_INPUTBIT0))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 1:
		((CStatic*)GetDlgItem(IDC_INPUTBIT1))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 2:
		((CStatic*)GetDlgItem(IDC_INPUTBIT2))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 3:
		((CStatic*)GetDlgItem(IDC_INPUTBIT3))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 4:
		((CStatic*)GetDlgItem(IDC_INPUTBIT4))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 5:
		((CStatic*)GetDlgItem(IDC_INPUTBIT5))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 6:
		((CStatic*)GetDlgItem(IDC_INPUTBIT6))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 7:
		((CStatic*)GetDlgItem(IDC_INPUTBIT7))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 8:
		((CStatic*)GetDlgItem(IDC_INPUTBIT8))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 9:
		((CStatic*)GetDlgItem(IDC_INPUTBIT9))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 10:
		((CStatic*)GetDlgItem(IDC_INPUTBIT10))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 11:
		((CStatic*)GetDlgItem(IDC_INPUTBIT11))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	default:
		break;
	}

}

/// <summary>
/// 按端口设置界面中的通用输入状态
/// </summary>
/// <param name="inputState_uint"></param>
void CIODlg::PortSetPictureBoxState(DWORD inputState_uint)
{
	for (int i = 0; i < 32; i++)
	{
		bool bitValue = (inputState_uint & (0x1 << i)) == (0x1 << i); //获取32位数中的第i位
		switch (i)
		{
		case 0:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 1:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 2:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 3:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 4:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 5:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 6:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 7:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 8:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 9:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 10:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 11:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		default:
			break;
		}
	}
}


/// <summary>
/// 按照输入的起始和个数获取到的输入口状态
/// </summary>
/// <param name="startIndex"></param>
/// <param name="inputNum"></param>
/// <param name="inputState"></param>
void CIODlg::PtrSetPictureBoxState(int startIndex, int inputNum, unsigned long long  inputState)
{
	for (int i = startIndex; i < inputNum; i++)
	{
		bool bitValue = (inputState & ((unsigned long long )0x1 << i)) == ((unsigned long long)0x1 << i); //获取64位数中的第i位
		switch (i)
		{
		case 0:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 1:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 2:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 3:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 4:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 5:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 6:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 7:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 8:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 9:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 10:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 11:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_INPUTBIT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		default:
			break;
		}
	}
}


/// <summary>
/// 按bit设置界面中的通用输出状态
/// </summary>
/// <param name="ouputIndex"></param>
/// <param name="state"></param>
void CIODlg::BitSetOutputState(DWORD ouputIndex, byte state)
{
	int useImage = 0;
	if (state == 0)
	{
		useImage = IDI_ICONGREEN;
	}
	else
	{
		useImage = IDI_ICONRED;
	}
	switch (ouputIndex)
	{
	case 0:
		((CStatic*)GetDlgItem(IDC_OUTPUT0))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 1:
		((CStatic*)GetDlgItem(IDC_OUTPUT1))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 2:
		((CStatic*)GetDlgItem(IDC_OUTPUT2))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 3:
		((CStatic*)GetDlgItem(IDC_OUTPUT3))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 4:
		((CStatic*)GetDlgItem(IDC_OUTPUT4))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 5:
		((CStatic*)GetDlgItem(IDC_OUTPUT5))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 6:
		((CStatic*)GetDlgItem(IDC_OUTPUT6))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 7:
		((CStatic*)GetDlgItem(IDC_OUTPUT7))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 8:
		((CStatic*)GetDlgItem(IDC_OUTPUT8))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 9:
		((CStatic*)GetDlgItem(IDC_OUTPUT9))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 10:
		((CStatic*)GetDlgItem(IDC_OUTPUT10))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	case 11:
		((CStatic*)GetDlgItem(IDC_OUTPUT11))->SetIcon(AfxGetApp()->LoadIcon(useImage));
		break;
	default:
		break;
	}
}

/// <summary>
/// 按port设置界面通用输出口状态
/// </summary>
/// <param name="outputState"></param>
void CIODlg::PortSetOutputState(DWORD outputState)
{
	for (int i = 0; i < 32; i++)
	{
		bool bitValue = (outputState & (0x1 << i)) == (0x1 << i); //获取32位数中的第i位
		switch (i)
		{
		case 0:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 1:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 2:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 3:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 4:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 5:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 6:
			if(bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 7:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 8:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 9:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 10:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 11:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		default:
			break;
		}
	}
}

/// <summary>
/// 按照输入的起始和个数获取到的输出口状态
/// </summary>
/// <param name="startIndex"></param>
/// <param name="outputNum"></param>
/// <param name="outputState"></param>
void CIODlg::PtrSetOutputState(int startIndex, int outputNum, unsigned long long  outputState)
{
	for (int i = startIndex; i < outputNum; i++)
	{
		bool bitValue = (outputState & ((unsigned long long)0x1 << i)) == ((unsigned long long)0x1 << i); //获取64位数中的第i位
		switch (i)
		{
		case 0:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT0))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 1:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT1))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 2:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 3:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT3))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 4:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT4))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 5:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT5))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 6:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT6))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 7:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT7))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 8:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT8))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 9:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT9))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 10:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT10))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		case 11:
			if (bitValue) //为1，高电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONRED));
			}
			else//为0，低电平
			{
				((CStatic*)GetDlgItem(IDC_OUTPUT11))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICONGREEN));
			}
			break;
		default:
			break;
		}
	}
}


#pragma region 通用输出按钮操作
void CIODlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT0))->GetIcon() == redIcon)
	{
		const int SetOutIoType = 0; //设置通用输出口也有三种方式
		DWORD ioState = 0;
		switch (SetOutIoType)
		{
		case 0:
			MC_SetOutIoBit(cardConnectNo, 0, 0); //方式1
			break;
		case 1:
			
			MC_GetOutIoPort(cardConnectNo, 0, &ioState);
			ioState &= 0xFFFFFFFE; //将bit0设置为0
			MC_SetOutIoPort(cardConnectNo, 0, ioState);//方式2
			break;
		case 2:
			MC_SetOutIoPtr(cardConnectNo, 0, 0, 0x1);//方式3，IoMask = 0x1,bit0写入ioState = 0，其他位保持不变
			break;
		default:
			break;
		}
		
	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 0, 1);
	}
}


void CIODlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT1))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 1, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 1, 1);
	}
}

void CIODlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT2))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 2, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 2, 1);
	}
}


void CIODlg::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT3))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 3, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 3, 1);
	}
}


void CIODlg::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT4))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 4, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 4, 1);
	}
}


void CIODlg::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT5))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 5, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 5, 1);
	}
}


void CIODlg::OnBnClickedButton7()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT6))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 6, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 6, 1);
	}
}


void CIODlg::OnBnClickedButton8()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT7))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 7, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 7, 1);
	}
}


void CIODlg::OnBnClickedButton9()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT8))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 8, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 8, 1);
	}
}


void CIODlg::OnBnClickedButton10()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT9))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 9, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 9, 1);
	}
}


void CIODlg::OnBnClickedButton11()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT10))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 10, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 10, 1);
	}
}


void CIODlg::OnBnClickedButton12()
{
	// TODO: 在此添加控件通知处理程序代码
	HICON redIcon = AfxGetApp()->LoadIcon(IDI_ICONRED);
	if (((CStatic*)GetDlgItem(IDC_OUTPUT11))->GetIcon() == redIcon)
	{

		MC_SetOutIoBit(cardConnectNo, 11, 0);

	}
	else
	{
		MC_SetOutIoBit(cardConnectNo, 11, 1);
	}
}
#pragma endregion





