0

I want to control a color (in this example "red") in 512 DMX-channels. I read the red color from an XML-file and put it in a Dictionary:

<Channel Id="Lamp1Red" Key="2"/>
<Channel Id="Lamp1Green" Key="3"/>
<Channel Id="Lamp1Blue" Key="4"/>
<Channel Id="Lamp2Red" Key="5"/>
<Channel Id="Lamp2Green" Key="6"/>
<Channel Id="Lamp2Blue" Key="7"/>
<Channel Id="Lamp3Red" Key="8"/>
        etc. ... up to 512 keys/channels.

I have the following Dictionary which contains IDs (string) and Channel(Key+Value)

public Dictionary<string, Tuple<byte, byte>> DmxChannelsDictionary
{
    get;
    set;
}

I want to lookup all strings (red) containing ID "LampXRed" and get the Key (2, 5, 8) for each one of them and use them in the following method SetColor:

SetColor(red, green, blue);
public void SetColor(Tuple<byte, byte> redTuple, Tuple<byte, byte> greenTuple, Tuple<byte, byte> blueTuple)

SetColor passes the Tuples to DmxDataMessage()

public static byte[] DmxDataMessage(Tuple<byte, byte>  redTuple, Tuple<byte, byte> greenTuple, Tuple<byte, byte> blueTuple)
    {
        //Initialize DMX-buffer: Must be full buffer (512Bytes)
        var dmxBuffer = new byte[512];
        dmxBuffer.Initialize();

        // Fill DATA Buffer: Item1 (Key/Channel) = Item2 (Value)
        // Channel1
        dmxBuffer[redTuple.Item1] = redTuple.Item2;
        dmxBuffer[greenTuple.Item1] = greenTuple.Item2;
        dmxBuffer[blueTuple.Item1] = blueTuple.Item2;

        // Here I need a foreach or something else to set the the value for each channel (up to 512)
       ....

How do I make a smart search/interation in the Dictionary and save all red-IDs + Keys for use in SetColor() ???

This is the way I do it for one "red" channel:

var red = DmxChannelsDictionary["Lamp1Red"];
red = Tuple.Create(red.Item1, _redValue); // _redValue = 0-255

I hope this makes sense. Thanks a lot for your help!

4

2 に答える 2

1

Why not have something like this:

class LampInfo
{
  int Red{get;set;}
  int Green{get;set;}
  int Blue{get;set;}
}

and then map the lamp name (eg Lamp1) to it:

Dictionary<string,LampInfo> dmxChannelsDictionary;

To populate you'd do soemthing like this:

Then you can do:

Lamp lamp=new LampInfo(){Red=2, Green=3, Blue=4}'
dmxChannelsDictionary.Add("Lamp1",lamp);

Then to get the data you just have to say:

var lamp=dmxChannelsDictionary["Lamp1"];
int red=lamp.Red;
于 2013-01-15T11:49:24.690 に答える
0

The following fixed my issue - thanks a lot for your help.

public static byte[] DmxDataMessage(Tuple<byte, byte> redTuple, Tuple<byte, byte> greenTuple, Tuple<byte, byte> blueTuple, EnttecDmxController _enttecDmxControllerInterface)
{

    foreach (KeyValuePair<string, Tuple<byte, byte>> entry in _enttecDmxControllerInterface.DmxChannelsDictionary)
    {
        if (entry.Key.Contains("Red"))
        {
            dmxBuffer[entry.Value.Item1] = redTuple.Item2;
        }
    }
     .......
}
于 2013-01-15T23:35:34.090 に答える