/* Test I-8017H AI Module

   Author: Moki Matsushima  

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   
   File level history (record changes for this file here.)

   i8kaio2.c
   v 0.0 1 Sep 2018 by Moki Matsushima
   
   create, ... ok, i keep this as simple as possible
 */


#include<stdio.h>
#include<stdlib.h>
#include <sys/time.h>
#include "msw.h"
#include "i8017W.h"
	
char szSend[80], szReceive[80];
DWORD dwBuf[12];
float fBuf[12];

int main()
{
	int i, wRetVal,wchannel,wslot, ret;
	float fAi;
	int hAi;
	short jumper;
	struct timeval start,end;
	/* COM2, Baudrate=9600, 8 data bit, non-parity, 1 stop bit */
	gettimeofday(&start,NULL);
	for(wslot = 1; wslot < 9;wslot++) {
		wRetVal = Open_Slot(wslot);
		if (wRetVal > 0) {
			printf("open Slot failed!\n");
			return (-1);
		}

		ret=I8017_Init(wslot);
		if (ret != -1) {  
			//I8017_Select_SingleEnd(wslot, 0); //0:differential ; 1:single-ended mode., this function is for I-9017-15 only
			I8017_GetSingleEndJumper(wslot, &jumper);  
			//I8017_Select_SingleEnd(wslot, 0); //i8017H_Select_SingleEnd(int slot, short selection)
	  
			for (wchannel=0;wchannel<8;wchannel++) {
				I8017_ReadAI(wslot,wchannel,0,&fAi); //I8017_ReadAI(slot,i,iGain,&fAi);
				printf("Slot %d Ch %d: I-8017 Float Analog avalue =%f\n",wslot,wchannel,fAi);
			}
			Close_Slot(wslot);
		}
	}
	gettimeofday(&end,NULL);
	printf("\r\nTime = %ld us \n\r",end.tv_usec-start.tv_usec);
	printf("\r\nTime = %ld ms \n\r",(end.tv_usec-start.tv_usec)/1000);
	return 0;
}
