⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad.cpp

📁 pci7222单片机的驱动程序
💻 CPP
字号:
// ad.cpp : implementation file
//

#include "stdafx.h"
#include "pci7222.h"
#include "ad.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CPci7222App theApp;
mPCH365_IO_REG mBaseAddr1;
//根据ch365dll.h头文件定义基地址变量
const dly=12000;
 
//设置延时的大小
/////////////////////////////////////////////////////////////////////////////
// ad dialog

ad::ad(CWnd* pParent /*=NULL*/)
	: CDialog(ad::IDD, pParent)
{
	//{{AFX_DATA_INIT(ad)
	m_fAD1 = 0.0f;
	m_fAD2 = 0.0f;
	m_fAD3 = 0.0f;
	m_fAD4 = 0.0f;
	m_fAD5 = 0.0f;
	m_fAD6 = 0.0f;
	m_fAD7 = 0.0f;
	m_fAD8 = 0.0f;
	m_fAD9 = 0.0f;
	m_fAD10 = 0.0f;
	m_Age = _T("");
	
	//}}AFX_DATA_INIT
	
}


void ad::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ad)
	
	DDX_Text(pDX, IDC_age, m_Age);
	
	DDX_Text(pDX, IDC_height, m_height);
    DDX_Text(pDX, IDC_weight, m_weight);
	DDX_Text(pDX, IDC_right1, m_fAD1);
	DDX_Text(pDX, IDC_right2, m_fAD2);
	DDX_Text(pDX, IDC_right3, m_fAD3);
	DDX_Text(pDX, IDC_right4, m_fAD4);
	DDX_Text(pDX, IDC_right5, m_fAD5);
	DDX_Text(pDX, IDC_left1, m_fAD6);
	DDX_Text(pDX, IDC_left2, m_fAD7);
	DDX_Text(pDX, IDC_left3, m_fAD8);
	DDX_Text(pDX, IDC_left4, m_fAD9);
	DDX_Text(pDX, IDC_left5, m_fAD10);

	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(ad, CDialog)
	//{{AFX_MSG_MAP(ad)
	ON_BN_CLICKED(IDC_AD_START, OnAdStart)
	ON_BN_CLICKED(IDC_AD_STOP, OnAdStop)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_save, OnWriteAccess)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_sex1, Onsex1)
	ON_BN_CLICKED(IDC_sex2, Onsex2)
	ON_BN_CLICKED(IDC_type1, Ontype1)
	ON_BN_CLICKED(IDC_type2, Ontype2)
    
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ad message handlers

BOOL ad::OnInitDialog() 
{
	CDialog::OnInitDialog();


	// TODO: Add extra initialization here
	m_fAD1 = 0.00f;
	m_fAD2 = 0.00f;
	m_fAD3 = 0.00f;
	m_fAD4 = 0.00f;
	m_fAD5 = 0.00f;
	m_fAD6 = 0.00f;
	m_fAD7 = 0.00f;
	m_fAD8 = 0.00f;
	m_fAD9 = 0.00f;
	m_fAD10 = 0.00f;
	m_fAD11 = 0.00f;
	/*m_fAD12 = 0.0f;
	m_fAD13 = 0.0f;
	m_fAD14 = 0.0f;
	m_fAD15 = 0.0f;
	m_fAD16 = 0.0f;
	m_iSD = -1;
	m_iRange = -1;
	m_fAD17 = 0.0f;
	m_fAD18 = 0.0f;
	m_fAD19 = 0.0f;
	m_fAD20 = 0.0f;
	m_fAD21 = 0.0f;
	m_fAD22 = 0.0f;
	m_fAD23 = 0.0f;
	m_fAD24 = 0.0f;
	m_fAD25 = 0.0f;
	m_fAD26 = 0.0f;
	m_fAD27 = 0.0f;
	m_fAD28 = 0.0f;
	m_fAD29 = 0.0f;
	m_fAD30 = 0.0f;
	m_fAD31 = 0.0f;
	m_fAD32 = 0.0f;
    m_iSD=0;
	m_iRange=1;*/
	UpdateData(false);
	GetDlgItem(IDC_AD_STOP)->EnableWindow(FALSE);
	return TRUE; 
	              // EXCEPTION: OCX Property Pages should return FALSE
	////////////////////////////////////////数据库操作/////////////////////////////////	
	m_pRecordset.CreateInstance(__uuidof(Recordset)); 
		try
	{
			
		m_pRecordset->Open("SELECT * FROM resultable",                // 查询resultable表中所有字段
							_variant_t((IDispatch*)theApp.m_pConnection,true),	 // 获取库接库的IDispatch指针
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
		//	m_pRecordset=m_pConnection->Execute("INSERT INTO resultable (age) values('12')",&RecordsAffected,adCmdText);

	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}



void ad::OnAdStart() 
{
	// TODO: Add your control notification handler code here
	SetTimer(2,800,NULL);
	GetDlgItem(IDC_AD_STOP)->EnableWindow(true);
	GetDlgItem(IDC_AD_START)->EnableWindow(false);
}

void ad::OnAdStop() 
{
	// TODO: Add your control notification handler code here
	KillTimer(2);
	GetDlgItem(IDC_AD_STOP)->EnableWindow(false);
	GetDlgItem(IDC_AD_START)->EnableWindow(true);
}

void ad::OnExit() 
{
	// TODO: Add your control notification handler code here
    //	m_pRecordset->Close();
//	m_pRecordset = NULL;
	
	
	OnOK();
}

void ad::OnTimer(UINT nIDEvent) 
{
	m_iRange=0;
	// TODO: Add your message handler code here and/or call default
	UCHAR cByte1,cByte2;
	float data[32];
	int k,i;
	float b,c;
	switch(m_iRange)
	{
	case 0:
		b=(float)5.0/4095;
		c=0;
		break;
	case 1:
		b=(float)10.0/4095;
		c=0;
		break;
	case 2:
		b=(float)10.0/4095;
		c=5;
		break;
	case 3:
		b=(float)20.0/4095;
		c=10;
		break;
	}
	
	for(i=0;i<32;i++)
	{
		CH365mWriteIoByte(0,&mBaseAddr1->mCh365IoPort[0],i);
		//送AD通道
		for(k=0;k<dly;k++);
		CH365mWriteIoByte(0,&mBaseAddr1->mCh365IoPort[1],0);
		//启动AD转换
		for(k=0;k<dly;k++);
		CH365mReadIoByte( 0, &mBaseAddr1->mCh365IoPort[2], &cByte1 );
		//读AD数据低8位
		CH365mReadIoByte( 0, &mBaseAddr1->mCh365IoPort[3], &cByte2 );
		//读AD数据高4位
		data[i]=(float)(cByte2&15)*256+cByte1;
	}

		m_fAD1=data[0]*b-c;
		m_fAD2=data[1]*b-c;
		m_fAD3=data[2]*b-c;
		m_fAD4=data[3]*b-c;
		m_fAD5=data[4]*b-c;
		m_fAD6=data[5]*b-c;
		m_fAD7=data[6]*b-c;
		m_fAD8=data[7]*b-c;
		m_fAD9=data[8]*b-c;
		m_fAD10=data[9]*b-c;
		/*m_fAD11=data[10]*b-c;
		m_fAD12=data[11]*b-c;
		m_fAD13=data[12]*b-c;
		m_fAD14=data[13]*b-c;
		m_fAD15=data[14]*b-c;
		m_fAD16=data[15]*b-c;
		m_fAD17=data[16]*b-c;
		m_fAD18=data[17]*b-c;
		m_fAD19=data[18]*b-c;
		m_fAD20=data[19]*b-c;
		m_fAD21=data[20]*b-c;
		m_fAD22=data[21]*b-c;
		m_fAD23=data[22]*b-c;
		m_fAD24=data[23]*b-c;
		m_fAD25=data[24]*b-c;
		m_fAD26=data[25]*b-c;
		m_fAD27=data[26]*b-c;
		m_fAD28=data[27]*b-c;
		m_fAD29=data[28]*b-c;
		m_fAD30=data[29]*b-c;
		m_fAD31=data[30]*b-c;
		m_fAD32=data[31]*b-c;*/
		

	UpdateData(false);

	CDialog::OnTimer(nIDEvent);
}

void ad::Onsex1() 
{
	// TODO: Add your control notification handler code here
	    m_sex="男";
	    
  }

void ad::Onsex2() 
{
	// TODO: Add your control notification handler code here
	   m_sex="女";
	    
  }


void ad::Ontype1() 
{
	// TODO: Add your control notification handler code here
	m_type="体力劳动";
}

void ad::Ontype2() 
{
	// TODO: Add your control notification handler code here
	m_type="脑力劳动";
}
	


void ad::OnWriteAccess() 
{	UpdateData();
_variant_t RecordsAffected;
CString  strQuery; 
strQuery.Format("INSERT INTO resultable (age,sex,height,weight,type,right1,right2,right3,right4,right5,left1,left2,left3,left4,left5) VALUES ('%s','%s','%s','%s','%s',%f,%f,%f,%f,%f,%f,%f,%f,%f,%f)",m_Age,m_sex,m_height,m_weight,m_type,m_fAD1,m_fAD2,m_fAD3,m_fAD4,m_fAD5,m_fAD6,m_fAD7,m_fAD8,m_fAD9,m_fAD10);

	if(m_weight == "" || m_Age == "" || m_weight== "")
	{
		AfxMessageBox("请输入正确信息!");
		return;
	}
		// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
	// 因为它有时会经常出现一些想不到的错误。
	try
	{
		theApp.m_pConnection->Execute((_bstr_t)strQuery,&RecordsAffected,adCmdText);

		// 写入各字段值
		//m_pRecordset-> AddNew();
		//m_pRecordset->PutCollect("Name", (_variant_t)m_Name);
		//m_pRecordset->PutCollect("age", _variant_t(m_Age));
		/*m_pRecordset->PutCollect("sex", _variant_t(m_sex));
		m_pRecordset->PutCollect("height", _variant_t(m_height));
		m_pRecordset->PutCollect("weight",_variant_t(m_weight));
		m_pRecordset->PutCollect("type", _variant_t(m_type));
		
	/*	m_pRecordset->PutCollect("right1", m_fAD1);
		m_pRecordset->PutCollect("right2", m_fAD2);
		m_pRecordset->PutCollect("right3", m_fAD3);
		m_pRecordset->PutCollect("right4", m_fAD4);
		m_pRecordset->PutCollect("right5", m_fAD5);
		m_pRecordset->PutCollect("left1", m_fAD6);
		m_pRecordset->PutCollect("left2", m_fAD7);
		m_pRecordset->PutCollect("left3", m_fAD8);
		m_pRecordset->PutCollect("left4", m_fAD9);
		m_pRecordset->PutCollect("left5", m_fAD10);
		//m_pRecordset->Update();*/

		AfxMessageBox("插入成功!");
      // m_pRecordset->Close();
//	m_pRecordset = NULL;
	
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}

}
//////////////////////////////////////////////////////////////////////////////
//名称:DestroyWindow
//功能:关闭对话框时清除工作
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.12.10
/////////////////////////////////////////////////////////////////////////////
/*BOOL ad::DestroyWindow() 
{
	// 关闭记录集
	m_pRecordset->Close();
	m_pRecordset = NULL;
	
	return CDialog::DestroyWindow();
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -