
#include "..\..\..\..\Lib\vp2k.h"
#include "..\..\..\..\Lib\8024.h"

//#define MSC     //enable the defination if you use MSC compiler.
void main(void)
{
    int iSlot,iChannel,iMode,iValue;
    float fValue;
    int iRun=1;
    int i;           
    unsigned long sw;
    char sTemp[20]; // For MSC 
    
    Puts("/*******************/\n\r");
    Puts("/*    8024 demo    */\n\r");
    Puts("/*                 */\n\r");
    Puts("/*  [7,Oct,2004]   */\n\r");                
    Puts("/*******************/\n\r");
    Puts("\n\r");
    while(iRun)
    {
        Puts("Slot(0~3 or 0~7)=");
        
        #ifdef MSC // For MSC
		    LineInput(sTemp,20);
		    sscanf(sTemp,"%d",&iSlot);
		    //iSlot=atoi(sTemp);
		#else // For BC, TC
            Scanf("%d",&iSlot);
        #endif
		Puts("Channel(0~3)=");
               
        #ifdef MSC//For MSC
            LineInput(sTemp,20);
            sscanf(sTemp,"%d",&iChannel);
            //iChannel=atoi(sTemp);
		#else // For BC, TC
            Scanf("%d",&iChannel);
        #endif
		
        Puts("Mode\n\r");
        Puts("  0) Voltage +/- 10.0 V          (float format)\n\r");
        Puts("  1) Current 0 ~ 20 mA           (float format)\n\r");
        Puts("  2) Voltage +/- 10.0 V          (2's format)\n\r");
        Puts("  3) Current 0 ~ 20 mA           (2's format)\n\r");
        Puts("  4) Voltage +/- 10000 (mV)      (integer format)\n\r");      
        Puts("  5) Current 0 ~ 20000 (0.001 mA)(integer format)\n\r"); 
        
        Puts("  Please choose(0~5):");
        
        #ifdef MSC
            LineInput(sTemp,20);
            sscanf(sTemp,"%d",&iMode);
            iMode=atoi(sTemp);  
        #else
            Scanf("%d",&iMode);
		#endif
				
        switch(iMode)
        {
            case 0:
                Puts("Output Voltage(+/- 10.0)(unit: V) = ");
                
                #ifdef MSC //For MSC
                    LineInput(sTemp,20);
                    sscanf(sTemp,"%f",&fValue);   
                #else // For BC, TC
                    Scanf("%f",&fValue);
                #endif  
                break;
            		        
            case 1:
                Print("Output Current(0.0 ~ 20.0)(unit: mA) = ");
                #ifdef MSC //For MSC              
                   LineInput(sTemp,20);
                   sscanf(sTemp,"%f",&fValue);   
                #else // For BC, TC                   
                    Scanf("%f",&fValue); 
                #endif                   
                break;                   
                
            case 2:
                Puts("Output Voltage(-32768~32767)(unit: none) = ");
                #ifdef MSC //For MSC              
                    LineInput(sTemp,20); 
                    sscanf(sTemp,"%d",&iValue);
                    //iValue=atoi(sTemp);  
                #else                    
                    Scanf("%d",&iValue); 
                #endif                   
                break;                   
            
            case 3:	
                Puts("Output Current(0~32768)(unit: none) = ");	
                #ifdef MSC  //For MSC            
                    LineInput(sTemp,20);
                    sscanf(sTemp,"%d",&iValue);
                    //iValue=atoi(sTemp); 
                #else  // For BC, TC                 
                    Scanf("%d",&iValue);
                #endif                  
                break;                  
            		        
            case 4:	
                Puts("Output Voltage(+/- 10000)(unit: mV) = ");	
                #ifdef MSC //For MSC             
                    LineInput(sTemp,20);
                    sscanf(sTemp,"%d",&iValue);
                    //iValue=atoi(sTemp); 
                #else  // For BC, TC                 
                    Scanf("%d",&iValue);
                #endif                  
                break;                  
            
            case 5:
                Puts("Output Current(0 ~ 20000)(unit: 0.001 mA) = ");
                #ifdef MSC //For MSC             
                    LineInput(sTemp,20);
                    sscanf(sTemp,"%d",&iValue);
                    //iValue=atoi(sTemp); 
                #else  // For BC, TC                 
                    Scanf("%d",&iValue);
                #endif                  
                break;                  
            
		}
        
        I8024_Initial(iSlot);
        
        switch(iMode)
        {
            case 0:
                I8024_VoltageOut(iSlot,iChannel,fValue);         
                break;
                          
            case 1:
                I8024_CurrentOut(iSlot,iChannel,fValue);
                break;
                
            case 2:                                                           
                I8024_VoltageOut_Hex(iSlot,iChannel,iValue);         
                break;                                                                      
                                                                            
            case 3:
                I8024_CurrentOut_Hex(iSlot,iChannel,iValue);
                break;      
                
            case 4:
                I8024_VoltageOut_mV(iSlot,iChannel,iValue);      
                break;
                
            case 5:     
                I8024_CurrentOut_0001mA(iSlot,iChannel,iValue);
                break;
        }
            
        Puts("\n\rPress 'q' or 'Q' to quit, other key to continue....");
        sTemp[0]=Getch();
        if(sTemp[0]=='q' || sTemp[0]=='Q')
            iRun=0;
        Puts("\n\r\n\r");
    }
}