2 using System.Collections.Generic;
 
   3 using System.ComponentModel;
 
   8 using System.Windows.Forms;
 
  12     public partial class LEDMixer : Form
 
  14         private const int LIGHT_MAX = 0x1F;
 
  18             InitializeComponent();
 
  21         private void LEDMixer_Load(object sender, EventArgs e)
 
  23             String[] PortNames = System.IO.Ports.SerialPort.GetPortNames();
 
  24             Array.Sort<String>(PortNames, delegate(string strA, string strB) { return int.Parse(strA.Substring(3)).CompareTo(int.Parse(strB.Substring(3))); });
 
  26             cbPort.Items.AddRange(PortNames);
 
  28             cbPort.SelectedIndex = 0;
 
  30             tbRed.Maximum = LIGHT_MAX;
 
  31             tbGreen.Maximum = LIGHT_MAX;
 
  32             tbBlue.Maximum = LIGHT_MAX;
 
  35         private void tbRed_Scroll(object sender, EventArgs e)
 
  37             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  40         private void tbGreen_Scroll(object sender, EventArgs e)
 
  42             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  45         private void tbBlue_Scroll(object sender, EventArgs e)
 
  47             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);
 
  50         private void NotifyLight(int Red, int Green, int Blue)
 
  52             byte[] buffer = new byte[3];
 
  53             buffer[0] = (byte)(0x80 | (Red & LIGHT_MAX));
 
  54             buffer[1] = (byte)(0x40 | (Green & LIGHT_MAX));
 
  55             buffer[2] = (byte)(0x20 | (Blue & LIGHT_MAX));
 
  59                 serSerialPort.PortName = cbPort.Text;
 
  61                 serSerialPort.Write(buffer, 0, buffer.Length);
 
  62                 serSerialPort.Close();
 
  70         private void cbPort_SelectedIndexChanged(object sender, EventArgs e)
 
  72             NotifyLight(tbRed.Value, tbGreen.Value, tbBlue.Value);