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.
There is a multimedia walk-through of these techniques in the online Technical Resources.
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:
The device's IP Address,
The SNMP Object Identifiers for the parameters within your device that your wish to monitor or control.
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
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.
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.
To create a new CobraNet device driver,
In the Topology View click the Add New Product button, or select Add New Product from the Tools menu, or press F8.
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.
Enter the Model Number of "CO2", and a Description of "CobraNet Development Board". Click OK.
In the Product Properties dialog, click Add to add a new Port.
In the Port Properties dialog enter "Ethernet" as the Name, and select "Cobranet Ethernet Port" as the port Type. Click OK
Click Add to add another Port: enter "Audio Output" as the Name, and select "Cobranet Audio Output" as the port Type.
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
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:
a channelOID string constant with a value of the OID of the device's Transmitter 1 Channel property,
private const string channelOID = "1.3.6.1.4.1.2680.1.1.7.1.1.2.1";
an OnOpened function which is described below,
a private variable channel which holds the value of the channel that the audio output is set to,
private int channel;
a Channel property with a get and a set accessor, described below,
an OnChannelChanged event which will fire when the value of the channel variable is updated,
[Controllable]
public event EventHandler OnChannelChanged;
a function called OnSnmpIn which processes SNMP data received, described below.
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 );
}
overrides the SnmpClientPortInstance base class's OnOpened method,
calls the base class's BeginGetSnmp method is called with the channelOID to begin monitoring the Transmitter 1 Channel property.
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 );
}
overrides the SnmpClientPortInstance base class's OnSnmpIn method,
calls the base class's OnSnmpIn method,
contains a switch statement on the incoming OID,
a case block which is entered if the incoming OID is equal to the channelOID string constant, to allow us to process the response,
within the case block, it first checks whether the incoming value differs from the 's current value,
if it is different, the is assigned the new value, using a cast to convert the value object to an integer,
the OnChannelChanged event checked for subscribers, and is then fired if there are any,
finally, calls the base class's BeginGetSnmp method is called with the channelOID to continue monitoring the Transmitter 1 Channel property.
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.
You can now use the new device driver and test the Channel property and OnChannelChanged event.
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.
Connect the Ethernet input port of the CobraNet device to the Ethernet port of your Computer device.
In the Properties Grid, ensure that the IP Address matches your device's IP Address.
In the Forms View, from the Controls tab of the Toolbox, click and drag a MultiPositionKnob control onto the form.
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.
Add the following Action
to set the Channel property:
Devices –
CO2 (1) –
Audio Output –
Set Channel to
Set the Channel
property to:
Controls –
multiPositionKnob1 –
Value
Click Ok to close the Actions dialog.
From the Controls tab of the Toolbox, click and drag a DigitalLED control onto the form.
In the Properties Grid, set the digital LED control's Text property to "0".
Double-click the form
to display the Actions Editor, and select the CobraNet device's OnChannelChanged event:
Devices –
CO2 (1) –
Audio Output –
OnChannelChanged
Add the following Action
to set the digital LED's Text
property:
Controls –
Form1 –
digitalLED1 –
Set Text to
Set the Text
property to:
Devices –
CO2 (1) –
Audio Output –
Channel
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