public override void StartSearch() { foundDevices.Clear(); OnStartSearch.Invoke(); #if UNITY_EDITOR #if UNITY_EDITOR_WIN string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { CommDevice foundDevice = new CommDevice(); foundDevice.name = port; foundDevice.address = "//./" + port; foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); } #elif UNITY_EDITOR_OSX string prefix = "/dev/"; string[] ports = Directory.GetFiles(prefix, "*.*"); foreach (string port in ports) { if (port.StartsWith("/dev/cu.")) { CommDevice foundDevice = new CommDevice(); foundDevice.name = port.Substring(prefix.Length); foundDevice.address = port; foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); } } #endif #else #if UNITY_STANDALONE_WIN string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { CommDevice foundDevice = new CommDevice(); foundDevice.name = port; foundDevice.address = "//./" + port; foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); } #elif UNITY_STANDALONE_OSX string prefix = "/dev/"; string[] ports = Directory.GetFiles(prefix, "*.*"); foreach (string port in ports) { if (port.StartsWith("/dev/cu.")) { CommDevice foundDevice = new CommDevice(); foundDevice.name = port.Substring(prefix.Length); foundDevice.address = port; foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); } } #endif #endif OnStopSearch.Invoke(); }
// Update is called once per frame void Update() { if (_threadOnOpen) { OnOpen.Invoke(); _threadOnOpen = false; } if (_threadOnOpenFailed) { ErrorClose(); OnOpenFailed.Invoke(); _threadOnOpenFailed = false; } if (_threadOnErrorClosed) { ErrorClose(); OnErrorClosed.Invoke(); _threadOnErrorClosed = false; } if (_threadOnStartSearch) { OnStartSearch.Invoke(); _threadOnStartSearch = false; } if (_threadOnStopSearch) { OnStopSearch.Invoke(); _threadOnStopSearch = false; } if (_threadOnFoundDevice) { OnFoundDevice.Invoke(new CommDevice(foundDevices[foundDevices.Count - 1])); _threadOnFoundDevice = false; } if (_threadOnChangedDevice) { OnChangedDevice.Invoke(new CommDevice(device)); _threadOnChangedDevice = false; } if (_threadOnWriteCompleted) { OnWriteCompleted.Invoke(); _threadOnWriteCompleted = false; } if (_searchTimeout > 0f) { _searchTimeout -= Time.deltaTime; if (_searchTimeout <= 0f) { StopSearch(); } } }
public override void StopSearch() { if (_searchTimeout <= 0f) { return; } #if UNITY_ANDROID if (_android != null) { _android.Call("StopSearch"); } #endif _searchTimeout = 0f; OnStopSearch.Invoke(); }
public override void StartSearch() { foundDevices.Clear(); OnStartSearch.Invoke(); #if UNITY_STANDALONE #if UNITY_EDITOR_WIN WindowPortSearch(); #elif UNITY_EDITOR_OSX OsxPortSearch(); #elif UNITY_STANDALONE_WIN WindowPortSearch(); #elif UNITY_STANDALONE_OSX OsxPortSearch(); #else Debug.Log("CommSerial: Not Supported Platform!"); #endif #endif OnStopSearch.Invoke(); }
void Update() { if (_threadOnOpenFailed) { OnOpenFailed.Invoke(); _threadOnOpenFailed = false; } if (_searchTimeout > 0f) { _searchTimeout -= Time.deltaTime; if (_searchTimeout <= 0f) { #if UNITY_ANDROID if (_android != null) { _android.Call("StopSearch"); } #endif OnStopSearch.Invoke(); } } }