Code Examples

The majority of the code shown below is taken from the Sample .Net code delivered as part of the RedRat SDK. It demonstrates, in a simple fashion, the use of the RedRat API and most of the RedRat3’s functionality.

Finding a RedRat3

The code snippet below provides an example of how to find RedRat3 devices attached to a computer or on a network. The method RedRat3USBImpl.FindDevices() returns a list of all RedRat3s found and the first device on the list is selected.

A specific RedRat can be found via information associated with the LocationInfo object, such as the device name or serial number, using the following code:


Discovering Information about the RedRat

The code snippet below shows how to print information about the RedRat3.


IR Signal Input – Learning Mode

To allow the RedRat3 to enable IR signal input from the learning detector, first a learning-signal event delegate needs to be created.

The SignalEventArgs object indicates several things: whether the signal has been captured properly, the signal capture has been cancelled by the user or an error has occurred via exception handling. The following code snippet shows how to add the learning-signal event delegate to the RedRat3 instance and then perform the above checks.

The finally section ensures the learning-signal event delegate is removed.

Outputting a Remote Control Signal

The following code snippet provides a simple example of how to output a captured signal.


Loading a Signal Database

To use a database of IR signals from several audio-visual devices, the code snippet below can be used. The database is loaded from an XML file to create an object of type AVDeviceDB. This object contains multiple AVDevice objects which each represent a particular piece of AV equipment or remote.


Using the Database to Decode Signals

Upon input from a remote control, IR signals need to be decoded by a RedRat3 before they can be used. First, a listener for the RCDetectorSignalIn event needs to be added.

Once a valid signal has been received, it is passed directly to the AVDeviceDB object for decoding.

The DecodeSignal() methods returns a SignalKey object which contains information identifying the signal. As an example, the SignalKey can then be passed to the following MoveWindow() method to change the location of a simple WinForms application window on the screen.

The new location of the window is set as follows:


Remote Control Signal Queue

When reading incoming signals from the RedRat3, the action that each signal initiates on the computer cannot take too long or the RedRat will miss part or all of the next signal. As a result, the signal data needs to be decoupled from the RedRat and the signal event dispatching using a FIFO queue as follows:

In some situations, the signal backlog may become too large and it may be desired to clear the queue. This can be done with the following code snippet:


Database Signal Lookup for Output

The code snippet below shows  how to obtain a particular signal from the signal database for output.

Instead of a device and signal name, a UID can also be used to lookup a signal:

This site uses cookies. Find out more about this site’s cookies.