Pattern Generator Wrapper Imports System.Text Imports System.Runtime.InteropServices Public Class ComClass1 Public Const ClassId As String = "E6EF34A1-307D-4D52-A36A-D2BC5AF00EB6" Public Const InterfaceId As String = "1519443E-2AF2-465A-B09E-3B4E41DA65FE" Public Const EventsId As String = "3A5E00E2-5B64-4293-ADA8-37ECBE12E0A0" Public Sub New() MyBase.New() End Sub 'Initializing Device Public Function AD2_FDwfDeviceOpen(ByVal idxDevice As Integer, ByVal phdwf As Integer) As Integer 'Opens a device identified by the enumeration index with the selected configuration and retrieves a handle. Call FDwfDeviceOpen(idxDevice, phdwf) End Function Public Function AD2_FDwfDigitalOutInternalClockInfo(ByVal hdwf As Integer, ByVal phzFreq As Double) As Integer 'Retrieves the internal clock frequency. Call FDwfDigitalOutInternalClockInfo(hdwf, phzFreq) End Function Public Function AD2_FDwfDigitalOutEnableSet(ByVal hdwf As Integer, ByVal idxChannel As Integer, ByVal fEnable As Integer) As Integer 'Enables or disables the channel specified by idxChannel. Call FDwfDigitalOutEnableSet(hdwf, idxChannel, fEnable) End Function Public Function AD2_FDwfDigitalOutRunSet(ByVal hdwf As Integer, ByVal secRun As Double) As Integer 'Sets the run length for the instrument in Seconds. Call FDwfDigitalOutRunSet(hdwf, secRun) End Function Public Function AD2_FDwfDigitalOutRepeatSet(ByVal hdwf As Integer, ByVal cRepeat As Integer) As Integer 'Sets the repeat count. Call FDwfDigitalOutRepeatSet(hdwf, cRepeat) End Function Public Function AD2_FDwfDigitalOutTypeSet(ByVal hdwf As Integer, ByVal idxChannel As Integer, ByVal t As Integer) As Integer 'Sets the output type of the specified channel. Call FDwfDigitalOutTypeSet(hdwf, idxChannel, t) End Function Public Function AD2_FDwfDigitalOutIdleSet(ByVal hdwf As Integer, ByVal idxChannel As Integer, ByVal i As Integer) As Integer 'Sets the idle output of the specified channel. Call FDwfDigitalOutIdleSet(hdwf, idxChannel, i) End Function Public Function AD2_FDwfDigitalOutDividerSet(ByVal hdwf As Integer, ByVal idxChannel As Integer, ByVal d As Integer) As Integer 'Sets the divider value of the specified channel. Call FDwfDigitalOutDividerSet(hdwf, idxChannel, d) End Function Public Shared Function AD2_FDwfDigitalOutDataSet(ByVal Hdwf As Integer, ByVal IdxChannel As Integer, ByVal RgBits As String, ByVal CountOfBits As Integer) As String Dim TxStat As Integer = -1 Dim TxWrapper As String = "" 'Post Processing Method Dim TxString As String = RgBits Dim HexString(1024) As String Dim strReturn(1024) As String Dim b As Integer, g As Integer Dim BinString(1024) As String Dim BinStr(1024) As String Dim RevBin As String Dim BitNum As Integer : BitNum = 7 'Conversion of String to Hex For b = 0 To (Len(TxString) - 1) HexString(b) = Mid(TxString, b + 1, 1) strReturn(b) = Asc(HexString(b)) 'Conversion of Hex to Binary For g = BitNum To 0 Step -1 If strReturn(b) And (2 ^ g) Then BinString(b) = "1" + BinString(b) Else BinString(b) = "0" + BinString(b) End If Next 'Adding of Transition Bits before the Start of Inverted ASCII Bits BinStr(b) = "10" + (BinString(b)) RevBin = RevBin + BinStr(b) Next 'Padding of Additional 1s (Not yet adaptive) Dim Counter As Integer : Counter = Len(RevBin) If Counter = 10 Then RevBin = RevBin + "111111" If Counter = 20 Then RevBin = RevBin + "1111" If Counter = 30 Then RevBin = RevBin + "11" If Counter = 50 Then RevBin = RevBin + "111111" If Counter = 60 Then RevBin = RevBin + "1111" If Counter = 70 Then RevBin = RevBin + "11" If Counter = 90 Then RevBin = RevBin + "111111" If Counter = 100 Then RevBin = RevBin + "1111" If Counter = 110 Then RevBin = RevBin + "11" RevBin = RevBin 'Chunking of Bits into 8 Dim RevBytes(Len(RevBin)) As String For e As Integer = 0 To Len(RevBin) Step 8 RevBytes(e) = RevBytes(e) + Mid(RevBin, e + 1, 8) Next Dim backup As String Dim Extracted(1024) As String Dim TxBits(1024) As Byte Dim f As Integer, x As Integer Dim lTemp As Integer : lTemp = 0 'Inverting and Conversion of Bits For f = 0 To RevBytes.Length backup = StrReverse(RevBytes(8 * f)) If backup = "" Then Extracted(f) = "0" Extracted(f) = Extracted(f) & backup 'Conversion of Binary to Decimal Dim lngValue As Integer Dim k As Integer k = Len(Extracted(f)) For x = k To 1 Step -1 If Mid$(Extracted(f), x, 1) = "1" Then If k - x > 8 Then lngValue = lngValue Or -2147483648.0# Else lngValue = lngValue + 2 ^ (k - x) End If End If Next x TxBits(f) = lngValue lngValue = 0 If TxBits(f) = 0 Then Exit For Next f TxStat = FDwfDigitalOutDataSet(Hdwf, IdxChannel, TxBits, CountOfBits) If (TxStat = 1) Then TxWrapper = "Done" Else TxWrapper = "Error on FDwfDigitalOutDataSet: " + Str(TxStat) End If Return TxWrapper End Function Public Function AD2_FDwfDigitalOutConfigure(ByVal hdwf As Integer, ByVal fStart As Integer) As Integer 'Starts or stops the instrument. Call FDwfDigitalOutConfigure(hdwf, fStart) End Function Public Function AD2_FDwfDigitalOutReset(ByVal hdwf As Integer) As Integer 'Resets and configures (by default, having auto configure enabled) all the instrument parameters to 'default values. Call FDwfDigitalOutReset(hdwf) End Function Public Function AD2_FDwfDeviceCloseAll() As Integer 'Closes all opened devices by the calling process. It does not close all devices across all processes. Call FDwfDeviceCloseAll() End Function End Class