我想控制 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
我希望这是有道理的。非常感谢你的帮助!