Пример #1
0
    private UniRx.IObservable <double> HikeStream()
    {
        return(Observable.Create <double>(obs =>
        {
            if (Verbose)
            {
                MainThreadDispatcher.Post(_ =>
                {
                    Debug.LogFormat("[{0}] Start reading data.", name);
                }, null);
            }

            if (plc.Open() == ErrorCode.NoError)
            {
                if (PLCdata.SetHike(plc) == ErrorCode.NoError)
                {
                    var ttt = 0;
                    while (ttt < TTTDuration)
                    {
                        ttt = (int)((uint)plc.Read("DB9.DBD48")).ConvertToDouble();
                        obs.OnNext(ttt);
                    }
                    obs.OnCompleted();
                }
                else
                {
                    obs.OnError(new Exception("Unable to send msg to plc"));
                }
            }
            else
            {
                obs.OnError(new Exception("Unable to send msg to plc"));
            }
            return Disposable.Create(() =>
            {
                plc.Close();
                if (Verbose)
                {
                    MainThreadDispatcher.Post(_ => Debug.LogFormat("[{0}] Hike Stream disposed.", name), null);
                }
            });
        }).SubscribeOn(Scheduler.ThreadPool));
    }
Пример #2
0
    private void Awake()
    {
        _appStateBroker = AppStateBroker.Instance;
        _appStateBroker.HikeStream.Subscribe(_ => Hike()).AddTo(gameObject);
        _inputModule = InputModule.Instance;

        var _PLCAddres = GameManager.DevMode_External? PLCAddress : Config.Read(CONFIG_KEYS.plcip).ToString();

        plc = new Plc(cpu: CpuType.S71200, ip: _PLCAddres, rack: 0, slot: 1);
        ErrorCode errCode = plc.Open();

        if (Verbose)
        {
            Debug.LogFormat("[{0}] initial status [{2}] => {1}", name, errCode, _PLCAddres);
        }

        var       _DistanceFeet = GameManager.DevMode_External? DistanceFeet : float.Parse(Config.Read(CONFIG_KEYS.distance));
        ErrorCode feet          = PLCdata.SetDistance(plc, _DistanceFeet);

        if (Verbose)
        {
            Debug.LogFormat("[{0}] Setting feet to {2} => {1} feet", name, feet, _DistanceFeet);
        }

        ErrorCode duration = PLCdata.SetTTT(plc, TTTDuration);

        if (Verbose)
        {
            Debug.LogFormat("[{0}] Setting TTT to {2} => {1} secconds", name, duration, TTTDuration);
        }
        plc.Close();

        Debug.Log("////////////////////////////////////");
        Debug.LogFormat("[{0}] initial status [{2}] => {1}", name, errCode, _PLCAddres);
        Debug.Log("////////////////////////////////////");
        //debug binding
        Observable.EveryUpdate()
        .Select(_ => GameManager.TargetObject_External)
        .DistinctUntilChanged()
        .Subscribe(_ => Verbose = (GameManager.TargetObject_External & TargetObject.PLCModule) == TargetObject.PLCModule)
        .AddTo(gameObject);
    }