研华818L的采集卡疑问!
我用的是研华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;
} 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++;
}
}
<P>楼上的兄弟,我也使用研华的pcl-818l卡,不过我用的是turbo-c语言</P><P>我不会c++</P><P>我把采集程序给你发过来,如果愿意,留下qq讨论,我的qq 9376724</P> <P>呵呵 就是斑竹</P><P>/*
**********************************************************************
*Program : ADTRIG.C *
*Description : Program for PCL-818L pacer trigger A/D *
* conversion with software data transfer. *
*Revision : 1.00 ByWangYong *
*Date : 3/11/2004 Harbin commercial university *
**********************************************************************
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
#include <dos.h>
#include <math.h>
/*********************/
extern pcl818L(int, unsigned int *);
#define BASE 0x300 /* base address */
#define NUM10000
#define door 1.5/1340 /* ???????????? */
FILE *fp;
unsigned int param; /* If two boards installed, need to declare
the second parameter array */
unsigned int data; /* Conversion data buffer */
unsigned int far * dat;
main()
{</P><P> unsigned int i;
float *p,*str,num1;
float DataBuf,acc1,div,divisor1,divisor2;
float rate;
floats_time,t_unit; /* sample time inteval*/
char filename; /* data file name */
float wait;
int k;
clrscr() ;</P><P> dat = data; /* data=start address of 12bit sample data array*/
param= 0; /* Board number */
param= 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(<40KHz):");
scanf("%f",&rate);
div=1000000L/rate;
if(div<25) /****25=1M/40K******/
{
printf("invalid sample rate!!");
goto re_enter;
}
divisor1=div/0xffff;
if(divisor1>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 (>5000):");
edt3:
scanf("%f",&num1);
if (num1<5000||num1>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= divisor1; /* Pacer rate = 1M / (div1*div2) */
param= divisor2; /*sample rate */
param= 0; /* Trigger mode, 0 : pacer trigger */
param = FP_OFF(dat);/* Offset of A/D data buffer A */
param = FP_SEG(dat);/* Segment of A/D data buffer A */
param = 0; /* Data buffer B address, if not used, */
param = 0; /* must set to 0. */
param = NUM; /* A/D conversion number */
param = 0; /* A/D conversion start channel */
param = 0; /* A/D conversion stop channel */
param = 0; /* Overall gain code, 0 : +/- 5V */</P><P> /* param = FP_OFF(gain_array);
param = FP_SEG(gain_array);*/</P><P> /* param : Error code
param : Return value 0
param : Return value 1 */</P><P> pcl818L(3, param); /* Func 3 : Hardware initialization */
if (param != 0) {
printf(" DRIVER INITIALIZATION FAILED !");
exit(1);
}</P><P> pcl818L(4, param); /* Func 4 : A/D initialization */
if (param != 0) {
printf(" A/D INITIALIZATION FAILED !");
exit(1);
}
/********************control start sample*******************************/
edt:
printf("\n input wait time(from 1 to 100):");
scanf("%f",&wait);
if(wait<1||wait>100)
goto edt;</P><P> wait=wait*5000;
for(k=9;k>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 != 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);
}
/*********************writedata***************************/
s_time=(param*param)*0.000001;
t_unit=0.000001; /*******1/1M*************/
str=calloc(NUM,sizeof(float)); /* allocation data buf*/
p=str;
for (i = 0; i < param; i++)
{
DataBuf = data<i> & 0xFFF;
DataBuf =(((5 - (-5)) * DataBuf / 4096) + (-5));
/*
(5 - (-5)) : A/D input range (-5Vto5V)
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<param;i++)
{
printf("\n time=%faccoceloration= %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> <P>不采用驱动,直接控制!</P><P> /*'**********************************************************************
'* *
'*This demo program performs pacer triggered one A/D conversion*
'*and program control data transfer without using the PCL-818L *
'*driver. *
'* *
'**********************************************************************
*/
#include <stdio.h>
#include <dos.h>
#include <process.h>
#include <conio.h>
#include <stdlib.h>
/******************/
#include <math.h>
#define BASE 0x300 /*base address*/
#define NUM 5000 /*buildbuffers*/
#define DOOR 1.5/1340
FILE *fp; /*file*/
/*****************/</P><P>char *gain_str={"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;
int port,val, i, j,re_ctr;</P><P>/*********************/
struct time time;
float*p,*str;/*data buffer*/
int k; /*conunt*/
char filename; /*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 & 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 & 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 <0-15>: ");
scanf("%d",&start);
printf("Enter stop channel number <0-15>: ");
scanf("%d",&stop);
}
else
{
printf("*****you have set pcl818 card for 8 differential*****\n");
printf("Enter start channel number <0-7>: ");
scanf("%d",&start);
printf("Enter stop channel number <0-7>: ");
scanf("%d",&stop);
}</P><P> if ((s_end==0) & (stop>7))
{
printf("Entered channel failed! Re-do!\n");
goto redo;
}</P><P> if ((s_end==1) & (stop>15))
{
printf("Entered channel failed! Re-do!\n");
goto redo;
}</P><P> if (start > 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<=stop; i++)
{
printf("Enter range code <0 -- 3> for channel %d :",i);
re_enter_gain:
scanf("%d",&ch_gain<i>);
if( ch_gain<i> < 0 || ch_gain<i> > 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(<40KHz): ");/* up to 40K Hz With DMA */
scanf ("%f",&rate);
div=2000000L/rate; /* L is long integret */
if (div < 50) /* rate must < 50 0000*/
{
printf("Invalid time rate,please input again!\n");
goto re_enter;
}
divisor1=div/0xffff;
if (divisor1 > 2) /*adjust divisor1 & 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",&wait);
if(wait<1||wait>100)
goto edt;
wait=wait*5000;
for(k=9;k>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&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>0? data1:-data1; /* get | data1 | */
/*if((data2>wait)&&(abs(data1-data2)>100)) break;
/*data2=data1;</P><P> /*}</P><P>/********* STEP 5: PERFORM SINGLE A/D CONVERSION***********/</P><P>gettime(&time); /* count using time */</P><P> for(k=0;k<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&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(&time);
sec1=time.ti_sec-time.ti_sec;
sec_h=(time.ti_hund-time.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]);
printf(" Next scan channel = %d\n",(status & 0x0f));
printf(" Start scan channel= %d\n",start);
printf(" Stop scan channel = %d\n",stop);
p=str;
for(k=0;k<NUM;k++)
{
fprintf(fp,"%f %6f\n",k*time_interval,(*p-2049)*DOOR); /* is a value of 0v*/
p++; /* writedata 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> 呵呵,谢谢啊! 学习学习
页:
[1]