#include<stdio.h>
#include<conio.h>
#include"A826.h"

int Base=0x220;
int Buf[1000];

void main(void)
{ int err;
  int i,t;
  float rate=10.0/32768.0,val;

  err=A826_Initialize(0,Base,-1,-1);
  if(err){
     if(err==CheckBoardError){
	printf("Address 0 Error!\n");
     }
     else if(err==CardNumError){
	printf("Card Number Error!(range:0-7)\n");
     }
     return;
  }
  printf("\nCard 0 [polling test]");
  printf("\nUsing [A826_AD_PollingArray]");
  A826_AD_SetChGainMode(0,A826_BI_1,POLLING_MODE);
  A826_AD_PollingArray(Buf,1000);
  for(i=0;i<1000;i+=100){
	 printf("\n[%3d] [%x] %f",i,Buf[i],rate*Buf[i]);
  }
  for (i=0; i<5; i++)
  {
  printf("\nUsing [A826_AD_PollingVar]");
  Buf[0]=A826_AD_PollingVar();
  printf(" --> PollingVar= [%x] %f",Buf[0],rate*Buf[i]);
  }
  Buf[0]=0x7fff;
  if ((Buf[0]&0x8000)==0) val=Buf[0];
  else
	 {
	 t=Buf[0]^0xffff+1;
	 val=t;
	 }
  printf("\nTEST 1 = [%x] %f",Buf[0],rate*val);
  Buf[0]=0xffff;
  if ((Buf[0]&0x8000)==0) val=Buf[0];
  else
	 {
	 t=Buf[0]^0xffff+1;
	 val=t;
	 }
  printf("\nTEST 2 = [%x] %f",Buf[0],rate*val);
  Buf[0]=0x8000;
  if ((Buf[0]&0x8000)==0) val=Buf[0];
  else
	 {
	 t=Buf[0]^0xffff+1;
	 val=t;
	 }
  printf("\nTEST 3 = [%x] %f",Buf[0],rate*val);
}
