====== USB-DIO32HS DInScan / DOutScan ====== This is a simple 32 bit console application demonstrating device discovery, DInScan and DOutScan functionality. It was created in Visual Studio 2008 so when opening in a newer environment you will get warning that can be ignored. If you get an error check the project references for a possible error on the MCCDAQ.DLL reference. If it's marked as a problem, delete it and re-add it. Below is the code, the full project is attach as a zip file. 'import statements help reduce line length and typing Imports MccDaq Imports MccDaq.ScanOptions Imports MccDaq.ChannelType Imports MccDaq.Range Imports MccDaq.DigitalPortType Imports MccDaq.FunctionType Imports MccDaq.ErrorInfo.ErrorCode Imports MccDaq.MccService Imports System Imports System.Convert Imports System.Threading.Thread Imports System.Timers Imports System.IO Module Module1 Const BLOCKSIZE As Integer = 5000 'samples per channel Const SAMPLERATE As Integer = 1000 'desired sample rate 'because the blocksize is 5 times greater than sample rate - input output scan time is 5 seconds Dim CurrentCount As Integer = 0 'indicates total samples taken Dim CurrentIndex As Integer = 0 'points to the last scan read Dim Status As Short = 0 Dim DaqBoard As MccBoard 'device object Dim memHandle As IntPtr Dim ret As ErrorInfo Sub Main() Dim ret As MccDaq.ErrorInfo Dim str As String = "USB-DIO32HS" Dim cki As ConsoleKeyInfo = New ConsoleKeyInfo MccService.ErrHandling(ErrorReporting.DontPrint, ErrorHandling.DontStop) MccDaq.DaqDeviceManager.IgnoreInstaCal() Dim bNum As Integer = -1 Dim BoardNum As Integer = 0 'get the device inventory to discover the device 'doing it this way you don't need to run InstCal but you do need it installed Dim inventory As MccDaq.DaqDeviceDescriptor() = MccDaq.DaqDeviceManager.GetDaqDeviceInventory(DaqDeviceInterface.Any) Dim numDevDiscovered As Integer = inventory.Length If numDevDiscovered > 0 Then For BoardNum = 0 To numDevDiscovered - 1 Dim daq As MccDaq.MccBoard = DaqDeviceManager.CreateDaqDevice(BoardNum, inventory(BoardNum)) If daq.BoardName = "USB-DIO32HS" Then bNum = BoardNum End If Exit For Next End If If (bNum > -1) Then DaqBoard = New MccBoard(bNum) 'get the device object Else Stop End If 'set digital port 0 to output ret = DaqBoard.DConfigPort(AuxPort0, DigitalPortDirection.DigitalOut) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop End If 'set digital port 1 to input ret = DaqBoard.DConfigPort(AuxPort1, MccDaq.DigitalPortDirection.DigitalIn) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop End If 'allocate driver memory memHandle = MccService.WinBufAllocEx(BLOCKSIZE) Dim rate As Integer = SAMPLERATE 'read data from port 1 Console.WriteLine("Reading port 1...will take 5 seconds") ret = DaqBoard.DInScan(AuxPort1, BLOCKSIZE, rate, memHandle, Background) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop Do ret = DaqBoard.GetStatus(Status, CurrentCount, CurrentIndex, MccDaq.FunctionType.DiFunction) Threading.Thread.Sleep(1) Loop Until (Status = 0) DaqBoard.StopBackground(DiFunction) 'transfer data to local buffer Dim data(BLOCKSIZE) As UShort ret = MccService.WinBufToArray(memHandle, data, 0, BLOCKSIZE) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop Dim i As Integer 'print a few points Console.WriteLine("printing 256 values") For i = 0 To 256 Console.Write("{0},", data(i)) Next Console.WriteLine(vbCrLf) 'make some data to output Dim angle As Double = 6.28318 / BLOCKSIZE Dim value As Double For i = 0 To BLOCKSIZE value = (System.Math.Sin(angle * i) + 1) * 65535 / 2 data(i) = System.Convert.ToUInt16(value) Next 'write the data to the driver ret = MccService.WinArrayToBuf(data, memHandle, 0, BLOCKSIZE) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop Console.WriteLine("Sending buffer out port 0...will take 5 seconds") 'send data out port 0 ret = DaqBoard.DOutScan(AuxPort0, BLOCKSIZE, rate, memHandle, Background) If ret.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop Do ret = DaqBoard.GetStatus(Status, CurrentCount, CurrentIndex, MccDaq.FunctionType.DoFunction) Threading.Thread.Sleep(1) Loop Until (Status = 0) DaqBoard.StopBackground(DoFunction) Console.WriteLine("Done...Press key to exit.") cki = Console.ReadKey() If Console.KeyAvailable = True Then cki = Console.ReadKey() End If End Sub **Attachments**\\ [[ https://files.digilent.com/reference-attachments/VBNET2008_USB_DIO32HS_DOutScan.zip |VBNET2008_USB_DIO32HS_DOutScan.zip ]]