EXAMPLE CLASS LIBRARY CODE
Below is our example Class Library source code that performs 3 different protocol decodes and displays the results on the waveline. A version that includes an actual NEC IR decoder is installed with the USBee Suite. Use this example to start your own.
Imports System.IO
Public Class CustomUSBeeSuiteDecoder
Declare Function SampleData Lib "usbeeste.dll" Alias _
"?LoggedData@@YGJK@Z" (ByVal Index As Integer) As UInteger
' The SampleData routine returns a 4 byte value that contains a single
' sample of all the signals
' The format of the 32 bits is as follows:
'
' MSB LSB
' XXXXXXXXYYYYYYYYFEDCBA9876543210
'
' where XXXXXXXX is Channel 2 Analog value (0=-10V, 255 = +10V)
' YYYYYYYY is Channel 1 Analog value (0=-10V, 255 = +10V)
' F is logic level (0 or 1) for channel F
' E is logic level (0 or 1) for channel E
' D is logic level (0 or 1) for channel D
' ...
' 0 is logic level (0 or 1) for channel 0
Public Sub DecodeCustom(ByVal OutFile As String, _
ByVal NumberOfSamples As Integer, _
ByVal RateIndex As Byte, _
ByVal Parameters As String)
Dim OldSample As UInteger
Try
' This is a custom bus decoder Processing Routine
'
' The passed in variables are as follows:
' OutFile - the file that all of the decoded Entries get
' written to. This is the file that the Suite
' will read to display the data on the waveline.
' RateIndex - Index of the sample rate samples were taken.
' 17=1Msps,27=2Msps,37=3Msps,47=4Msps
' 67=6Msps,87=8Msps,127=12Msps,167=16Msps
' 247=24Msps
' Parameters - User defined string passed from the Suite user
' interface Channel Setting for this waveline.
' Use this string to pass in any parameters that
' your decoder needs to know, such as what
' channels to use in decoding, which protocol if
' you have multiple protocols supported here,
' and how you want the data formatted.
' Below is an example set of Custom Protocol decoders that show
' how to access the sample buffer and how to generate output that
' get sent to the screen.
' Setup the File Stream that stores the Output Entry Information
Dim FS As New FileStream(OutFilename, FileMode.Append, _
FileAccess.Write)
Dim BW As New BinaryWriter(FS)
USBee Suite User’s Manual 71
' Since this file supports 3 different custom decoders, we need to
' see which one to run for this pass based on the Parameters
' string
If InStr(Parameters.ToUpper, "CHANGE") Then
' Sample Decoder that just detects when a signal changes state
' The signal to use for the detection is specified in the
' Parameters as the second parameter
Dim Params() = Parameters.Split(" ,-")
Dim SignalToUse = Val(Params(1))
' Make the mask to mask off the channel we want in the sample
Dim SignalMask = 1 << SignalToUse
' Now go from the start to the end and process the samples
For Sample = 0 To NumberOfSamples - 1
Dim DigitalChannel = SampleData(Sample) And SignalMask
If DigitalChannel <> OldSample Then
WriteEntry(BW, Sample, Sample + 100, "Changed!")
End If
OldSample = DigitalChannel
Next
ElseIf InStr(Parameters.ToUpper, "RISE") Then
' Sample Decoder that detects when a signal has a Rising Edge
' The signal to use for the detection is specified in the
' Parameters as the second parameter
Dim Params() = Parameters.Split(" ,-")
Dim SignalToUse = Val(Params(1))
' Make the mask to mask off the channel we want in the sample
Dim SignalMask = 1 << SignalToUse
' Now go from the start to the end and process the samples
For Sample = 0 To NumberOfSamples - 1
Dim DigitalChannel = SampleData(Sample) And SignalMask
If (DigitalChannel <> OldSample) And (OldSample = 0) Then
WriteEntry(BW, Sample, Sample + 100, _
"Rising Edge!")
End If
OldSample = DigitalChannel
Next
ElseIf InStr(Parameters.ToUpper, "HELLOWORLD") Then
' Simplest Decoder Possible
' Print Hello World at the start of the buffer
WriteEntry(BW, 0, 100, "Hello World!")
End If
Catch ex As Exception
End Try
End Sub