// sample0Dlg.cpp : implementation file // #include "stdafx.h" #include "sample0.h" #include "sample0Dlg.h" #include "acces32.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg dialog CSample0Dlg::CSample0Dlg(CWnd* pParent /*=NULL*/) : CDialog(CSample0Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CSample0Dlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CSample0Dlg::GetDeviceInfo() { HKEY key; unsigned long dataType, dataLength; long cardsFound; TPCI_COMMON_CONFIG buf[64]; char cardString[128]; numCards = 0; RegOpenKeyEx(HKEY_LOCAL_MACHINE, regKey, 0, KEY_READ, &key); dataLength = sizeof(cardsFound); if (RegQueryValueEx(key, "NumDevices", NULL, &dataType, (PUCHAR)&cardsFound, &dataLength) != ERROR_SUCCESS) cardsFound = 0; else { dataLength = cardsFound * sizeof(TPCI_COMMON_CONFIG); RegQueryValueEx(key, "PCICommonConfig", NULL, &dataType, (PUCHAR)buf, &dataLength); } for (int count = 0; count < cardsFound; count++) { if (buf[count].VendorID == 0x494f && buf[count].DeviceID == 0x0f01) { cardAddresses[numCards] = buf[count].BaseAddresses[2] & 0xFFF8; sprintf(cardString, "%d: LPCI-IIRO-8", numCards); m_deviceList.AddString(cardString); numCards++; } } if (numCards) { m_addrEdit.SetReadOnly(true); } cardAddresses[numCards] = 0x300; m_deviceList.AddString("104-IIRO-8 (Enter Base Address below)"); m_deviceList.SetCurSel(0); sprintf(cardString, "%x", cardAddresses[0]); m_addrEdit.SetWindowText(cardString); } void CSample0Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSample0Dlg) DDX_Control(pDX, IDC_GO_BTN, m_goBtn); DDX_Control(pDX, IDC_ADDR_EDIT, m_addrEdit); DDX_Control(pDX, IDC_DEVICE_LIST, m_deviceList); DDX_Control(pDX, IDC_OUTPUT0, m_output0); DDX_Control(pDX, IDC_OUTPUT1, m_output1); DDX_Control(pDX, IDC_OUTPUT2, m_output2); DDX_Control(pDX, IDC_OUTPUT3, m_output3); DDX_Control(pDX, IDC_OUTPUT4, m_output4); DDX_Control(pDX, IDC_OUTPUT5, m_output5); DDX_Control(pDX, IDC_OUTPUT6, m_output6); DDX_Control(pDX, IDC_OUTPUT7, m_output7); DDX_Control(pDX, IDC_INPUT0, m_input0); DDX_Control(pDX, IDC_INPUT1, m_input1); DDX_Control(pDX, IDC_INPUT2, m_input2); DDX_Control(pDX, IDC_INPUT3, m_input3); DDX_Control(pDX, IDC_INPUT4, m_input4); DDX_Control(pDX, IDC_INPUT5, m_input5); DDX_Control(pDX, IDC_INPUT6, m_input6); DDX_Control(pDX, IDC_INPUT7, m_input7); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSample0Dlg, CDialog) //{{AFX_MSG_MAP(CSample0Dlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_OUTPUT0, OnOutput0) ON_BN_CLICKED(IDC_OUTPUT1, OnOutput1) ON_BN_CLICKED(IDC_OUTPUT2, OnOutput2) ON_BN_CLICKED(IDC_OUTPUT3, OnOutput3) ON_BN_CLICKED(IDC_OUTPUT4, OnOutput4) ON_BN_CLICKED(IDC_OUTPUT5, OnOutput5) ON_BN_CLICKED(IDC_OUTPUT6, OnOutput6) ON_BN_CLICKED(IDC_OUTPUT7, OnOutput7) ON_CBN_SELCHANGE(IDC_DEVICE_LIST, OnSelchangeDeviceList) ON_BN_CLICKED(IDC_GO_BTN, OnGoBtn) ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSample0Dlg message handlers BOOL CSample0Dlg::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 GetDeviceInfo(); //the Bitmaps need to be loaded from the resource file OpenBmp.LoadBitmap(IDB_OPEN); ClosedBmp.LoadBitmap(IDB_CLOSED); //stuffing the inputs and outputs into arrays makes them much easier //to use later inArray[0] = &m_input0; inArray[1] = &m_input1; inArray[2] = &m_input2; inArray[3] = &m_input3; inArray[4] = &m_input4; inArray[5] = &m_input5; inArray[6] = &m_input6; inArray[7] = &m_input7; outArray[0] = &m_output0; outArray[1] = &m_output1; outArray[2] = &m_output2; outArray[3] = &m_output3; outArray[4] = &m_output4; outArray[5] = &m_output5; outArray[6] = &m_output6; outArray[7] = &m_output7; inByte = outByte = 0; return TRUE; // return TRUE unless you set the focus to a control } // 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 CSample0Dlg::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 CSample0Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CSample0Dlg::OnOutput0() { // TODO: Add your control notification handler code here outByte ^= 0x1; m_output0.SetBitmap(outByte & 0x1 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput1() { // TODO: Add your control notification handler code here outByte ^= 0x2; m_output1.SetBitmap(outByte & 0x2 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput2() { // TODO: Add your control notification handler code here outByte ^= 0x4; m_output2.SetBitmap(outByte & 0x4 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput3() { // TODO: Add your control notification handler code here outByte ^= 0x8; m_output3.SetBitmap(outByte & 0x8 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput4() { // TODO: Add your control notification handler code here outByte ^= 0x10; m_output4.SetBitmap(outByte & 0x10 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput5() { // TODO: Add your control notification handler code here outByte ^= 0x20; m_output5.SetBitmap(outByte & 0x20 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput6() { // TODO: Add your control notification handler code here outByte ^= 0x40; m_output6.SetBitmap(outByte & 0x40 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnOutput7() { // TODO: Add your control notification handler code here outByte ^= 0x80; m_output7.SetBitmap(outByte & 0x80 ? ClosedBmp : OpenBmp); } void CSample0Dlg::OnSelchangeDeviceList() { // TODO: Add your control notification handler code here char editString[8]; if (m_deviceList.GetCurSel() == numCards - 1) //ISA option selected m_addrEdit.SetReadOnly(false); else m_addrEdit.SetReadOnly(true); sprintf(editString, "%.04x", cardAddresses[m_deviceList.GetCurSel()]); m_addrEdit.SetWindowText(editString); } void CSample0Dlg::OnGoBtn() { // TODO: Add your control notification handler code here char buf[8]; m_goBtn.GetWindowText(buf, 8); if (buf[0] == 'G') { m_addrEdit.GetWindowText(buf, 8); sscanf(buf, "%x", &baseAddress); m_goBtn.SetWindowText("STOP"); SetTimer(1, 1000, NULL); } else { KillTimer(1); m_goBtn.SetWindowText("GO"); } } void CSample0Dlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default OutPortB(baseAddress, outByte); inByte = InPortB(baseAddress + 1); for (int count = 0; count < 8; count++) inArray[count]->SetBitmap((inByte >> count) & 0x1 ? ClosedBmp : OpenBmp); CDialog::OnTimer(nIDEvent); }