0

我想控制 512 个 DMX 通道中的颜色(在本例中为“红色”)。我从 XML 文件中读取红色并将其放入字典中:

<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.

我有以下内容Dictionary,其中包含 ID(字符串)和 Channel(Key+Value)

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

我想查找所有包含 ID“LampXRed”的字符串(红色)并为每个字符串获取密钥(2、5、8),并在以下方法 SetColor 中使用它们:

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

SetColor 将元组传递给 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)
       ....

如何在字典中进行智能搜索/交互并保存所有红色 ID + 键以用于SetColor()???

这是我为一个“红色”频道做的方式:

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

我希望这是有道理的。非常感谢你的帮助!

4

2 回答 2

1

为什么没有这样的东西:

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

然后将灯名称(例如 Lamp1)映射到它:

Dictionary<string,LampInfo> dmxChannelsDictionary;

要填充你会做这样的事情:

然后你可以这样做:

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

然后要获取数据,您只需说:

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

以下解决了我的问题 - 非常感谢您的帮助。

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 回答