我的畢業設計需要對采集到的信號進行計數,然后求出信號之間的時間差。(比如程式計了10個數,時間為4S)。因為計數采集用的是資料采集卡,商家給了一個寫好的計數程式,然后,學渣就不知道該怎么修改這個程式對它定時了。請大神幫我一把,讓學弟順利畢業吧~~~~
非常感謝!下面是提供的計數程式:
// IO_countDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IO_count.h"
#include "IO_countDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static int usb_open=0;
static unsigned char io_out[8];
extern "C" __declspec(dllimport) int OpenUsb(void);
extern "C" __declspec(dllimport) int CloseUsb(void);
extern "C" __declspec(dllimport) int GetDeviceCount(void);
extern "C" __declspec(dllimport) void SetCurDevice(int Devicenum);
extern "C" __declspec(dllimport) int DO_SOFT(unsigned char chan,unsigned char state);
extern "C" __declspec(dllimport) unsigned char DI_Soft(void);
extern "C" __declspec(dllimport) int AD_single(int chan,int gain,float* adResult);
extern "C" __declspec(dllimport) int AD_continu(int chan,int gain,int Num_Sample,int Rate_Sample,float *databuf);
extern "C" __declspec(dllimport) int MAD_continu(int chan_first,int chan_last,int *gainList,int Num_Sample,int Rate_Sample,float *mad_data);
extern "C" __declspec(dllimport) int DA_sigle_out(int chan,int value);
extern "C" __declspec(dllimport) int DA_DATA_SEND(int chan,int Num,int *databuf);
extern "C" __declspec(dllimport) int DA_scan_out(int chan,int Freq,int scan_Num);
extern "C" __declspec(dllimport) int PWM_Out(int chan,int Freq,int DutyCycle,int mod);
extern "C" __declspec(dllimport) int PWM_In(int mod);
extern "C" __declspec(dllimport) int COUNT(int mod);
extern "C" __declspec(dllimport) int Read_PWM_In(float* Freq, int* DutyCycle);
extern "C" __declspec(dllimport) int Read_COUNT(int* count);
/////////////////////////////////////////////////////////////////////////////
// CIO_countDlg dialog
CIO_countDlg::CIO_countDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIO_countDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIO_countDlg)
m_in1 = FALSE;
m_in2 = FALSE;
m_in3 = FALSE;
m_in4 = FALSE;
m_in5 = FALSE;
m_in6 = FALSE;
m_in7 = FALSE;
m_in8 = FALSE;
m_out1 = FALSE;
m_out2 = FALSE;
m_out3 = FALSE;
m_out4 = FALSE;
m_out5 = FALSE;
m_out6 = FALSE;
m_out7 = FALSE;
m_out8 = FALSE;
m_count = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CIO_countDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIO_countDlg)
DDX_Check(pDX, IDC_in1, m_in1);
DDX_Check(pDX, IDC_in2, m_in2);
DDX_Check(pDX, IDC_in3, m_in3);
DDX_Check(pDX, IDC_in4, m_in4);
DDX_Check(pDX, IDC_in5, m_in5);
DDX_Check(pDX, IDC_in6, m_in6);
DDX_Check(pDX, IDC_in7, m_in7);
DDX_Check(pDX, IDC_in8, m_in8);
DDX_Check(pDX, IDC_out1, m_out1);
DDX_Check(pDX, IDC_out2, m_out2);
DDX_Check(pDX, IDC_out3, m_out3);
DDX_Check(pDX, IDC_out4, m_out4);
DDX_Check(pDX, IDC_out5, m_out5);
DDX_Check(pDX, IDC_out6, m_out6);
DDX_Check(pDX, IDC_out7, m_out7);
DDX_Check(pDX, IDC_out8, m_out8);
DDX_Text(pDX, IDC_count, m_count);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIO_countDlg, CDialog)
//{{AFX_MSG_MAP(CIO_countDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_openusb, Onopenusb)
ON_BN_CLICKED(IDC_button_count, Onbuttoncount)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIO_countDlg message handlers
BOOL CIO_countDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CIO_countDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CIO_countDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CIO_countDlg::Onopenusb()
{
// TODO: Add your control notification handler code here
if(usb_open==0)
{
if(!OpenUsb())
{
usb_open=1;
m_nTimer=SetTimer(1,100,NULL);
this->SetDlgItemText(ID_openusb,"關閉設備");
}
}
else
{
if(!CloseUsb())
{
usb_open=0;
KillTimer(m_nTimer);
this->SetDlgItemText(ID_openusb,"打開設備");
}
}
}
int count_enable=0;
void CIO_countDlg::Onbuttoncount()
{
// TODO: Add your control notification handler code here
if(usb_open==1)
{
if(count_enable==0)
{
count_enable=1;
this->SetDlgItemText(IDC_button_count,"停止");
COUNT(1);
}
else
{
count_enable=0;
this->SetDlgItemText(IDC_button_count,"運行");
COUNT(0);
}
}
}
void CIO_countDlg::OnCancel()
{
// TODO: Add extra cleanup here
CloseUsb();
CDialog::OnCancel();
}
void CIO_countDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
UpdateData(true);
if(count_enable==1)
{
int count;
Read_COUNT(&count);
m_count=count;
}
unsigned char io_in=0;
io_in=DI_Soft();
if(io_in&(0x1<<0))
{
m_in1 =true;
}
else
{
m_in1 =false;
}
if(io_in&(0x1<<1))
{
m_in2 =true;
}
else
{
m_in2 =false;
}
if(io_in&(0x1<<2))
{
m_in3 =true;
}
else
{
m_in3 =false;
}
if(io_in&(0x1<<3))
{
m_in4 =true;
}
else
{
m_in4 =false;
}
if(io_in&(0x1<<4))
{
m_in5 =true;
}
else
{
m_in5 =false;
}
if(io_in&(0x1<<5))
{
m_in6 =true;
}
else
{
m_in6 =false;
}
if(io_in&(0x1<<6))
{
m_in7 =true;
}
else
{
m_in7 =false;
}
if(io_in&(0x1<<7))
{
m_in8 =true;
}
else
{
m_in8 =false;
}
if(m_out1)
{
DO_SOFT(0,1);
}
else
{
DO_SOFT(0,0);
}
if(m_out2)
{
DO_SOFT(1,1);
}
else
{
DO_SOFT(1,0);
}
if(m_out3)
{
DO_SOFT(2,1);
}
else
{
DO_SOFT(2,0);
}
if(m_out4)
{
DO_SOFT(3,1);
}
else
{
DO_SOFT(3,0);
}
if(m_out5)
{
DO_SOFT(4,1);
}
else
{
DO_SOFT(4,0);
}
if(m_out6)
{
DO_SOFT(5,1);
}
else
{
DO_SOFT(5,0);
}
if(m_out7)
{
DO_SOFT(6,1);
}
else
{
DO_SOFT(6,0);
}
if(m_out8)
{
DO_SOFT(7,1);
}
else
{
DO_SOFT(7,0);
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
uj5u.com熱心網友回復:
其實看廠家提供給你的采集卡.H檔案和函式說明,比直接改這個程式要好很多,在看不太明白的時候參考一下這個程式就可以了uj5u.com熱心網友回復:
VC6.0?uj5u.com熱心網友回復:
是VC6.0uj5u.com熱心網友回復:
沒有廠家的SDK么轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/119870.html
標籤:基礎類
上一篇:學習第35天
下一篇:如何改變通用的列印控制元件
