/* Test with I-8024 AO Module and I-8017H AI Module at Slot 01 and 02 of LinCon seperately
   
   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.)

   i8kaio.c
   v1.0 2018.9.1 by Edward  
*/

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

int main()
{
	int wRetVal, chAi;
	float fVal;
	short hAi,jumper;
	int slot_8017 = 2, slot_8024 = 3;
	//I-8024   
	wRetVal = Open_Slot(slot_8024);
	if (wRetVal > 0) {
		printf("open Slot failed!\n");
		return (-1);
	}
	
	//I8024 Initial
	I8024_Initial(slot_8024);
	
	//I8024_AO Output
	I8024_VoltageOut(slot_8024,0,5);
	Close_Slot(slot_8024);
	
	//I-8017H  
	wRetVal = Open_Slot(slot_8017);
	if (wRetVal > 0) {
		printf("open Slot failed!\n");
		return (-1);
	}
	//I8017H Initial
	I8017_Init(slot_8017);
	//I8017_Select_SingleEnd(2, 0); //i8017H_Select_SingleEnd(int slot, short selection), this function is for I-9017-15 only
	I8017_GetSingleEndJumper(slot_8017, &jumper);  	
  
	//First Method: Get AI Value: I8017_ReadAI	
	I8017_ReadAI(slot_8017,0,0,&fVal); //I8017_ReadAI(slot,i,iGain,&fVal);
	printf("Slot2 CH0 I8017_ReadAI =%f\n",fVal);
	
	I8017_ReadAI(slot_8017,1,0,&fVal); //I8017_ReadAI(slot,i,iGain,&fVal);
	printf("Slot2 CH1 I8017_ReadAI =%f\n",fVal);
	
	//Second Method: Get AI Value: I8017_ReadAIHex	
	I8017_ReadAIHex(slot_8017,1,0,&hAi); //i8017H_ReadAIHex(int slot,int iChannel,int iGain,short* iValue)
	printf("Slot%d CH1 I8017_ReadAIHex =%x\n",slot_8017, hAi);
	
	Close_Slot(2);
	
	return 0;
}
