It is an example program in Visual C#. The conversion data and error contents are displayed in output window.
Example program by using AioSingleAo
Example program by using AioMultiAo
Example program by using AioSingleAo
//---------------------------
// Variable declaration
//---------------------------
int Ret; //Return values of functions
short Id; //ID
string ErrorString; //Array for storing error string
//---------------------------
// Initialize device
// Devicename : Aio000
//---------------------------
Ret = aio.Init( "Aio000" , out Id );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.Init : " + ErrorString);
return;
}
//---------------------------
// Set analog output range
// Range : -10 to 10V
//---------------------------
Ret = aio.SetAoRangeAll( Id , (short)CaioConst.PM10 );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.SetAoRangeAll : " + ErrorString);
Ret = aio.Exit( Id );
return;
}
//---------------------------
// Analog output form the specified channel only once
// Output channel : 0
// Output data : 800H
//---------------------------
Ret = aio.SingleAo( Id , 0 , 0x800 );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.SingleAo : " + ErrorString);
Ret = aio.Exit( Id );
return;
}
System.Diagnostics.Trace.WriteLine("Channel0 : 0x800");
//---------------------------
// Device exit
//---------------------------
Ret = aio.Exit( Id );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.Exit : " + ErrorString);
return;
}
Example program by using AioMultiAo
//---------------------------
// Variable declaration
//---------------------------
int Ret; //Return values of functions
short Id; //ID
string ErrorString; //Array for storing error string
int[] AoData = new int[8]; //Conversion data
short i;
//---------------------------
// Initialize device
// Devicename : Aio000
//---------------------------
Ret = aio.Init( "Aio000" , out Id );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.Init : " + ErrorString);
return;
}
//---------------------------
// Set analog output range
// Range : -10 to 10V
//---------------------------
Ret = aio.SetAoRangeAll( Id , (short)CaioConst.PM10 );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.SetAoRangeAll : " + ErrorString);
Ret = aio.Exit( Id );
return;
}
//---------------------------
// Analog output from multiple channels only once
// Number of output channels : 8
//---------------------------
for( i = 0 ; i < 8 ; i++ )
{
AoData[ i ] = i * 100;
System.Diagnostics.Trace.WriteLine("Channel" + i + " : " + AoData[ i ].ToString() );
}
Ret = aio.MultiAo( Id , 8 , AoData );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.MultiAo : " + ErrorString);
Ret = aio.Exit( Id );
return;
}
//---------------------------
// Device exit
//---------------------------
Ret = aio.Exit( Id );
if( Ret != 0 )
{
aio.GetErrorString( Ret , out ErrorString );
System.Diagnostics.Trace.WriteLine("aio.Exit : " + ErrorString);
return;
}