Example #1
0
        public LedController(int numberOfLeds, string comName, int baud,  Monitor monitor)
        {
            this.monitor = monitor;
            this.numberOfLeds = numberOfLeds;
            buffer = new byte[(numberOfLeds * 3) + 6];
            buffer[0] = Convert.ToByte('A');
            buffer[1] = Convert.ToByte('d');
            buffer[2] = Convert.ToByte('a');

            buffer[3] = (byte)((numberOfLeds - 1));
            buffer[4] = (byte)(0);
            buffer[5] = (byte)(buffer[3] ^ buffer[4] ^ 0x55);

            sp = new SerialPort(comName, baudRate: baud);
            sp.DataReceived += sp_DataReceived;
            sp.Open();
        }
Example #2
0
        public Form1()
        {
            monitor = new Monitor();
            lc = new LedController(50, SerialPort.GetPortNames()[0], 115200, monitor);
            InitializeComponent();

            monitor.Show();
            lc.sp.DataReceived += sp_DataReceived;

            for (int i = 1; i <= 50; i++)
            {
                ListViewItem li = new ListViewItem(string.Format("Led #{0}", i), i - 1);

                listView1.Items.Add(li);
            }
            listView1.ItemSelectionChanged += listView1_ItemSelectionChanged;
        }