// 87k_dioDlg.cpp : implementation file // #include "stdafx.h" #include "87k_dio.h" #include "87k_dioDlg.h" #include "PACSDK.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy87k_dioDlg dialog CMy87k_dioDlg::CMy87k_dioDlg(CWnd* pParent /*=NULL*/) : CDialog(CMy87k_dioDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy87k_dioDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, cmbSlot); DDX_Control(pDX, IDC_EDIT1, txtDOValue); DDX_Control(pDX, IDC_EDIT4, txtDOChannel); DDX_Control(pDX, IDC_EDIT2, txtDIChannel); DDX_Control(pDX, IDC_EDIT3, txtDIValue); DDX_Control(pDX, IDC_BUTTON1, btnRead); DDX_Control(pDX, IDC_BUTTON2, btnWrite); DDX_Control(pDX, IDC_BUTTON3, btnClear); } BEGIN_MESSAGE_MAP(CMy87k_dioDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy87k_dioDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy87k_dioDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CMy87k_dioDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CMy87k_dioDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CMy87k_dioDlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON6, &CMy87k_dioDlg::OnBnClickedButton6) END_MESSAGE_MAP() // CMy87k_dioDlg message handlers BOOL CMy87k_dioDlg::OnInitDialog() { CDialog::OnInitDialog(); // 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 // TODO: Add extra initialization here //set default value SetDlgItemText(IDC_COMBO1,L"1"); SetDlgItemText(IDC_EDIT4,L"8"); SetDlgItemText(IDC_EDIT2,L"8"); SetDlgItemText(IDC_EDIT1,L"0XFF"); SetDlgItemText(IDC_EDIT6, L"What is pac_xxx_MF?\r\nMF is the abbreviation of Multi-function.\r\npac_xxx_MF is used to access DIO channels of the Multi-function module.\r\nAIO or counter modules equipped with DI or DO channel is known as Multi-function module.\r\nCall pac_xxxx function to access DIO channels of the DCON module equipped only with DI or DO channel.\r\nCall pac_xxx_MF functions to access DIO channel of the Multi-function module.\r\n"); return TRUE; // return TRUE unless you set the focus to a control } #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) void CMy87k_dioDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY87K_DIO_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY87K_DIO_DIALOG)); } } #endif void CMy87k_dioDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here HANDLE hPort = uart_Open(""); TCHAR temp[10]; //get user set slot GetDlgItemText(IDC_COMBO1,temp,10); int slot = _wtoi(temp); //get user set DI total channel GetDlgItemText(IDC_EDIT2,temp,10); int DIChannel = _wtoi(temp); //get user set DO total channel GetDlgItemText(IDC_EDIT4,temp,10); int DOChannel = _wtoi(temp); DWORD DIValue=0,DOValue=0; //use pac_ReadDIO functio to read DI and DO data BOOL iret = pac_ReadDIO(hPort,slot,DIChannel,DOChannel,&DIValue,&DOValue); uart_Close(hPort); if(!iret){ ::MessageBox(NULL,L"Read DI error",L"87k_dio",MB_OK); }else{ wsprintf(temp,L"%d",DIValue); SetDlgItemText(IDC_EDIT3,temp); wsprintf(temp,L"0X%lx",DIValue); SetDlgItemText(IDC_EDIT5,temp); } } void CMy87k_dioDlg::OnBnClickedButton2() { // TODO: Add your control notification handler code here //uart_Open function parameter is "", it's open COM0 port and baud rate set 115200 //COM0 port connect to backplane HANDLE hPort = uart_Open(""); TCHAR temp[10]; CString strTemp; char ctemp[20]={0}; DWORD DOValue= 0; //get user set slot GetDlgItemText(IDC_COMBO1,temp,10); int slot = _wtoi(temp); //get user set DO total channel GetDlgItemText(IDC_EDIT4,temp,10); int DOChannel = _wtoi(temp); //get user set write DO data GetDlgItemText(IDC_EDIT1,strTemp); for(int i=0;i