Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim rrLookup As RedRatLookup Dim signalDB As ISignalDB Private WithEvents rr3 As CCWRedRat3 Attribute rr3.VB_VarHelpID = -1 Dim SigCount As Integer Dim Signal As CCWModulatedSignal Dim haveSignal As Boolean Dim haveRR3 As Boolean Dim inSig As CCWModulatedSignal Private Sub Clear_Click() RichTextBox1.Text = "" End Sub Private Sub Form_Load() ' Find RedRat3s plugged into this machine Dim rr3Names() As String Set rrLookup = New RedRat.RedRatLookup rr3Names = rrLookup.FindRedRat3s ' Set flag to indicate whether have an RR3 or not. If (UBound(rr3Names) < 0) Then haveRR3 = False Else haveRR3 = True End If ' Add them to the combo box If haveRR3 Then For i = 0 To UBound(rr3Names) RedRatCombo.List(i) = rr3Names(i) Next i RedRatCombo.Text = rr3Names(0) ' Set to the first one by default Set rr3 = rrLookup.GetRedRat3(rr3Names(0)) End If SetupGUI ' Other init haveSignal = False Set signalDB = New RedRat.CCWSignalDB End Sub 'Sets program state from selected RedRat3 Private Sub SetupGUI() If haveRR3 Then SigCount = 0 If rr3.RCDetectorEnabled Then rcEnabledCB.Value = 1 Else rcEnabledCB.Value = 0 End If 'Print out info. about the RedRat3 Dim deviceInfo As RedRat.CCWRR3DeviceInfo deviceInfo = rr3.DeviceInformation RichTextBox1.Text = RichTextBox1.Text + "Opened " + deviceInfo.ProductName + "." + CStr(deviceInfo.verMajor) + "." + CStr(deviceInfo.verMinor) RichTextBox1.Text = RichTextBox1.Text + " from " + deviceInfo.company + vbNewLine RichTextBox1.Text = RichTextBox1.Text + "Serial number: " + deviceInfo.serialNo + vbNewLine End If End Sub Private Sub Form_Unload(Cancel As Integer) If haveRR3 Then ' Unhook events so that we don't get notified of the detector ' being disabled as we're closing the app down, which causes ' an exception. From SDK V2.05 onwards. rr3.UnhookEvents ' Disable the RC detector on exit in case it is still enabled. rr3.RCDetectorEnabled = False End If End Sub Private Sub LearnSig_Click() If haveRR3 Then rr3.GetModulatedSignal (10000) RichTextBox1.Text = RichTextBox1.Text + "Waiting 10s for signal to learn...." + vbNewLine End If End Sub Private Sub LoadDB_Click() ' Load a signal DB for decoding. Dim fileName As String fileName = "D:\\temp\\DeviceDB.xml" signalDB.AddDeviceDB (fileName) RichTextBox1.Text = RichTextBox1.Text + "Loaded signal DB file: " + fileName + vbNewLine ' Should handle errors here!!! haveSignalDB = True ' Set one of the device parameters Dim RRDevice As CCWAVDeviceInfo RRDevice = signalDB.GetAVDeviceInfo("CD") RRDevice.manufacturer = "Groovy" Call signalDB.SetAVDeviceInfo(RRDevice) ' Test signal DB functions 'Dim Sig1 As CCWModulatedSignal 'Dim Sig2 As CCWModulatedSignal 'Sig1 = signalDB.GetSignal("CD", "Play") 'Call signalDB.RemoveSignal("CD", "Play") ''Sig2 = signalDB.GetSignal("CD", "Play") ' Should create error 'Call signalDB.AddSignal("CD", Sig1, False) ''Call signalDB.AddSignal("CD", Sig1, False) ' Should create error 'Call signalDB.AddSignal("CD", Sig1, True) End Sub Private Sub PlaySig_Click() If haveRR3 Then If haveSignal = True Then Call rr3.OutputModulatedSignal(Signal) RichTextBox1.Text = RichTextBox1.Text + "Output modulated signal" + vbNewLine Else RichTextBox1.Text = RichTextBox1.Text + "Have not yet captured a signal." + vbNewLine End If End If End Sub Private Sub rcDisable_Click() If haveRR3 Then rr3.RCDetectorEnabled = False End If End Sub Private Sub rcEnable_Click() If haveRR3 Then rr3.RCDetectorEnabled = True End If End Sub Private Sub RedRatCombo_Click() ' Select the RR3 we want Set rr3 = rrLookup.GetRedRat3(RedRatCombo.Text) SetupGUI End Sub Private Sub Blink_Click() If haveRR3 Then rr3.Blink RichTextBox1.Text = RichTextBox1.Text + "Blink" + vbNewLine End If End Sub ' Signal in from short-range learning detector Private Sub rr3_LearningSignalIn(ByVal sender As RedRat.ICCWRedRat3, ByVal e As RedRat.ISignalInEventArgs) If e.Action = 1 Then RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " Have Signal: " + vbNewLine Signal = e.ModulatedSignal haveSignal = True ' Print ot length values ' For N = 0 To 31 ' RichTextBox1.Text = RichTextBox1.Text + "length " + CStr(i) + " " + CStr(Signal.Lengths(N)) + vbNewLine ' Next N ElseIf e.Action = 3 Then ' This could be error, or timeout. RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " Exception: " + e.Exception + vbNewLine End If End Sub ' Signal input from long range RC detector. Private Sub rr3_RCSignalIn(ByVal sender As RedRat.ICCWRedRat3, ByVal e As RedRat.ISignalInEventArgs) If e.Action = SignalEventAction_MODULATED_SIGNAL Then Dim sigKey As String ' Try and recognize signal inSig = e.ModulatedSignal sigKey = signalDB.DecodeSignal(inSig) RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " Have RC signal: " + sigKey + vbNewLine ' Tests signal queuing stuff 'RichTextBox1.Text = RichTextBox1.Text + "Signal queue length: " + CStr(e.QueueSize) + vbNewLine 'Sleep (300) 'sender.ClearRCSignalInQueue ElseIf e.Action = SignalEventAction_EXCEPTION Then RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " Exception: " + e.Exception + vbNewLine ElseIf e.Action = SignalEventAction_RC_DETECTOR_ENABLED Then ' Update display RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " RC detector enabled." + vbNewLine rcEnabledCB.Value = 1 ElseIf e.Action = SignalEventAction_RC_DETECTOR_DISABLED Then ' Update display RichTextBox1.Text = RichTextBox1.Text + RedRatCombo.Text + " RC detector disabled." + vbNewLine rcEnabledCB.Value = 0 End If End Sub Private Sub Test_Click() ' == Misc test stuff == ' Obtain the XML for a signal Dim Sig As CCWModulatedSignal Dim xmlSig As String Sig = signalDB.GetSignal("CD", "Pause") xmlSig = signalDB.SignalToXML(Sig) RichTextBox1.Text = RichTextBox1.Text + "Have signal: " + vbNewLine + xmlSig + vbNewLine ' Add signal to the DB under a different device and signal name Dim Sig2 As CCWModulatedSignal Sig2 = signalDB.XMLToSignal(xmlSig) Sig2.Name = "New Sig" Call signalDB.AddSignal("Default", Sig2, False) ' Get some info about device "CD" Dim DevInfo As CCWAVDeviceInfo DevInfo = signalDB.GetAVDeviceInfo("CD") RichTextBox1.Text = RichTextBox1.Text + "Manufacturer: " + DevInfo.manufacturer + vbNewLine If DevInfo.AVDeviceType = AVDeviceType.AVDeviceType_CD_PLAYER Then RichTextBox1.Text = RichTextBox1.Text + "Device type is CD" + vbNewLine End If ' List the devices in the device DB Dim devNames() As String devNames = signalDB.GetDeviceNames For i = 0 To UBound(devNames) RichTextBox1.Text = RichTextBox1.Text + "Have device: " + devNames(i) + vbNewLine Next i ' Test output of part of DoubleSignal Dim DoubleSig As CCWDoubleModulatedSignal DoubleSig = signalDB.GetDoubleModSignal("Philips DTX 6371", "0") Dim Sig1 As CCWModulatedSignal Sig1 = DoubleSig.signal1 If haveRR3 Then Call rr3.OutputModulatedSignal(Sig1) RichTextBox1.Text = RichTextBox1.Text + "Sig1 of double signal output" + vbNewLine End If End Sub