It is an example program in Visual Basic .NET. The conversion data and error contents are displayed in debug window.
Example program by using AioSingleAi
Example program by using AioMultiAi
Example program by using AioSingleAi
'---------------------------
' Variable declaration
'---------------------------
Dim Ret As Integer 'Return values of functions
Dim Id As Short 'ID
Dim ErrorString As String = Space(256) 'Array for storing error string
Dim AiData As Integer 'Conversion data
'---------------------------
' Initialize device
' Devicename : Aio000
'---------------------------
Ret = AioInit("Aio000", Id)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioInit : " + ErrorString)
Exit Sub
End If
'---------------------------
' Set analog input method
' Input method : Single-end input
'---------------------------
Ret = AioSetAiInputMethod(Id, 0)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioSetAiInputMethod : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
'---------------------------
' Set analog input range
' Range : -10 to 10V
'---------------------------
Ret = AioSetAiRangeAll(Id, PM10)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioSetAiRangeAll : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
'---------------------------
' Analog input to the specified channel only once
' Input channel : 0
'---------------------------
Ret = AioSingleAi(Id, 0, AiData)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioSingleAi : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
System.Diagnostics.Trace.WriteLine("Channel0 : " + AiData.ToString())
'---------------------------
' Device exit
'---------------------------
Ret = AioExit(Id)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioExit : " + ErrorString)
Exit Sub
End If
Example program by using AioMultiAi
'---------------------------
' Variable declaration
'---------------------------
Dim Ret As Integer 'Return values of functions
Dim Id As Short 'ID
Dim ErrorString As String = Space(256) 'Array for storing error string
Dim AiData(8) As Integer 'Conversion data
Dim i As Short
'---------------------------
' Initialize device
' Devicename : Aio000
'---------------------------
Ret = AioInit("Aio000", Id)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioInit : " + ErrorString)
Exit Sub
End If
'---------------------------
' Set analog input method
' Input method : Single-end input
'---------------------------
Ret = AioSetAiInputMethod(Id, 0)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioSetAiInputMethod : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
'---------------------------
' Set analog input range
' Range : -10 to 10V
'---------------------------
Ret = AioSetAiRangeAll(Id, PM10)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioSetAiRangeAll : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
'---------------------------
' Analog input to multiple channels only once
' Number of input channels : 8
'---------------------------
Ret = AioMultiAi(Id, 8, AiData(0))
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioMultiAi : " + ErrorString)
Ret = AioExit(Id)
Exit Sub
End If
For i = 0 To 7
System.Diagnostics.Trace.WriteLine("Channel" + i.ToString() + " : " + AiData(i))
Next i
'---------------------------
' Device exit
'---------------------------
Ret = AioExit(Id)
If Ret <> 0 Then
AioGetErrorString(Ret, ErrorString)
System.Diagnostics.Trace.WriteLine("AioExit : " + ErrorString)
Exit Sub
End If