为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

CVI源代码

2011-04-21 3页 doc 26KB 58阅读

用户头像

is_906974

暂无简介

举报
CVI源代码//***************************************************************************** // Labwindows/cvi8.5  虚拟简易示波器 // szlihongtao // 2010-07-29 //*****************************************************************************  #include #include #include    #include #inc...
CVI源代码
//***************************************************************************** // Labwindows/cvi8.5  虚拟简易示波器 // szlihongtao // 2010-07-29 //*****************************************************************************  #include #include #include    #include #include "虚拟简易示波器.h" //***************************************************************************** #define NUM_DIV    10    // X轴的分格数 #define SAMPLES_DIV   48    // X轴每格对应显示点数 #define SAMPLES_TOTAL  (NUM_DIV*SAMPLES_DIV)  // X轴的总的点数 //***************************************************************************** static int panelHandle; //***************************************************************************** int main (int argc, char *argv[]) {  if (InitCVIRTE (0, argv, 0) == 0)   return -1; /* out of memory */  if ((panelHandle = LoadPanel (0, "虚拟简易示波器.uir", PANEL)) < 0)   return -1;  DisplayPanel (panelHandle);  RunUserInterface ();  DiscardPanel (panelHandle);  return 0; } //***************************************************************************** int CVICALLBACK func_exit (int panel, int control, int event,   void *callbackData, int eventData1, int eventData2) {  switch (event)  {   case EVENT_COMMIT:    QuitUserInterface (0);    break;  }  return 0; } //***************************************************************************** int CVICALLBACK func_gen (int panel, int control, int event,   void *callbackData, int eventData1, int eventData2) {    double *arr;    double Amplitude;    int Number_of_Elements;    double Phase_Degrees;    double Number_of_Cycles;    double *Sine_Pattern;    double fx,fs,f;    double gain;    int sec_div;    int temp;              switch (event)  {   case EVENT_COMMIT:    {    Number_of_Elements=SAMPLES_TOTAL;    GetCtrlVal (panelHandle, PANEL_NUMERIC, &Amplitude); // 信号幅度    GetCtrlVal (panelHandle, PANEL_NUMERIC_2, &Phase_Degrees);// 初始相位    GetCtrlVal (panelHandle, PANEL_NUMERIC_3, &fx);   // 信号的原始频率    GetCtrlVal (panelHandle, PANEL_RINGDIAL_DIV, &sec_div); // 每格代表的时间        fs=Number_of_Elements*1000000.0/(double)(NUM_DIV*sec_div); // 采样频率            Sine_Pattern=malloc(Number_of_Elements*sizeof(double));   // 申请数组内存        #if 1      // 方法1     f=fx/fs; // Frequency of the resulting sine wave signal in normalized units of cycles/sample.     SineWave (Number_of_Elements, Amplitude,f,&Phase_Degrees,Sine_Pattern);    #else      // 方法2                f=Number_of_Elements*fx/fs;     // Number_of_Cycles,正弦波每个周期对应的点数     SinePattern (Number_of_Elements,Amplitude,Phase_Degrees,f,Sine_Pattern);    #endif   //---------------------------------------------------------------------------------     if (sec_div>=1000)   // 1ms     temp=0;    else if (sec_div>=100)     temp=1;    else     temp=0;     SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XPRECISION, temp);  // 小数点位数 //---------------------------------------------------------------------------------       gain=(double)sec_div/(double)SAMPLES_TOTAL;    if (sec_div>=1000)      // 1ms     gain/=100;    else if (sec_div>=100)   // 0.1ms     gain/=100;    else     gain*=10;         SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XAXIS_GAIN,gain); // X轴数字显示的放大倍数    SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_XDIVISIONS, NUM_DIV);  // X轴的分格数,总是10格,看起来好看一些     //---------------------------------------------------------------------------------       SetAxisScalingMode(panelHandle,PANEL_GRAPH,VAL_BOTTOM_XAXIS,VAL_MANUAL,0,SAMPLES_TOTAL);  // 设置X轴的最小值,最大值            DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, 1);        PlotY (panelHandle, PANEL_GRAPH, Sine_Pattern,Number_of_Elements, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);    free(Sine_Pattern);   // 释放内存    break;   }   }  return 0; } //***************************************************************************** //***************************************************************************** //*****************************************************************************
/
本文档为【CVI源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索