Example #1
0
 void Update()
 {
     if (serialPort != null && serialPort.PortOpen())
     {
         char cc;
         uint numRead;
         do
         {
             bool connectionHealthy = serialPort.ReadChar(out cc, out numRead);
             if (!connectionHealthy)
             {
                 ConnectionLost();
                 return;
             }
             if (numRead > 0)
             {
                 if (cc == '\r')
                 {
                     continue;
                 }
                 else if (cc == '\n' || (int)cc == 0)
                 {
                     puzzletConnection.HandleMessage(PuzzletUtility.ParseMessage(partialLine));
                     partialLine = "";
                 }
                 else
                 {
                     partialLine += cc;
                 }
             }
         } while (numRead > 0);
     }
 }
Example #2
0
        //find and connect to a Play Tray
        public void Connect()
        {
            PortName    = "";
            partialLine = "";
            string[] playTrays = PuzzletUtility.GetPlayTrayPorts();
            Debug.Log("all play trays");
            foreach (string playTray in playTrays)
            {
                Debug.Log(playTray);
            }
            foreach (string playTray in playTrays)
            {
                if (!badConnections.Contains(playTray))
                {
                    PortName = playTray;
                    break;
                }
            }
            if (PortName == "")
            {
                badConnections.Clear();
                StartCoroutine(RetryConnection());
                return;
            }
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            serialPort = new WindowsSerial();
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
            serialPort = new MacSerial();
#endif
            serialPort.OpenSerial(PortName, Baud);
            puzzletConnection.PuzzletConnected();
        }
        IEnumerator CheckVersion()
        {
            passed = false;

            while(!didTryDownloadVersion)
                yield return 0;

            while(!passed)
            {
                if(!PuzzletConnection.Connected)
                    yield break;

                //check hardcoded and network firmwares
                bool passedHardcodedFirmware = PuzzletUtility.CheckFirmwareVersion();

                bool passedNetworkFirmware = true;
                if(requiredVersions != null)
                     passedNetworkFirmware = PuzzletUtility.CheckFirmwareVersion(requiredVersions[PuzzletConnection.HardwareVersion]);

                //show required version appropriate to which check failed (if they failed)
                if(!passedHardcodedFirmware)
                    needsText.text = PuzzletUtility.RequiredFirmwareString().Substring(0,5);

                if(!passedNetworkFirmware)
                    needsText.text = PuzzletUtility.FirmwareString(requiredVersions[PuzzletConnection.HardwareVersion]).Substring(0,5);

                currentText.text = PuzzletUtility.FirmwareString().Substring(0,5);

                //stay up or dismiss depending on check
                passed = passedHardcodedFirmware && passedNetworkFirmware;

                if(passed)
                    updatePrompt.SetActive(false);
                else
                {
                    updatePrompt.SetActive(true);
                    yield return 0;
                }
            }
        }
Example #4
0
 public void PuzzletReceiveMessageIOS(string message)
 {
     puzzletConnection.HandleMessage(PuzzletUtility.ParseMessage(message));
 }