📄 dcmot.cpp
字号:
// Dcmot.cpp : implementation file
//
#include "stdafx.h"
#include "pctest.h"
#include "Dcmot.h"
#include "adc.h"
#include "address.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern PCHAR mDynVxDName ;
/////////////////////////////////////////////////////////////////////////////
// Dcmot dialog
Dcmot::Dcmot(CWnd* pParent /*=NULL*/)
: CDialog(Dcmot::IDD, pParent)
{
//{{AFX_DATA_INIT(Dcmot)
// NOTE: the ClassWizard will add member initialization here
m_inputvolt = 0.0f;
//}}AFX_DATA_INIT
hDevice=NULL;
hDevice1=NULL;
d0=0;
flagt0=0;
}
void Dcmot::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Dcmot)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Text(pDX, IDC_EDIT1, m_inputvolt);
DDV_MinMaxFloat(pDX, m_inputvolt, 0.f, 255.f);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Dcmot, CDialog)
//{{AFX_MSG_MAP(Dcmot)
// NOTE: the ClassWizard will add message map macros here
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dcmot message handlers
BOOL Dcmot::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if(hDevice==NULL)
{
hDevice = CreateFile(mDynVxDName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
AfxMessageBox("请检查板卡和驱动程序");
CDialog::OnCancel();
return FALSE;
}
W_AD=(Write_AD*)malloc(sizeof(Write_AD));
}
// BOOL status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08321,
// NULL,
// 0x0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=io_08321;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08322,
// NULL,
// 0x0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=io_08322;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//+++++++++++++init the 8253 T0++++++++++++++++
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_8253_type,
// NULL,
// 0x10,
// NULL,
// NULL);
W_AD->Data=0x10;
W_AD->Address=IC_8253_type;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_8253_0,
// NULL,
// 0x01,
// NULL,
// NULL);
W_AD->Data=0x01;
W_AD->Address=IC_8253_0;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//+++++++++++++++++++++++++++++++++++++++++++++
// status = DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_ADC0809,
// NULL,
// 0x0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=IC_ADC0809;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
return TRUE;
}
void Dcmot::OnButton1()
{
// TODO: Add your control notification handler code here
SetTimer(1,100,NULL);
}
void Dcmot::OnCancel()
{
// TODO: Add extra cleanup here
KillTimer(1);
CloseHandle(hDevice);
CDialog::OnCancel();
}
void Dcmot::dianji()
{
flagt0=0;
BYTE data,d_t0;
// BOOL status = DeviceIoControl(
// hDevice,
// DIOC_IO_READ,
// pci,
// IC_ADC0809,
// &data,
// 0,
// NULL,
// NULL);
BYTE OffSet=IC_ADC0809;
BOOL status = DeviceIoControl(
hDevice,
IOCTL_IOR,
&OffSet,
sizeof(BYTE),
&data,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08321,
// NULL,
// data,
// NULL,
// NULL);
W_AD->Data=data;
W_AD->Address=io_08321;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08322,
// NULL,
// 0x0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=io_08322;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//+++++++read 8253T0++++++++++++
// status = DeviceIoControl(
// hDevice,
// DIOC_IO_READ,
// pci,
// IC_8253_0,
// &d_t0,
// 0,
// NULL,
// NULL);
OffSet=IC_8253_0;
status = DeviceIoControl(
hDevice,
IOCTL_IOR,
&OffSet,
sizeof(BYTE),
&d_t0,
0,
&nRet,
NULL);
if (d_t0==d0)
m_inputvolt=0;
else
m_inputvolt=(100-(float)d_t0)*60;
// status=DeviceIoControl( //重写计数值1
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_8253_0,
// NULL,
// 0x01,
// NULL,
// NULL);
W_AD->Data=0x01;
W_AD->Address=IC_8253_0;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//++++++++++++++++++++++++++++++++++++
// status = DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_ADC0809,
// NULL,
// 0X0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=IC_ADC0809;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
UpdateData(FALSE);
}
void Dcmot::OnTimer(UINT nIDEvent)
{
if (flagt0==0)
dianji1();
else
dianji();
CDialog::OnTimer(nIDEvent);
}
void Dcmot::dianji1()
{
flagt0=1;
BYTE data,d_t0;
// BOOL status = DeviceIoControl(
// hDevice,
// DIOC_IO_READ,
// pci,
// IC_ADC0809,
// &data,
// 0,
// NULL,
// NULL);
BYTE OffSet=IC_ADC0809;
BOOL status = DeviceIoControl(
hDevice,
IOCTL_IOR,
&OffSet,
sizeof(BYTE),
&data,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08321,
// NULL,
// data,
// NULL,
// NULL);
W_AD->Data=data;
W_AD->Address=io_08321;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
// status=DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// io_08322,
// NULL,
// 0x0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=io_08322;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//+++++++read 8253T0++++++++++++
// status = DeviceIoControl(
// hDevice,
// DIOC_IO_READ,
// pci,
// IC_8253_0,
// &d_t0,
// 0,
// NULL,
// NULL);
OffSet=IC_8253_0;
status = DeviceIoControl(
hDevice,
IOCTL_IOR,
&OffSet,
sizeof(BYTE),
&d_t0,
0,
&nRet,
NULL);
d0=d_t0;
// status=DeviceIoControl( //重写计数值100
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_8253_0,
// NULL,
// 0x64,
// NULL,
// NULL);
W_AD->Data=0x64;
W_AD->Address=IC_8253_0;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
//++++++++++++++++++++++++++++++++++++
// status = DeviceIoControl(
// hDevice,
// DIOC_IO_WRITE,
// pci,
// IC_ADC0809,
// NULL,
// 0X0,
// NULL,
// NULL);
W_AD->Data=0x0;
W_AD->Address=IC_ADC0809;
DeviceIoControl(
hDevice,
IOCTL_IOW,
W_AD,
sizeof(W_AD)+1,
NULL,
0,
&nRet,
NULL);
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -