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

📄 scope.c

📁 CVI教程,用于信号采集系统的多任务开发软件.学习简单,功能实用.
💻 C
字号:
#include <formatio.h>#include <ansi_c.h>/*  == Sample Oscilloscope Instrument Module =============================== */#include "scope.h"int scope_device_closed (void);int scope_invalid_integer_range (int, int, int, int);int scope_invalid_real_range (double, double, double, int);int scope_write_data (char *, int);int scope_err = 0;/* ========================================================================= */static int bd;static char cmd[100];static double ch1_volts_per_div;static double ch2_volts_per_div;static double sec_per_div;static int ch1_coupling;static int ch2_coupling;/* ========================================================================= */int CVIFUNC scope_init (int addr){  if (scope_invalid_integer_range (addr, 0, 30,  -1) != 0)    return scope_err;  if (addr != 1)  {    scope_err = 223;    return scope_err;  }  bd = 1;  ch1_volts_per_div = 1.0;  ch2_volts_per_div = 1.0;  ch1_coupling = 1;  ch2_coupling = 1;  sec_per_div = 0.001;  scope_err = 0;  return scope_err;}/* ========================================================================= */int CVIFUNC scope_close (void){  if (scope_device_closed () != 0)    {        scope_err = 223;        return scope_err;    }  bd = 0;  scope_err = 0;  return scope_err;}/* ========================================================================= */int CVIFUNC scope_config (int chan, double v_div, int coupling, double sec_div){  char *cou_name;  if (scope_device_closed () != 0)    return scope_err;  if (scope_invalid_integer_range (chan, 1, 2,  -1) != 0)    return scope_err;  if (scope_invalid_real_range (v_div, 0.01, 50.0,  -2) != 0)    return scope_err;  if (scope_invalid_integer_range (coupling, 0, 2,  -3) != 0)    return scope_err;  if (scope_invalid_real_range (sec_div, 0.001, 1.0,  -4) != 0)    return scope_err;  if (chan == 1)  {    ch1_volts_per_div = v_div;    ch1_coupling = coupling;  }  else  {    ch2_volts_per_div = v_div;    ch2_coupling = coupling;  }  sec_per_div = sec_div;  switch (coupling)  {  case 0:    cou_name = "AC";    break;  case 1:    cou_name = "DC";    break;  case 2:    cou_name = "GND";    break;  default:    return scope_err;  }  Fmt (cmd, "CH%d VOL:%f,COU:%s;HOR ASE:%f;", chan, v_div, cou_name, sec_div);  if (scope_write_data (cmd, NumFmtdBytes ()) != 0)    return  scope_err;  scope_err = 0;  return  scope_err;}/* ========================================================================= */int CVIFUNC scope_read_waveform (int sou, double wvfm[100], double *xin, double *xzero){  int i;  int coupling;  double offset;  double mult;  *xzero = 0.0;  coupling = 0;  mult = 0.0;  offset = 0.0;  if (scope_device_closed () != 0)    return scope_err;  if (scope_invalid_integer_range (sou, 1, 2,  -1) != 0)    return scope_err;  if (sou == 1)    coupling = ch1_coupling;  else    coupling = ch2_coupling;  if (coupling != 2)  {    if (sou == 1)      mult = 0.5/ch1_volts_per_div;    else      mult = 0.05/ch2_volts_per_div;    if (coupling == 1)      offset = 1;  }  Fmt (cmd, "DAT SOU:CH%d;CURV?", sou);  if (scope_write_data (cmd, NumFmtdBytes ()) != 0)    return scope_err;  if (sou == 1) {      i = 0;      while (i < 100)  {        wvfm[i] = mult * sin (2.0 * 3.14159 * (sec_per_div / 0.1) * (double)i) + (offset - 1);        i++;       }     }  else if (sou == 2) {    i = 0;    while (i < 100) {        wvfm[i] = mult * (((rand()/32767.0) * 2.0)- 1.0);        i++;        }  }  *xin = sec_per_div / 100.0;  *xzero = 0.0;  scope_err = 0;  return scope_err;}/* ========================================================================= */int scope_device_closed (void){  if (bd <= 0)    scope_err = 232;  else    scope_err = 0;  return scope_err;}/* ========================================================================= */int scope_invalid_integer_range (val, min, max, err_code)int val;int min;int max;int err_code;{  if (val < min || val > max)  {    scope_err = err_code;    return 1;  }  return 0;}/* ========================================================================= */int scope_invalid_real_range (val, min, max, err_code)double val;double min;double max;int err_code;{  if (val < min || val > max)  {    scope_err = err_code;    return 1;  }  return 0;}/* ========================================================================= */int scope_write_data (cmd, cnt)char *cmd;int cnt;{  /*       if (ibwrt (bd, cmd, cnt) <= 0)   */  /*           scope_err = 230;             */  /*       else                             */  scope_err = 0;  return scope_err;}

⌨️ 快捷键说明

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