How Do I ... ?

CobraNet Devices

 

 

CobraNet networked digital audio devices can be very easily controlled or monitored using Stardraw Control.

 

Please note that this is an advanced topic and requires some programming knowledge.  If you have not created or modified driver scripts before, the Write my Own Driver topic may be worth reviewing.

 

Online Resources

There is a multimedia walk-through of these techniques in the online Technical Resources.

 

You Will Need...

CobraNet digital audio devices use an Ethernet protocol called SNMP Simple Network Management Protocol: a standard protocol for monitoring and controlling devices on an Ethernet network. that allows software applications like Stardraw Control to monitor and control parameters and settings within the device itself.

 

You need to know the following configuration and control properties of your device:

 

About SNMP

SNMP is a standard, general-purpose protocol for controlling and monitoring network applications and devices.  Controllable parameters or properties exposed by SNMP devices are addressed using Object Identifiers (OIDs) which can be used to interrogate, set or monitor those properties.  An OID uniquely identifies the device on the network, the instance of the object, such as a specific audio output or DSP block, and finally the object parameter being controlled, such as Gain, Delay, etc.

 

 

1.3.6.1.4.1.2680.1.2.7.3.2.0

 

An SNMP Object Identifier

 

OIDs and MIBs

CobraNet devices that support SNMP have a list file of all the OIDs, called the Management Information Base (MIB). The MIB provides the name, OID, data types and descriptions of each object and parameter.

 

Your device's MIB can be obtained from the manufacturer as a file, and can be viewed using an MIB browser application.

 

Example Device

The device that is used in this example is an Attero Tech CobraNet CO2 evaluation board.  The OID for the audio output channel parameter we will control was obtained using an MIB browser:

 

Parameter

Object Identifier

Transmitter n Channel

1.3.6.1.4.1.2680.1.1.7.1.1.2.n

 

where n represents the Transmitter instance: 1, 2, 3, etc.

 

To verify that the driver is working, the Attero Tech CO2 Demonstration Utility application is also installed and running.

 

Creating a CobraNet Device Driver

To create a new CobraNet device driver,  

  1. In the Topology View click the Add New Product button, or select Add New Product from the Tools menu, or press F8.

  2. In the Add New Product dialog select the Manufacturer Name "Attero Tech" from the list: if it is not present, click New to define a new manufacturer.

  3. Enter the Model Number of "CO2", and a Description of "CobraNet Development Board".  Click OK.

  4. In the Product Properties dialog, click Add to add a new Port.

  5. In the Port Properties dialog enter "Ethernet" as the Name, and select "Cobranet Ethernet Port" as the port Type.  Click OK

  6. Click Add to add another Port: enter "Audio Output" as the Name, and select "Cobranet Audio Output" as the port Type.

  7. Click Edit: the Script Editor will open and display the default script for the selected port type.

 

In the default script, the driver's class derives from the SnmpClientPortInstance base class.  This base class provides all the functionality required to communicate with a CobraNet device using the SNMP protocol.

 

 

public class CobranetAudioOutput : SnmpClientPortInstance

 

 

Modifying the Default Script

The default script contains some basic initialization code, some general comments and commented-out demo code, but nothing more.  Remove the comment characters ( // ) from the script so that it looks like this:

 

 

public class CobranetAudioOutput : SnmpClientPortInstance

{

   public CobranetAudioOutput( ProductInstance productInstance, Port port ) : base( productInstance, port )

   {

   }

 

   private const string channelOID = "1.3.6.1.4.1.2680.1.1.7.1.1.2.1";

   

   protected override void OnOpened()

   {

      BeginGetSnmp( channelOID );

   }

   

   private int channel;

   

   [Controllable]

   public in Channel

   {

      get { return channel; }

      set { SetSnmpInteger( channelOID, value ); }

   }

   

   [Controllable]

   public event EventHandler OnChannelChanged;

   

   protected override void OnSnmpIn( string OID, object value )

   {

      base.OnSnmpIn( OID, value );

      

      switch( OID )

      {

         case channelOID:

            if( (int)value != channel )

            {

               channel = (int)value;

               if( OnChannelChanged != null );

                  OnChannelChanged( this, EventArgs.Empty );

            }

            break;

      }

      

      BeginGetSnmp( channelOID );

   }

}

 

The core of the Cobranet Audio Output port script

 

This script now contains:

 

The Channel property contains a get accessor that returns the channel variable, and a set accessor which calls the base class's SetSnmpInteger method: this performs the task of sending the new integer value to the device via SNMP addressed to the device's channel OID.

 

 

[Controllable]

public in Channel

{

   get { return channel; }

   set { SetSnmpInteger( channelOID, value ); }

}

 

 

The OnOpened method is called automatically when the driver and port are first initialized:

 

 

protected override void OnOpened()

{

   BeginGetSnmp( channelOID );

}

 

 

 

The BeginGetSnmp method requests the current value of the device's Transmitter 1 Channel property from the device.  When the device sees the get request by detecting the OID, it responds a short time later by sending the Transmitter 1 Channel property value back to the Stardraw application.

 

The OnSnmpIn method is called asynchronously An asynchronous operation executes independently from the action which started it. The application can continue performing other tasks while the asynchronous operation performs its task. in response to BeginGetSnmp:

 

 

protected override void OnSnmpIn( string OID, object value )

{

   base.OnSnmpIn( OID, value );

   

   switch( OID )

   {

      case channelOID:

         if( (int)value != channel )

         {

            channel = (int)value;

            if( OnChannelChanged != null );

               OnChannelChanged( this, EventArgs.Empty );

         }

         break;

   }

  

   BeginGetSnmp( channelOID );

}

 

 

 

The [Controllable] attribute on the Channel property and OnChannelChanged event makes these accessible from the Actions dialog, so that we can use it to control and respond to the driver.

 

Click Compile: Stardraw Control will verify and compile your code changes.  If no error messages appear, click OK to close the Script Editor.  Click OK to close the Port Properties dialog.

 

Before closing the Product Properties dialog, the Shared option can be cleared if you do not wish to share your new device driver with other Stardraw Control users; otherwise leave this option set.

 

Finally, click OK to accept the changes to the new driver: it will appear in the My Libraries list.

 

Using the New Driver

You can now use the new device driver and test the Channel property and OnChannelChanged event.

 

To use the new CobraNet Device

  1. In the Topology View, locate the CO2 device from the Attero Tech category in the My Libraries list:
    Click and drag the device to add it to your topology.

  2. Connect the Ethernet input port of the CobraNet device to the Ethernet port of your Computer device.

  3. In the Properties Grid, ensure that the IP Address matches your device's IP Address.

 

To create an Action to set the Channel

  1. In the Forms View, from the Controls tab of the Toolbox, click and drag a MultiPositionKnob control onto the form.

  2. Double-click the knob control to display the Actions Editor.
    The selected event is multiPositionKnob1.ValueChanged: this is the event that we wish to capture to change the device's channel.

  3. Add the following Action to set the Channel property:
    Devices – CO2 (1) – Audio Output – Set Channel to

  4. Set the Channel property to:
    Controls – multiPositionKnob1 – Value

  5. Click Ok to close the Actions dialog.

 

To create an Action to respond to the OnChannelChanged event

  1. From the Controls tab of the Toolbox, click and drag a DigitalLED control onto the form.

  2. In the Properties Grid, set the digital LED control's Text property to "0".

  3. Double-click the form to display the Actions Editor, and select the CobraNet device's OnChannelChanged event:
    Devices – CO2 (1) – Audio Output – OnChannelChanged

  4. Add the following Action to set the digital LED's Text property:
    Controls – Form1 – digitalLED1 – Set Text to

  5. Set the Text property to:
    Devices – CO2 (1) – Audio Output – Channel

  6. Click Ok to close the Actions dialog.

 

Run the project: when you change the position of the knob, the value of the digital LED changes, and you should be able to verify on your physical device that the source channel for the device's audio output 1 has changed, and by refreshing the CO2 Demonstration Utility application.

 

Similarly, your control application should respond to any changes in the device's audio output that are set from the CO2 Demonstration Utility.

 

You will also see the events and commands displayed in the debug output.

 

 

01/01/2007 17:09:24   Info    multiPositionKnob1, ValueChanged

01/01/2007 17:09:24   Info    Action CO2 (1).Audio Output.Channel = multiPositionKnob1.Value, Executed

01/01/2007 17:09:24   Debug   CO2 (1).Ethernet, SNMP Set [1.3.6.1.4.1.2680.1.1.7.1.1.2.1] : 2

01/01/2007 17:09:24   Info    CO2 (1).Audio Output, OnChannelChanged

01/01/2007 17:09:24   Info    Action digitalLED1.Text = CO2 (1).Audio Output.Channel

 

 

See Also

Write my Own Driver

Class Library

Attero Tech

CobraNet