'/****************************************************************************
'    Copyright © 2005,2006 Agilent Technologies Inc. All rights
'    reserved.
'
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Agilent has no
' warranty,  obligations or liability for any Sample Application Files.
'
' Agilent Technologies provides programming examples for illustration only,
' This sample program assumes that you are familiar with the programming
' language being demonstrated and the tools used to create and debug
' procedures. Agilent support engineers can help explain the
' functionality of Agilent software components and associated
' commands, but they will not modify these samples to provide added
' functionality or construct procedures to meet your specific needs.
'****************************************************************************/

' This program demonstrates outputting a named data trace from memory on a 34450A 
' digital IO card (the sender) to another card or device that is receiving the
' data (the receiver).

Imports System
Imports Agilent.Agilent34980A.Interop
Imports Agilent.Agilent34950A.Interop

Module Module1

    Sub Main()

        Dim host As New Agilent.Agilent34980A.Interop.Agilent34980A
        Dim digIO As Agilent.Agilent34950A.Interop.IAgilent34950A

        Try
            Dim standardInitOptions As String

            ' Setup IVI-defined initialization options
            standardInitOptions = "Cache=false, InterchangeCheck=false, QueryInstrStatus=true, RangeCheck=true, RecordCoercions=false, Simulate=false"

            ' Initialize DMM and clear status system/errors
            host.Initialize("TCPIP0::156.140.92.11::INSTR", False, True, standardInitOptions)
            host.Status.Clear()

            ' Select the 34951 Personality:
            digIO = host.Personality.Select("Agilent34950A")

            ' Configure sender for Output, width = byte
            digIO.Digital.Output.Configure("1101", Agilent34950AChannelWidthEnum.Agilent34950AChannelWidthByte, 5.0)
            ' Create a waveform to output, size = 3000
            digIO.Digital.Trace.CreateStandard("1101", Agilent34950ATraceTypeEnum.Agilent34950ATraceTypeCount, "Count3000", 3000)

            ' Set up handshaking
            digIO.Digital.Handshake.Configure("1101", Agilent34950AHandshakeModeEnum.Agilent34950AHandshakeModeSynchronous, 2.5, 5.0)

            ' set up receiver, rate is 500K
            ' NOTE the sender will output on the rising edge of the clock.  The receiver will
            ' need to make certain the data is stable before reading it, so the receiver 
            ' should not use the same edge of the same clock to "read" the data.

            ' Set up sender
            ' Disable memory and set sync strobe source INTernal
            digIO.Digital.Output.Memory.Enable("1101") = False
            digIO.Digital.Handshake.SyncStrobe("1101") = Agilent34950AHandshakeStrobeSourceEnum.Agilent34950AHandshakeStrobeSourceInternal

            ' Select the name of the trace to output and set cycle count to '1'
            digIO.Digital.Output.Memory.TraceSelect("1101") = "Count3000"
            digIO.Digital.Output.Memory.CycleCount("1101") = 1

            ' Enable the sender
            digIO.Digital.Output.Memory.Enable("1101") = True

            ' Start the receiver now if not already started

            ' Now Start the sender, he will pace the transfer
            digIO.Digital.Output.Memory.Start("1101")

            ' Data will now be transmitted to the receiver

        Catch ex As Exception
            Dim errNum As Integer
            Dim errMssg As String

            Console.WriteLine(ex.Message)
            errNum = 5
            errMssg = ""
            While (errNum <> 0)
                host.Utility.ErrorQuery(errNum, errMssg)
                If (errNum <> 0) Then
                    Console.WriteLine("{0}", errMssg)
                End If
            End While
        End Try

        ' Close drivers
        host.Close()

        Console.WriteLine("Done - Press Enter to Exit")
        Console.ReadLine()

    End Sub

End Module
