// DlgDIGIN.cpp : implementation file
//#include "stdafx.h"
#include "test.h"
#include "DlgDIGIN.h"
#include "..\\Include\UNO_IsaDIO.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void ErrorHandler(LONG lDrvHandle, DWORD dwErrCde, BOOL bClose);
/////////////////////////////////////////////////////////////////////////////
// CDlgDIGIN dialog
CDlgDIGIN::CDlgDIGIN(CWnd* pParent /*=NULL*/)
: CDialog(CDlgDIGIN::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgDIGIN)
m_bitValue = 0;
m_Image1 = _T("");
m_Image2 = _T("");
m_Image3 = _T("");
m_Image4 = _T("");
m_Image5 = _T("");
m_Image6 = _T("");
m_Image7 = _T("");
m_Image8 = _T("");
//}}AFX_DATA_INIT
}
void CDlgDIGIN::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgDIGIN)
DDX_Control(pDX, IDC_COMBO1, m_combo);
DDX_Text(pDX, IDC_EDIT1, m_bitValue);
DDX_Text(pDX, IDC_Image1, m_Image1);
DDX_Text(pDX, IDC_Image2, m_Image2);
DDX_Text(pDX, IDC_Image3, m_Image3);
DDX_Text(pDX, IDC_Image4, m_Image4);
DDX_Text(pDX, IDC_Image5, m_Image5);
DDX_Text(pDX, IDC_Image6, m_Image6);
DDX_Text(pDX, IDC_Image7, m_Image7);
DDX_Text(pDX, IDC_Image8, m_Image8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgDIGIN, CDialog)
//{{AFX_MSG_MAP(CDlgDIGIN)
ON_BN_CLICKED(IDC_BUTTONREADBIT, OnButtonreadbit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDlgDIGIN message handlers
void ErrorHandler(LONG lDrvHandle, DWORD dwErrCde, BOOL bClose)
{
TCHAR szErrMsg[180];

if (bClose) DeviceClose(&lDrvHandle);

GetErrorMessage(dwErrCde, szErrMsg);

}
//-------------------------------------------------------------------void CDlgDIGIN::OnButtonreadbit() 
{
// TODO: Add your control notification handler code here
USHORT bitNumber;  //the bit number to read
USHORT bitStatus =0; //value of the port to read
USHORT DiValue = 0;
CString str; //Step 1: Open device
errCde=DeviceOpen(0,&DeviceHandle); //Step2: Read port byte using read port byte function.
errCde = DioReadPortByte( DeviceHandle, 0, &DiValue );
if ( errCde != 0 )
{
if ( errCde == ResourceConflict && bFirst)
{
bFirst = false;
ErrorHandler( DeviceHandle, errCde, false );
}
else if ( errCde != ResourceConflict )
{

ErrorHandler( DeviceHandle, errCde, true );
}

}
         UpdateLED( DiValue ); //Step3: Read a specific bit by using read bit function.
     for (int i=0;i<=7;i++)
     {
 int n=m_combo.GetLBTextLen(i);
 bitNumber=(USHORT)m_combo.GetLBText(i,str.GetBuffer(n));
     }
errCde = DioReadBit( DeviceHandle, 0, bitNumber,  &bitStatus );
if ( errCde != 0 )
{
if ( errCde == ResourceConflict )
{
ErrorHandler( DeviceHandle, errCde, false );
}
else
{
ErrorHandler( DeviceHandle, errCde, true );
return;
}
}
m_bitValue=bitStatus;
 
}
//--------------------------------------------------------------------void CDlgDIGIN::OnCancel() 
{
// TODO: Add extra cleanup here
if (DeviceHandle!=0)
{
errCde = DeviceClose( &DeviceHandle );
if ( errCde != 0 )
{
ErrorHandler( DeviceHandle, errCde, false );
        }
}
CDialog::OnCancel();
}
//---------------------------------------------------------------------void CDlgDIGIN::UpdateLED(int DiValue)
{
int iShift;
iShift = 1; //CStatic *LED[8];
//={Image1,Image2,Image3,Image4,Image5,Image6,Image7,Image8}; CBitmap Image9,Image10;
    Image9.LoadBitmap(IDB_GREEN);
Image10.LoadBitmap(IDB_RED);
    //检查每一个数据输入口
CStatic *p1=(CStatic*)GetDlgItem(IDC_Image1);
    if ((DiValue&iShift)==iShift)
    {
p1->SetBitmap(Image9);
    }
else
{
p1->SetBitmap(Image10);
}
//Check next bit
    iShift = iShift * 2;
CStatic *p2=(CStatic*)GetDlgItem(IDC_Image2);
    if ((DiValue&iShift)==iShift)
    {
p2->SetBitmap(Image9);
    }
else
{
p2->SetBitmap(Image10);
}
    //Check next bit
    iShift = iShift * 2;
CStatic *p3=(CStatic*)GetDlgItem(IDC_Image3);
    if ((DiValue&iShift)==iShift)
    {
p3->SetBitmap(Image9);
    }
else
{
p3->SetBitmap(Image10);
}
//Check next bit
    iShift = iShift * 2;
}出现的错误
--------------------Configuration: test - Win32 Debug--------------------
Linking...
DlgDINOUT.obj : error LNK2005: "void __cdecl ErrorHandler(long,unsigned long,int)" (?ErrorHandler@@YAXJKH@Z) already defined in DlgDIGIN.obj
DlgDIGIN.obj : error LNK2001: unresolved external symbol _GetErrorMessage@8
DlgDINOUT.obj : error LNK2001: unresolved external symbol _GetErrorMessage@8
DlgDIGIN.obj : error LNK2001: unresolved external symbol _DeviceClose@4
DlgDINOUT.obj : error LNK2001: unresolved external symbol _DeviceClose@4
DlgDIGIN.obj : error LNK2001: unresolved external symbol _DioReadBit@16
DlgDIGIN.obj : error LNK2001: unresolved external symbol _DioReadPortByte@12
DlgDIGIN.obj : error LNK2001: unresolved external symbol _DeviceOpen@8
DlgDINOUT.obj : error LNK2001: unresolved external symbol _DioGetCurrentDOBit@16
DlgDINOUT.obj : error LNK2001: unresolved external symbol _DioWritePortByte@16
DlgDINOUT.obj : error LNK2001: unresolved external symbol _DioGetCurrentDOByte@12
Debug/test.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.test.exe - 12 error(s), 0 warning(s)