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

📄 diodlg.cpp

📁 1553B板卡的源代码,只有购买板卡才能得到的好资料
💻 CPP
字号:
// DIODlg.cpp : implementation file
//

#include "stdafx.h"
#include "sf1553.h"
#include "DIODlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDIODlg dialog
static BYTE ioval422=0;
static BYTE iovalttl=0;


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


void CDIODlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDIODlg)
	DDX_Control(pDX, IDC_IO_CK_ENTTL, m_ckenttl);
	DDX_Control(pDX, IDC_IO_ED_VALTTL2, m_edvalttl2);
	DDX_Control(pDX, IDC_IO_ED_VALTTL, m_edvalttl);
	DDX_Control(pDX, IDC_IO_ED_VAL4222, m_edval4222);
	DDX_Control(pDX, IDC_IO_ED_VAL422, m_edval422);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDIODlg, CDialog)
	//{{AFX_MSG_MAP(CDIODlg)
	ON_BN_CLICKED(IDC_IO_BT_READ422, OnIoBtRead422)
	ON_BN_CLICKED(IDC_IO_BT_WRITE422, OnIoBtWrite422)
	ON_BN_CLICKED(IDC_IO_BT_READTTL, OnIoBtReadttl)
	ON_BN_CLICKED(IDC_IO_BT_WRITETTL, OnIoBtWritettl)
	ON_EN_CHANGE(IDC_IO_ED_VAL422, OnChangeIoEdVal422)
	ON_EN_KILLFOCUS(IDC_IO_ED_VAL422, OnKillfocusIoEdVal422)
	ON_EN_CHANGE(IDC_IO_ED_VAL4222, OnChangeIoEdVal4222)
	ON_EN_KILLFOCUS(IDC_IO_ED_VAL4222, OnKillfocusIoEdVal4222)
	ON_EN_CHANGE(IDC_IO_ED_VALTTL, OnChangeIoEdValttl)
	ON_EN_KILLFOCUS(IDC_IO_ED_VALTTL2, OnKillfocusIoEdValttl2)
	ON_EN_KILLFOCUS(IDC_IO_ED_VALTTL, OnKillfocusIoEdValttl)
	ON_EN_CHANGE(IDC_IO_ED_VALTTL2, OnChangeIoEdValttl2)
	ON_BN_CLICKED(IDC_IO_CK_ENTTL, OnIoCkEnttl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDIODlg message handlers

BOOL CDIODlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
		char c[80];
	this->m_edval422.LimitText(1);
	this->m_edvalttl.LimitText(2);
	this->m_edval4222.LimitText(1);
	this->m_edvalttl2.LimitText(2);
	ioval422 = 0;
	iovalttl = 0;

	sprintf(c, "%1x", ioval422);
	this->m_edval4222.SetWindowText(c);

	sprintf(c, "%02x", iovalttl);
	this->m_edvalttl2.SetWindowText(c);


	if (g_CardHandle != NULL)
	{
		// read io value
		//
		ioval422 = Rs422_DI(g_CardHandle); // 422
		ioval422 = ioval422&0x0f;
		iovalttl = TTL_DI(g_CardHandle); // TTL

		//	Disable TTL OUT
		//
		/*
		if (!TTL_DOEN(g_CardHandle, FALSE))
		{
			MessageBox(TEXT("停止 TTL 数字量输出失败!"), TEXT("错误"), MB_OK | MB_ICONERROR);
		}
		*/
	}
	else
	{
	}


	sprintf(c, "%1x", ioval422);
	this->m_edval422.SetWindowText(c);

	sprintf(c, "%02x", iovalttl);
	this->m_edvalttl.SetWindowText(c);

	this->m_ckenttl.SetCheck(BST_UNCHECKED);

	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDIODlg::OnIoBtRead422() 
{
	// TODO: Add your control notification handler code here
	char c[16];
	if (g_CardHandle != NULL)
	{
		// read data
		ioval422 = Rs422_DI(g_CardHandle);
		ioval422 = ioval422&0x0f;
	}

	sprintf(c, "%1x", ioval422);
	this->m_edval422.SetWindowText(c);
	
}

void CDIODlg::OnIoBtWrite422() 
{
	// TODO: Add your control notification handler code here
	char c[80];

	memset(c, 0, sizeof(c));
	this->m_edval4222.GetWindowText(c, sizeof(c));
	ioval422 = (BYTE) HEXS(c);
	ioval422 = ioval422&0x0f;

	if (g_CardHandle != NULL)
	{
		// write data
		Rs422_DO(g_CardHandle, ioval422);
	}
}

void CDIODlg::OnIoBtReadttl() 
{
	// TODO: Add your control notification handler code here

	char c[32];

	if (g_CardHandle != NULL)
	{
		// read data
		iovalttl = TTL_DI(g_CardHandle);
	}

	sprintf(c, "%02x", iovalttl);
	this->m_edvalttl.SetWindowText(c);
	
}

void CDIODlg::OnIoBtWritettl() 
{
	// TODO: Add your control notification handler code here
	char c[32];

	memset(c, 0, sizeof(c));
	this->m_edvalttl2.GetWindowText(c, sizeof(c));
	iovalttl = (BYTE) HEXS(c);

	if (g_CardHandle != NULL)
	{
		// write data
		TTL_DO(g_CardHandle, iovalttl);
	}
	
}

void CDIODlg::OnChangeIoEdVal422() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

		char c[32], s[32];
	char tc='\0';
	int i=0;
	int l=0, j=0;
	BOOL isErr=FALSE;
	DWORD dw=0;

	l = Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), -1);
	if (l==0)
		return;

	memset(s, 0, sizeof(s));
	memset(c, 0, sizeof(c));

	dw = Edit_GetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422));

	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), c, sizeof(c)); // get data string with HEX

	//  analyze data string with HEX
	//
	j=0;
	for (i=0; i<l; i++)
	{
		tc = c[i];
		if (((tc>='a')&&(tc<='f'))||((tc>='0')&&(tc<='9'))||((tc>='A')&&(tc<='F')))
		{
			s[j] = tc;
			j++;
		}
		else
		{
			isErr=TRUE;
		}
	}

	if (!isErr)
		return;

	//  write back the HEX value
	//
	::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), TEXT(s));
	Edit_SetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), HIWORD(dw)-1, HIWORD(dw)-1);

	
	// TODO: Add your control notification handler code here
	
}

void CDIODlg::OnKillfocusIoEdVal422() 
{
	// TODO: Add your control notification handler code here
		if (Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), -1)==0)
	{
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), TEXT("0"));
	}
	else
	{
		char c[80];

		memset(c, 0, sizeof(c));
		::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), c, sizeof(c));
		strupr(c);
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL422), TEXT(c));
	}
	
}

void CDIODlg::OnChangeIoEdVal4222() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	char c[32], s[32];
	char tc='\0';
	int i=0;
	int l=0, j=0;
	BOOL isErr=FALSE;
	DWORD dw=0;

	l = Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), -1);
	if (l==0)
		return;

	memset(s, 0, sizeof(s));
	memset(c, 0, sizeof(c));

	dw = Edit_GetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222));

	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), c, sizeof(c)); // get data string with HEX

	//  analyze data string with HEX
	//
	j=0;
	for (i=0; i<l; i++)
	{
		tc = c[i];
		if (((tc>='a')&&(tc<='f'))||((tc>='0')&&(tc<='9'))||((tc>='A')&&(tc<='F')))
		{
			s[j] = tc;
			j++;
		}
		else
		{
			isErr=TRUE;
		}
	}

	if (!isErr)
		return;

	//  write back the HEX value
	//
	::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), TEXT(s));
	Edit_SetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), HIWORD(dw)-1, HIWORD(dw)-1);
	
}

void CDIODlg::OnKillfocusIoEdVal4222() 
{
	// TODO: Add your control notification handler code here
	if (Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), -1)==0)
	{
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), TEXT("0"));
	}
	else
	{
		char c[80];

		memset(c, 0, sizeof(c));
		::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), c, sizeof(c));
		strupr(c);
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VAL4222), TEXT(c));
	}	
}

void CDIODlg::OnChangeIoEdValttl() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	char c[32], s[32];
	char tc='\0';
	int i=0;
	int l=0, j=0;
	BOOL isErr=FALSE;
	DWORD dw=0;

	l = Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), -1);
	if (l==0)
		return;

	memset(s, 0, sizeof(s));
	memset(c, 0, sizeof(c));

	dw = Edit_GetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL));

	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), c, sizeof(c)); // get data string with HEX

	//  analyze data string with HEX
	//
	j=0;
	for (i=0; i<l; i++)
	{
		tc = c[i];
		if (((tc>='a')&&(tc<='f'))||((tc>='0')&&(tc<='9'))||((tc>='A')&&(tc<='F')))
		{
			s[j] = tc;
			j++;
		}
		else
		{
			isErr=TRUE;
		}
	}

	if (!isErr)
		return;

	//  write back the HEX value
	//
	::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), TEXT(s));
	Edit_SetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), HIWORD(dw)-1, HIWORD(dw)-1);

	
}

void CDIODlg::OnKillfocusIoEdValttl2() 
{
	// TODO: Add your control notification handler code here
	if (Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), -1)==0)
	{
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), TEXT("00"));
	}
	else
	{
		char c[80];

		memset(c, 0, sizeof(c));
		::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), c, sizeof(c));
		strupr(c);
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), TEXT(c));
	}	

}

void CDIODlg::OnKillfocusIoEdValttl() 
{
	// TODO: Add your control notification handler code here
		if (Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), -1)==0)
	{
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), TEXT("00"));
	}
	else
	{
		char c[80];

		memset(c, 0, sizeof(c));
		::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), c, sizeof(c));
		strupr(c);
		::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL), TEXT(c));
	}
	
}

void CDIODlg::OnChangeIoEdValttl2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	char c[32], s[32];
	char tc='\0';
	int i=0;
	int l=0, j=0;
	BOOL isErr=FALSE;
	DWORD dw=0;

	l = Edit_LineLength(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), -1);
	if (l==0)
		return;

	memset(s, 0, sizeof(s));
	memset(c, 0, sizeof(c));

	dw = Edit_GetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2));

	::GetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), c, sizeof(c)); // get data string with HEX

	//  analyze data string with HEX
	//
	j=0;
	for (i=0; i<l; i++)
	{
		tc = c[i];
		if (((tc>='a')&&(tc<='f'))||((tc>='0')&&(tc<='9'))||((tc>='A')&&(tc<='F')))
		{
			s[j] = tc;
			j++;
		}
		else
		{
			isErr=TRUE;
		}
	}

	if (!isErr)
		return;

	//  write back the HEX value
	//
	::SetWindowText(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), TEXT(s));
	Edit_SetSel(::GetDlgItem(this->m_hWnd, IDC_IO_ED_VALTTL2), HIWORD(dw)-1, HIWORD(dw)-1);
	
}

void CDIODlg::OnIoCkEnttl() 
{
	// TODO: Add your control notification handler code here

	if ((this->m_ckenttl.GetCheck()) != BST_UNCHECKED)
	{
		if (g_CardHandle != NULL)
		{
			// Enable TTL
			if (!TTL_DOEN(g_CardHandle, TRUE))
			{
				MessageBox(TEXT("开启 TTL 数字量输出失败!"), TEXT("错误"), MB_OK | MB_ICONERROR);
			}
		}
	}
	else
	{
		if (g_CardHandle != NULL)
		{
			// Disable TTL
			if (!TTL_DOEN(g_CardHandle, FALSE))
			{
				MessageBox(TEXT("停止 TTL 数字量输出失败!"), TEXT("错误"), MB_OK | MB_ICONERROR);
			}
		}
	}


	
}

⌨️ 快捷键说明

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