コード例 #1
0
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            Tuple <DateTime, byte[]> output = sketch.ReadSerial();

            if (output == null)
            {
                return;
            }

            string ascii = Encoding.ASCII.GetString(output.Item2);

            asciiTextBox.AppendText(string.Format("{0:HH:mm:ss.fff} | {1}", output.Item1, ascii));
            asciiTextBox.AppendText(Environment.NewLine);


            string hex = string.Join(" ", output.Item2.Select(b => b.ToString("X2")));

            hexTextBox.AppendText(string.Format("{0:HH:mm:ss.fff} | {1}", output.Item1, hex));
            hexTextBox.AppendText(Environment.NewLine);

            string dec = string.Join(" ", output.Item2);

            decTextBox.AppendText(string.Format("{0:HH:mm:ss.fff} | {1}", output.Item1, dec));
            decTextBox.AppendText(Environment.NewLine);
        }
コード例 #2
0
        private void performHandshake()
        {
            /*
             * INFO(Richo): Perform connection request and handshake.
             * Otherwise, when we send a program later we will be rejected.
             */
            sketch.WriteSerial(new byte[]
            {
                RQ_CONNECTION_REQUEST, MAJOR_VERSION, MINOR_VERSION
            });
            sketch.Loop();
            byte handshake = sketch.ReadSerial().Item2[0];
            byte send      = (byte)((MAJOR_VERSION + MINOR_VERSION + handshake) % 256);

            sketch.WriteSerial(new byte[] { send });
            sketch.Loop();
            byte ack = sketch.ReadSerial().Item2[0];

            if (send != ack)
            {
                throw new InvalidOperationException("Could not perform handshake with the simulator");
            }
        }