Пример #1
0
    private IEnumerator ConnectCoroutine()
    {
        var wait = new WaitForSeconds(0.1f);

        isConnect = false;
        yield return(wait);

        SerialPortName _sp = GetComponent <SerialPortName> ();

        if (_sp == null)
        {
            yield break;
        }
        _serial = SerialHandler.Instance.PortList[_sp.SerialListNo]; //SerialHandlerのリストと紐づく

        //USBの切断
        _serial.Close();
        _serial.OnDataReceived -= OnDataReceived;
        yield return(wait);

        //USBの接続
        joinMsg = string.Empty;
        if (_serial.Open(true))
        {
            _serial.OnDataReceived += OnDataReceived;
            isConnect = true;
        }
        yield break;
    }
    private IEnumerator ConnectCoroutine()
    {
        flg_TimeOver = false;
        timeOver     = 0.0f;

        Now_Mode = MODE.TURMINAL;
        Bef_Mode = MODE.TURMINAL;
        var wait = new WaitForSeconds(0.1f);

        yield return(null);

        if (NowCoroutine != null)
        {
            StopCoroutine(NowCoroutine);
        }
        yield return(null);

        SerialPortName _sp = GetComponent <SerialPortName>();

        if (_sp == null)
        {
            yield break;
        }
        _serial = SerialHandler.Instance.PortList[_sp.SerialListNo];   //SerialHandlerのリストと紐づく

        //USBの切断
        _serial.Close();
        yield return(wait);


        _serial.OnDataReceived -= OnDataRead_Init;
        _serial.OnDataReceived -= OnDataRead_Receive_Interval;
        _serial.OnDataReceived -= OnDataRead_Communication;
        yield return(wait);


        //USBの接続
        _serial.Open(true);
        yield return(wait);


        Now_Mode = MODE.NONE;
        Bef_Mode = MODE.TURMINAL;


        yield break;
    }