2013-01-15 35 views
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(字符串)和信道(鍵+值)

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

如何讓我的字典的智能搜索/互爲作用,並保存所有紅色標識+密鑰,以SetColor() ???

這是我做的一個「紅色」通道的方式:

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

我希望這是有道理的。非常感謝你的幫助!

+0

你在詞典中存儲什麼? –

+0

你在「Channel(Key + Value)」中指的是「Value」是什麼? 「值」是「燈」和「綠色」之間的數字嗎? – JLRishe

+0

我在詞典中存儲的密鑰是​​例如Lamp1Red(字符串)。值是用於頻道的0-255。 –

回答

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; 
     } 
    } 
    ....... 
} 
1

爲什麼不能有這樣的事情:

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

然後映射燈名稱(如燈1)它:

Dictionary<string,LampInfo> dmxChannelsDictionary; 

要填充你會做soemthing這樣的:

然後你可以這樣做:

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

然後讓你不得不說的數據:

var lamp=dmxChannelsDictionary["Lamp1"]; 
int red=lamp.Red; 
+0

非常感謝您的快速回復!我想要做的是讓所有的燈串/燈用於紅色(在本例中爲2,5,8)。此後,我想將所有帶RED值的通道/鍵值(0-255)傳遞給方法SetColor()。非常感謝。 –

相關問題