cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 2493|回复: 5

研华818L的采集卡疑问!

[复制链接]
发表于 2004-11-8 17:51:21 | 显示全部楼层 |阅读模式
我用的是研华818L的采集卡,下面是我编的一个DLL,但是在VC++下就是编译不能通过,
出错的地方是在(*arg3)->elt=arrayA这一句,大侠们救我一下!!!谢谢!!!
/* Call Library source file */
#include "extcode.h"
#include "hosttype.h"
#include "conio.h"
#include "stdlib.h"
/* Typedefs */
typedef struct {
        long dimSize;
        float elt[1];
        } TD1;
typedef TD1 **TD1Hdl;
_declspec(dllexport) void goal(unsigned short int *basea, long *samples, TD1
Hdl arg3);               //basea为板卡的基地址,sanmples为采用点数,,
_declspec(dllexport) void goal(unsigned short int *basea, long *samples, TD1
Hdl arg3)
        {
        /* Insert code here */
        short int dbyte;
        float value;
        short int i;
        float * arrayA;      
arrayA=(float *) calloc (*samples,sizeof(float));
        (*arg3)->dimSize=*samples;
        (*arg3)->elt=arrayA;
        for(i=0;i<*samples;i++)
        {
                _outp(*basea+1,0x00);     //这些为写和读板卡的端口
                _outp(*basea+2,0x00);
                _outp(*basea+0,0x00);
                while(_inp(*arg1+8)&0x00);
                dbyte=_inp(*basea+1)&0xff+(_inp(*basea+0)&0xf0)*256;
                value=(float)((dbyte)*10/4096-5);
            *arrayA=value;
                arrayA++;
        }
}
发表于 2004-11-10 17:11:50 | 显示全部楼层
<>楼上的兄弟,我也使用研华的pcl-818l卡,不过我用的是turbo-c语言</P><>我不会c++</P><>我把采集程序给你发过来,如果愿意,留下qq讨论,我的qq 9376724</P>
发表于 2004-11-10 17:19:28 | 显示全部楼层
<>呵呵 就是斑竹</P><>/*
     **********************************************************************
     *  Program     : ADTRIG.C                                            *
     *  Description : Program for PCL-818L pacer trigger A/D              *
     *                conversion with software data transfer.             *
     *  Revision    : 1.00 By  WangYong                                   *
     *  Date        : 3/11/2004            Harbin commercial university   *
     **********************************************************************
*/
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;process.h&gt;
#include &lt;dos.h&gt;
#include &lt;math.h&gt;
/*********************/
extern pcl818L(int, unsigned int *);
#define BASE 0x300            /* base address */
#define NUM  10000
#define door 1.5/1340         /* ???????????? */
FILE *fp;
unsigned int param[60];       /* If two boards installed, need to declare
                                 the second parameter array                */
unsigned int data[5000];     /* Conversion data buffer                   */
unsigned int far * dat;
main()
{</P><>       unsigned int i;
       float   *p,*str,num1;
       float   DataBuf,acc1,div,divisor1,divisor2;
       float   rate;
       float  s_time,t_unit;             /* sample time inteval*/
       char filename[10];      /* data file name */
       float wait;
       int k;
       clrscr() ;</P><P>       dat = data;              /* data=start address of 12bit sample data array  */
       param[0]  = 0;           /* Board number                           */
       param[1]  = BASE;        /* Base I/O address                       */
/*********************program Explanation***********************/
  printf("\n****This is a sample program by Advantech PCL-818l card***\n\n");</P><P>  /****************************set sample rate**************************/
re_enter:
       printf("please input sample rate(&lt;40KHz):");
      scanf("%f",&amp;rate);
      div=1000000L/rate;
       if(div&lt;25)           /****25=1M/40K******/
       {
     printf("invalid sample rate!!");
     goto re_enter;
       }
       divisor1=div/0xffff;
       if(divisor1&gt;2)           /* adjust c1 and c2 */
     { divisor1=divisor1+1;
       divisor2=div/divisor1;
     }
       else
    {
     divisor1=2;
     divisor2=div/divisor1;
     }
       printf("\n actural sample rate=%f Hz\n",1000000L/(divisor1*divisor2));</P><P>/****************************number of all sample***********************/
      printf("\nplease input the number of all sample (&gt;5000):");
   edt3:
     scanf("%f",&amp;num1);
     if (num1&lt;5000||num1&gt;20000)
     {
      printf("\nyou should input number between 5000 and 20000,please again\n");
      goto edt3;
      }
     printf("elapsed sample time will be =%f second",NUM*(divisor1*divisor2)/1000000L);</P><P>       param[5]  = divisor1;          /* Pacer rate = 1M / (div1*div2)   */
       param[6]  = divisor2;           /*  sample rate   */
       param[7]  = 0;            /* Trigger mode, 0 : pacer trigger        */
       param[10] = FP_OFF(dat);  /* Offset of A/D data buffer A            */
       param[11] = FP_SEG(dat);  /* Segment of A/D data buffer A           */
       param[12] = 0;            /* Data buffer B address, if not used,    */
       param[13] = 0;            /* must set to 0.                         */
       param[14] = NUM;           /* A/D conversion number                  */
       param[15] = 0;            /* A/D conversion start channel           */
       param[16] = 0;            /* A/D conversion stop channel            */
       param[17] = 0;            /* Overall gain code, 0 : +/- 5V          */</P><P>       /* param[18] = FP_OFF(gain_array);
          param[19] = FP_SEG(gain_array);  */</P><P>       /* param[45] : Error code
          param[46] : Return value 0
          param[47] : Return value 1 */</P><P>       pcl818L(3, param);        /* Func 3 : Hardware initialization       */
       if (param[45] != 0) {
            printf(" DRIVER INITIALIZATION FAILED !");
            exit(1);
            }</P><P>       pcl818L(4, param);        /* Func 4 : A/D initialization            */
       if (param[45] != 0) {
            printf(" A/D INITIALIZATION FAILED !");
            exit(1);
            }
  /********************control start sample*******************************/
  edt:
     printf("\n input wait time(from 1 to 100):");
     scanf("%f",&amp;wait);
     if(wait&lt;1||wait&gt;100)
    goto edt;</P><P>     wait=wait*5000;
     for(k=9;k&gt;0;k--)
      {
      delay(wait);
      printf("\r%d",k);
      }
     printf("\n start sample!\n");</P><P>       pcl818L(5, param);        /* Func 5 : "N" times of A/D trigger      */
       if (param[45] != 0) {
        printf(" A/D SOFTWARE DATA TRANSFER FAILED !");
        exit(1);
        }
/********************File control*****************************/
       printf("\nyou have succeed to sample!\n\n");
       printf("please input file name you want to store:");
       scanf("%s",filename);
       if((fp=fopen(filename,"w+"))==NULL)
    {
     printf("I can not open the file %s\n",filename);
     exit(0);
    }
     /*********************write  data  ***************************/
       s_time=(param[5]*param[6])*0.000001;
       t_unit=0.000001;                  /*******1/1M*************/
       str=calloc(NUM,sizeof(float));    /* allocation data buf*/
       p=str;
       for (i = 0; i &lt; param[14]; i++)
     {
        DataBuf = data<i> &amp; 0xFFF;
        DataBuf =(((5 - (-5)) * DataBuf / 4096) + (-5));
        /*
           (5 - (-5)) : A/D input range (-5V  to  5V)
           4096       : Full scale 12 bit A/D data
           DataBuf    : A/D input data
           (-5)       : A/D input range "-5" V
        */
        *p=DataBuf*door;
    fprintf(fp,"%f %6f\n",i*(s_time), *p);</P><P>        p++;
     }
     fclose(fp);
/***************************display file*******************************/
     p=str;
     for(i=0;i&lt;param[14];i++)
        {
     printf("\n time=%f  accoceloration= %6f",i*(s_time), *p);
         p++;
        }</P><P>     printf("\n\n file is OK!\n");
     printf("Pleased any key return\n\n");
     getch();</P><P>}
</P>
发表于 2004-11-10 17:28:06 | 显示全部楼层
<>不采用驱动,直接控制!</P><> /*'**********************************************************************
    '*                                                                    *
    '*  This demo program performs pacer triggered one A/D conversion  *
    '*  and program control data transfer without using the PCL-818L      *
    '*  driver.                                                           *
    '*                                                                    *
    '**********************************************************************
*/
#include &lt;stdio.h&gt;
#include &lt;dos.h&gt;
#include &lt;process.h&gt;
#include &lt;conio.h&gt;
#include &lt;stdlib.h&gt;
/******************/
#include &lt;math.h&gt;
#define BASE 0x300          /*base address*/
#define NUM 5000            /*build  buffers*/
#define DOOR 1.5/1340
FILE *fp;                   /*file*/
/*****************/</P><>char *gain_str[4]={"5V","2.5V","0.25V","0.625V"};
void main()
{
int status  ,s_end  ,start ,stop;
int dtl ,dth ,adl   ,adt ,c_reg ,s_ch_val ,r_ch;
int chv ,ch_gain[16];
int port,val, i, j,re_ctr;</P><P>/*********************/
  struct time time[1];
  float  *p,*str;  /*data buffer*/
  int k;    /*conunt*/
  char filename[10];   /*data file name*/
  int sec1;
  float sec_h,rate;
  float wait;
  int high_byte,low_byte,data1,data2,data,data_low,data_higt,turedate_low;
  float div,d1,d2,divisor1,divisor2;
   port=BASE;              /* Set I/O port base address */</P><P>  /********** STEP 1: INITIALIZE &amp; SELECT SOFTWARE TRIGGER *************/
val=0x73;      /*  INTE I2 I1 I0   X DMAE ST1 ST2 ||  ST1 ST2=1 1 for pacer trig */
outportb(port+9,val);               /* pacer trigger */
c_reg = inportb(port+9);
if (c_reg != val)
    {
     printf("PCL-818L hardware verification failed!\n");
     exit(0);
     }
else
     printf("\n**** you have set pcl818l for pacer trigger! ****");
outportb(port+8,1);                 /* Clear interrupt request  */
printf("\n***** Please set PCL-818L's jumper 7 (A/D IN) to + - 5 V *****\n\n");</P><P>/*  ******** STEP 2: READ A/D STATUS REGISTER **************************** */</P><P> status = inportb(port+8);
if ((status &amp; 0x20)==0x20)  /* check MUX bit of port 8 is 8_diff or 16_single */
     s_end = 1;          /* 16 single_ended    */
else
     s_end = 0;          /* 8 differential channels */</P><P>red
if(s_end==1)
    {
    printf("Enter start channel number &lt;0-15&gt;: ");
    scanf("%d",&amp;start);
    printf("Enter stop channel number &lt;0-15&gt;: ");
    scanf("%d",&amp;stop);
    }
else
    {
     printf("*****you have set pcl818 card for 8 differential  *****\n");
     printf("Enter start channel number &lt;0-7&gt;: ");
     scanf("%d",&amp;start);
     printf("Enter stop channel number &lt;0-7&gt;: ");
     scanf("%d",&amp;stop);
     }</P><P> if ((s_end==0) &amp; (stop&gt;7))
     {
     printf("Entered channel failed! Re-do!\n");
     goto redo;
     }</P><P> if ((s_end==1) &amp; (stop&gt;15))
     {
     printf("Entered channel failed! Re-do!\n");
     goto redo;
     }</P><P> if (start &gt; stop)
     {
     printf("Entered channel failed!\n");
     goto redo;
     }</P><P>/*********** STEP 3: SET A/D RANGE CODE *****************/</P><P> printf("\n************** A/D Range Code Table **************");
printf("\n*   0) +5V   1) +2.5V   2) +1.25V   3) +0.625V   *");
printf("\n**************************************************\n\n");</P><P> for(i=start; i&lt;=stop; i++)
    {
    printf("Enter range code &lt;0 -- 3&gt; for channel %d :",i);
re_enter_gain:
    scanf("%d",&amp;ch_gain<i>);
    if( ch_gain<i> &lt; 0 || ch_gain<i> &gt; 3 )
       {
         printf("Wrong code! Enter again: ");
         goto re_enter_gain;
       }
    outportb(port+2, i);       /* port+2 for MUX scan register ,i repare channel for next input range code */
    outportb(port+1, ch_gain<i>);  /* port+1 for A/D range control */
    printf("\n");
    }</P><P>/********* STEP 4: SET SCAN CHANNEL RANGE  ***********************/</P><P> s_ch_val=stop*16+start;      /* Set scan channel value */
outportb(port+2,s_ch_val);   /* before 4 bit for stop, after 4 bit for start channel */
r_ch = inportb(port+2);      /* Read back channel value */
if (r_ch != s_ch_val)
{
     printf("Scan channel setting failed!\n");
     exit(0);
}
delay(1);
printf("****Scan channel setting OK !****\n");
/********************************************/
re_enter:
printf ("Input time rate(&lt;40KHz): ");  /* up to 40K Hz With DMA */
            scanf ("%f",&amp;rate);
        div=2000000L/rate;        /* L is long integret */
        if (div &lt; 50)             /* rate must &lt; 50 0000  */
                {
            printf("Invalid time rate,please input again!\n");
                    goto re_enter;
                }
            divisor1=div/0xffff;
            if (divisor1 &gt; 2)       /*  adjust divisor1 &amp; divisor2 */
                {
                    divisor1=divisor1+1;
                    divisor2=div/divisor1;
                }
            else
                {
                    divisor1=2;
                    divisor2=div/divisor1;
                }
            d1=divisor1;
            d2=divisor2;
        printf ("\n\tTIMER RATE=%f Hz\n",2000000L/(divisor1*divisor2));</P><P>
/*------------------*/</P><P>           /* port+15 for counter control word*/
    outportb(port+13,d1);    /* Counter1 division 200 low byte */
    outportb(port+13,0);      /* CTR1 high byte */</P><P>    outportb(port+15,0xB4);   /* select CTR2,R/W LSB first then MSB */</P><P>        outportb(port+14,d2);    /* CTR2 division 200 low byte */
        outportb(port+14,0);</P><P> /************* FILE CONTROL ****************/
printf("input file name you want to store:");
scanf("%s",filename);
if((fp=fopen(filename,"w+"))==NULL)
{
  printf("I can not open the file %s\n",filename);
  exit(0);
}
   str=calloc(NUM,sizeof(float));
   p=str;
edt:
    printf("\nInput wait time (from 1 to 100) :");
    scanf("%f",&amp;wait);
    if(wait&lt;1||wait&gt;100)
       goto edt;
   wait=wait*5000;
for(k=9;k&gt;0;k--)
   {
    delay(wait);
    textcolor(13);
    printf("\r%d",k);
   }
  printf("\n start signal acquire !\n");</P><P>
  /*textcolor(0);
  /*  data2=0;
  /*  for (i=0;;)           /* get n data */
     /*   {
    /* outportb(port+10,0);     /* select A/D channel  */</P><P>/*reread1:
  /*  outportb(port+8,0);  /* clear interrupt request by write any value to port8*/
   /* outportb(port,0);  /* software A/D trigger start by write any value to BASE+0 */</P><P>   /* status = inport(port+8);     /* port+8 is status register,
   /*  if ((status&amp;0x10)==0x10)      /* check INT bit of port+8 is 1? */
        /*  goto reread1 ??        =1 display have data is ready */</P><P>    /*  high_byte=inportb(port+1);
     /* low_byte=inportb(port+0);
    /*  data1=high_byte*256+low_byte-2048;  /* story A/D data into array */
     /* data1=data1&gt;0? data1:-data1;         /* get | data1 | */
    /*  if((data2&gt;wait)&amp;&amp;(abs(data1-data2)&gt;100)) break;
    /*  data2=data1;</P><P>   /*}</P><P>/********* STEP 5: PERFORM SINGLE A/D CONVERSION  ***********/</P><P>  gettime(&amp;time[0]); /* count using time */</P><P> for(k=0;k&lt;NUM;k++)
  {
  reread:
    outportb(port+8,0);        /* clear interrupt request by write any value to port8*/
    outportb(port,0);          /* software A/D trigger start by write any value to BASE+0 */
    status = inport(port+8);   /* port+8 is status register,
    if ((status&amp;0x10)==0x10)
       goto reread;</P><P>    delay(1);
    date_low = inportb(port);
    date_high = inportb(port+1);
    turedate_low = date_low/16;   /* get befroe 4 bit of low , after 4 bit is delete*/
    data = data_high*16+truedata_low;
    chv = date_low-truedate_low*16;
    *p=data;
    p++;
}</P><P>    gettime(&amp;time[1]);
    sec1=time[1].ti_sec-time[0].ti_sec;
    sec_h=(time[1].ti_hund-time[0].ti_hund)/100;        /* ti_hund for 0.01 secend*/
    all_time=sec1+sec_h;
    time_interval=all_time/NUM;</P><P>    p=str;
    printf(" Frist A/D data = %f\n",*p);
    printf(" Current channel   = %d   A/D range = %-7s\n",chv, gain_str[ch_gain[chv]]);
    printf(" Next scan channel = %d\n",(status &amp; 0x0f));
    printf(" Start scan channel= %d\n",start);
    printf(" Stop scan channel = %d\n",stop);
    p=str;
    for(k=0;k&lt;NUM;k++)
     {
       fprintf(fp,"%f %6f\n",k*time_interval,(*p-2049)*DOOR);    /* is a value of 0v*/
       p++;                   /* write  data to file */
     }
    fclose(fp);
    printf("\n Acquire signal file is OK! \n");
    printf(" Pressed any key return\n\n");
   free(str);
   str=NULL;
   p=NULL;
   getch();
}</P><P></P>
 楼主| 发表于 2004-11-13 19:00:22 | 显示全部楼层
呵呵,谢谢啊![em23][em23][em31][em31]
发表于 2010-5-28 01:20:01 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-5-2 19:42 , Processed in 0.547243 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表