📄 switchsignal.cpp
字号:
// SwitchSignal.cpp: implementation of the CSwitchSignal class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SwitchSignal.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include"OpenByInterface.h"
#include <winioctl.h>
#include "PCI9052Demoioctl.h"
#include "PCI9052DemoDeviceinterface.h"
#define IOCTL_INBUF_SIZE 512
#define IOCTL_OUTBUF_SIZE 512
GUID ClassGuid=PCI9052Demo_CLASS_GUID;
CSwitchSignal::CSwitchSignal()
{
CString s;
DWORD Error;
hDevice=INVALID_HANDLE_VALUE;
hDevice = OpenByInterface( &ClassGuid, 0, &Error);
if (hDevice == INVALID_HANDLE_VALUE)
{
s.Format("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError());
AfxMessageBox(s);;
Exit();
}
}
CSwitchSignal::~CSwitchSignal()
{
CloseIfOpen();
}
BOOL CSwitchSignal::CloseIfOpen()
{
if (hDevice != INVALID_HANDLE_VALUE)
{
// Close the handle to the driver
if (!CloseHandle(hDevice))
{
CString s;
s.Format("ERROR: CloseHandle returns %0x.\n", GetLastError());
AfxMessageBox(s);
return FALSE;
}
hDevice = INVALID_HANDLE_VALUE;
}
return TRUE;
}
BOOL CSwitchSignal::Exit()
{
CString s;
s.Format("Exiting...\n\n");
AfxMessageBox(s);
if(!CloseIfOpen())
return FALSE;
return TRUE;
}
BOOL CSwitchSignal::CauseUser01ToLow()
{
CHAR bufInput[IOCTL_INBUF_SIZE]; // Input to device
CHAR bufOutput[IOCTL_OUTBUF_SIZE]; // Output from device
ULONG nOutput; // Count written to bufOutput
if (!DeviceIoControl(hDevice,
PCI9052Demo_IOCTL_800,
bufInput,
IOCTL_INBUF_SIZE,
bufOutput,
IOCTL_OUTBUF_SIZE,
&nOutput,
NULL)
)
{
CString s;
s.Format("ERROR: DeviceIoControl returns %0x.", GetLastError());
AfxMessageBox(s);
Exit();
return FALSE;
}
return TRUE;
}
BOOL CSwitchSignal::CauseUser01ToHigh()
{
CHAR bufInput[IOCTL_INBUF_SIZE]; // Input to device
CHAR bufOutput[IOCTL_OUTBUF_SIZE]; // Output from device
ULONG nOutput; // Count written to bufOutput
if (!DeviceIoControl(hDevice,
PCI9052Demo_IOCTL_801,
bufInput,
IOCTL_INBUF_SIZE,
bufOutput,
IOCTL_OUTBUF_SIZE,
&nOutput,
NULL)
)
{
CString s;
s.Format("ERROR: DeviceIoControl returns %0x.", GetLastError());
AfxMessageBox(s);
Exit();
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -