Exemple #1
0
        public override void Write(byte[] data, bool getCompleted = false)
        {
            if (data == null)
            {
                return;
            }
            if (data.Length == 0)
            {
                return;
            }

#if UNITY_STANDALONE
            try
            {
                _serialPort.Write(data, 0, data.Length);
                if (getCompleted)
                {
                    OnWriteCompleted.Invoke();
                }
            }
            catch (Exception)
            {
                ErrorClose();
                OnErrorClosed.Invoke();
            }
#endif
        }
Exemple #2
0
        // 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();
                }
            }
        }
Exemple #3
0
 private void WriteCallback(IAsyncResult result)
 {
     try
     {
         _client.GetStream().EndWrite(result);
         OnWriteCompleted.Invoke();
     }
     catch (Exception e)
     {
         //    Debug.LogError("WriteCallback Error");
         //    Debug.LogError(e);
         ErrorClose();
     }
 }
Exemple #4
0
        void LateUpdate()
        {
            if (IsOpen && _txBuffer.Count > 0)
            {
#if UNITY_ANDROID
                if (_android != null)
                {
                    _android.Call("Write", _txBuffer.ToArray());
                }
#endif
                _txBuffer.Clear();
                if (_getCompleted)
                {
                    OnWriteCompleted.Invoke();
                }
            }
        }
 void LateUpdate()
 {
     if (IsOpen && _txBuffer.Count > 0)
     {
         try
         {
             _socket.Send(_txBuffer.ToArray());
             _txBuffer.Clear();
             if (_getCompleted)
             {
                 OnWriteCompleted.Invoke();
             }
         }
         catch (Exception e)
         {
             Debug.Log("Write: " + e);
             ErrorClose();
             OnErrorClosed.Invoke();
         }
     }
 }