コード例 #1
0
        private void Step()
        {
            running = true;
            do
            {
                using (client = listener.AcceptSocket())
                {
                    connected = true;
                    do
                    {
                        try
                        {
                            // Socket to serial
                            byte[] buffer    = new byte[1024];
                            int    bytesRead = client.Receive(buffer);
                            if (bytesRead > 0)
                            {
                                sketch.WriteSerial(buffer.Take(bytesRead).ToArray());
                            }

                            // Break if we're no longer running or if we read 0 bytes
                            connected = running && bytesRead > 0;
                        }
                        catch
                        {
                            connected = false;
                        }
                    }while (connected);
                }
                client = null;
            }while (running);
        }
コード例 #2
0
 private void sendButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(inputTextBox.Text))
     {
         return;
     }
     sketch.WriteSerial(Parse(inputTextBox.Text));
     inputTextBox.Clear();
 }
コード例 #3
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");
            }
        }
コード例 #4
0
        private void initializeSketch()
        {
            sketch = Sketch.Current;
            sketch.RegisterStats(false);

            sketch.SetMillis(0);
            sketch.Setup();

            performHandshake();
            // load an empty program, just in case.
            sketch.WriteSerial(emptyProgram);

            sketch.Loop();
        }