private void AndroidMessageFoundDevice(string message) { Debug.Log(message); string[] tokens = message.Split(new char[] { ',' }); CommDevice foundDevice = new CommDevice(); if (tokens[0].Length == 0) { foundDevice.name = tokens[1]; } else { foundDevice.name = tokens[0]; } foundDevice.address = tokens[1]; for (int i = 0; i < foundDevices.Count; i++) { if (foundDevices[i].Equals(foundDevice)) { return; } } foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); }
public override void StartSearch() { foundDevices.Clear(); _searchTimeout = searchTimeout; OnStartSearch.Invoke(); #if UNITY_ANDROID if (_android != null) { string[] devInfos = _android.Call <string[]>("GetBondedDevices"); for (int i = 0; i < devInfos.Length; i++) { string[] tokens = devInfos[i].Split(new char[] { ',' }); CommDevice foundDevice = new CommDevice(); foundDevice.name = tokens[0]; foundDevice.address = tokens[1]; foundDevices.Add(foundDevice); OnFoundDevice.Invoke(foundDevice); } _android.Call("StartSearch"); } #endif }
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(); } } }
private void WindowPortSearch() { 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); } }
private void OsxPortSearch() { 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); } } }