#include "stdio.h"
#include <string.h>
#include <math.h>
#include <alloc.h>
#include "..\lib\8028u.h"
#include "..\lib\8000.h"
void main()
{
	int iRet;
	int iRun=1;
	int iSlot,iChannel,iMode,iValue;
    float fValue;
	int i;
	char sTemp[20];
	unsigned short uValue;
	InitLib();
	Print("Slot(0~3 or 0~7)=");
	Scanf("%d",&iSlot);
	Print("Channel(0~3)=");
	Scanf("%d",&iChannel);
	i8028UW_Init(iSlot);
	while(iRun)
	{	
		Print("Mode\n\r");
        Print("  0) Voltage 0~5 V\n\r");
        Print("  1) Voltage 0~10 V\n\r");
        Print("  2) Voltage +/- 5 V\n\r");
        Print("  3) Voltage +/- 10 V\n\r");
        Print("  4) Current 4~20 mA\n\r");      
        Print("  5) Current 0~20 mA\n\r"); 
		Scanf("%d",&iMode);

		switch(iMode)
        {
            case 0:
				Print("Hex value=? (0~65535)");
				Scanf("%d",&uValue);
				iRet=i8028UW_WriteAOHex(iSlot,iChannel,0,uValue);
				break;
			case 1:
				Print("Hex value=? (0~32767)");
				Scanf("%d",&iValue);
				for(i=0;i<10000;i++)
				{
					uValue=((unsigned short)iValue)*2;
					iRet=i8028UW_WriteAOHex(iSlot,iChannel,1,uValue);
					Delay(5);
				}
				break;
			case 2:
				Print("Hex value=? (-32768~32767)");
				Scanf("%d",&iValue);
				iRet=i8028UW_WriteAOHex(iSlot,iChannel,2,iValue);
				break;
			case 3:
				Print("Hex value=? (-32768~32767)");
				Scanf("%d",&iValue);
				iRet=i8028UW_WriteAOHex(iSlot,iChannel,3,iValue);
				break;
			case 4:
				Print("Hex value=? (0~65535)");
				Scanf("%d",&uValue);
				iRet=i8028UW_WriteAOHex(iSlot,iChannel,4,uValue);
				break;
			case 5:
				Print("Hex value=? (0~65535)");
				Scanf("%d",&uValue);
				iRet=i8028UW_WriteAOHex(iSlot,iChannel,5,uValue);
				break;				
		}
		Print("\n\rPress 'q' or 'Q' to quit, other key to continue....");
        sTemp[0]=Getch();
        if(sTemp[0]=='q' || sTemp[0]=='Q')
            iRun=0;
        Print("\n\r\n\r");
	}

}