private void Disconnect() { if (!IsConnected) { return; } // If there is a user-defined tear-down function, execute it before // closing the underlying COM port. userDefinedTearDownFunction?.Invoke(); StopSampling(); // The serialThread reference should never be null at this point, // unless an Exception happened in the OnEnable(), in which case I've // no idea what face Unity will make. if (serialThread != null) { serialThread.RequestStop(); serialThread = null; } // This reference shouldn't be null at this point anyway. if (thread != null) { thread.Join(); thread = null; } IsConnected = false; Debug.Log("Serial disconnected:PITACO"); }
public void Connect() { //#if UNITY_EDITOR // if (testPitacoConnection) // { // Debug.Log("Debug PITACO connected!"); // IsConnected = true; // return; // } //#endif // Debug.Log("Looking for PITACO..."); var portName = AutoConnect(); if (string.IsNullOrEmpty(portName)) { Debug.LogWarning("Failed to connect PITACO!"); StartCoroutine(Reconnect()); return; } serialThread = new SerialThreadPitaco(portName, baudRate, reconnectionDelay, maxUnreadMessages); thread = new Thread(serialThread.RunForever); thread.Start(); IsConnected = true; Debug.Log($"Connected to {portName}:{baudRate}:PITACO"); }
public void Connect() { Debug.Log("Looking for PITACO..."); var portName = AutoConnect(); if (string.IsNullOrEmpty(portName)) { Debug.LogWarning("Failed to connect PITACO!"); return; } serialThread = new SerialThreadPitaco(portName, baudRate, reconnectionDelay, maxUnreadMessages); thread = new Thread(serialThread.RunForever); thread.Start(); IsConnected = true; Debug.Log($"Connected to {portName}:{baudRate}:PITACO"); }