Ejemplo n.º 1
0
 protected virtual void ResolveBytes(Byte[] bytes)
 {
     if (CurrentResolver != null)
     {
         CurrentResolver.ResolveBytes(bytes);
     }
 }
Ejemplo n.º 2
0
 public virtual void Close()
 {
     if (CurrentResolver != null)
     {
         CurrentResolver.Close();
     }
 }
Ejemplo n.º 3
0
    public virtual IEnumerator OnStart(LMBasePortResolver resolver = null)
    {
        if (!OpenPort())
        {
            yield break;
        }

        Debug.Log("端口正常运作,准备接收数据");

        // 获取解释器,并初始化
        CurrentResolver = (resolver != null) ? resolver : GetProperResolver(KeyportData);

        if (CurrentResolver != null)
        {
            CurrentResolver.Init(this);
        }

        // 尝试连接
        yield return(controller.StartCoroutine(TestConnect()));

        if (CurrentResolver != null)
        {
            yield return(controller.StartCoroutine(OnStartResolver()));
        }

        if (!IsConnected)
        {
            Close();
            ErrorTxt = "连接失败,请检查设备是否正确连接";
        }
    }
Ejemplo n.º 4
0
    public override IEnumerator OnStart(LMBasePortResolver resolver = null)
    {
        if (!OpenPort())
        {
            yield break;
        }

        Debug.Log("Port Active, receiving data");

        CurrentResolver = (resolver != null) ? resolver : GetProperResolver(KeyportData);

        if (CurrentResolver != null)
        {
            CurrentResolver.Init(this);
            yield return(controller.StartCoroutine(OnStartResolver()));
        }

        IsPortActive = m_isConnected = true;

        if (!IsConnected)
        {
            Close();
            ErrorTxt = "连接失败,请检查设备是否正确连接";
        }
    }
Ejemplo n.º 5
0
    public virtual float GetRawValue(int index)
    {
        if (CurrentResolver == null)
        {
            return(0f);
        }

        return(CurrentResolver.GetRawValue(index));
    }
Ejemplo n.º 6
0
    public virtual void Close()
    {
        if (CurrentResolver != null && IsPortActive)
        {
            CurrentResolver.Close();
        }

        IsPortActive = false;
        Reset();
    }
Ejemplo n.º 7
0
    protected virtual IEnumerator OnStartResolver()
    {
        if (!IsConnected)
        {
            yield break;
        }

        CurrentResolver.Start();

        yield return(controller.StartCoroutine(TestConnect()));
    }
Ejemplo n.º 8
0
    protected void ReadData(byte[] _bytes)
    {
        if (!m_isInit)
        {
            InitPortResolver();
        }

        m_bytes = _bytes;

        if (m_bytes == null || m_bytes.Length == 0)
        {
            m_cdToReconnect++;
            return;
        }

        m_cdToReconnect = 0f;
        isPortActive    = true;

        CurrentResolver.ResolveBytes(m_bytes);
    }
Ejemplo n.º 9
0
    // 端口写入流程
    private IEnumerator PortWriteRoutine(byte[] bytes)
    {
        while (!IsPortWriting)
        {
            try {
                Port.Write(bytes, 0, bytes.Length);
                IsPortWriting = true;
            } catch (System.TimeoutException ex) {
                Debug.LogWarning(ex);
                Debug.Log("重启写入程序");
            }
        }

        yield return(new WaitForSeconds(0.1f));

        m_isConnected = false;
        yield return(new WaitUntil(() => m_isConnected));

        Debug.Log("校准完毕");
        IsPortWriting = false;

        yield return(controller.StartCoroutine(CurrentResolver.OnFinishPortWrite()));
    }
Ejemplo n.º 10
0
 public virtual void Recalibration()
 {
     CurrentResolver.Recalibration();
 }
Ejemplo n.º 11
0
 protected void InitPortResolver()
 {
     CurrentResolver = GetProperResolver(KeyportData);
     CurrentResolver.Init(this);
     m_isInit = true;
 }
Ejemplo n.º 12
0
    protected override IEnumerator OnStartResolver()
    {
        CurrentResolver.Start();

        yield return(controller.StartCoroutine(TestConnect()));
    }