#pragma once
#include <assert.h>
class CIOMocker
{
public:
CIOMocker() : m_bOpen(FALSE)
{
srand((unsigned)time(NULL));
wsprintf(m_szDescription,_T("CAXA-CAPP-%03d"),1+rand()%999);
}
~CIOMocker() {}
// 获得设备的描述
LPCTSTR GetDescription() const
{
return m_szDescription;
}
// 打开设备,前提设备必须已经关闭;初始时设备为关闭状态
BOOL Open()
{
if (m_bOpen)
{
assert(!m_bOpen);
return TRUE;
}
m_bOpen = rand()%2;
return m_bOpen;
}
// 读取信号,前提设备必须已经打开
// 返回的第 0-7 bit 分别代表1-8路信号
DWORD Read()
{
if (!m_bOpen)
{
assert(m_bOpen);
return -1;
}
return rand() % 0x100;
}
// 关闭设备
void Close()
{
m_bOpen = FALSE;
}
private:
BOOL m_bOpen;
TCHAR m_szDescription[64];
#include <assert.h>
class CIOMocker
{
public:
CIOMocker() : m_bOpen(FALSE)
{
srand((unsigned)time(NULL));
wsprintf(m_szDescription,_T("CAXA-CAPP-%03d"),1+rand()%999);
}
~CIOMocker() {}
// 获得设备的描述
LPCTSTR GetDescription() const
{
return m_szDescription;
}
// 打开设备,前提设备必须已经关闭;初始时设备为关闭状态
BOOL Open()
{
if (m_bOpen)
{
assert(!m_bOpen);
return TRUE;
}
m_bOpen = rand()%2;
return m_bOpen;
}
// 读取信号,前提设备必须已经打开
// 返回的第 0-7 bit 分别代表1-8路信号
DWORD Read()
{
if (!m_bOpen)
{
assert(m_bOpen);
return -1;
}
return rand() % 0x100;
}
// 关闭设备
void Close()
{
m_bOpen = FALSE;
}
private:
BOOL m_bOpen;
TCHAR m_szDescription[64];
};
DWORD dwVal = dev.dwRead();
// signalVal[0] = (dwVal & 0x1 == 0) ? 0 : 1;
signalVal[0] = dwVal & 0x1;
signalVal[1] = dwVal & 0x2;
signalVal[2] = dwVal & 0x4;
signalVal[3] = dwVal & 0x8;
signalVal[4] = dwVal & 0x10;
signalVal[5] = dwVal & 0x20;
signalVal[6] = dwVal & 0x40;
signalVal[7] = dwVal & 0x80;
//信号有无,判断是否非0