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"); } }
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(); }