예제 #1
0
        private async void WriteAllReg()
        {
            canUserOperate = false;
            await Task.Run(() =>
            {
                var regs = rms.GetAllCanWriteAddrs();
                foreach (var reg in regs)
                {
                    rms.WriteRegs(reg.ToArray());
                }
            });

            canUserOperate = true;                   //设置为True后 canExecute不会立刻执行,所以按钮还是Disable状态
            WriteAllRegCmd.RaiseCanExecuteChanged(); //触发CanExecuteChanged()后会立马刷新,但是好像其他命令不需要执行,执行其中一个就可以了
        }
예제 #2
0
        private async void WriteConfigReg()
        {
            if (!File.Exists(ConfigFilePath))
            {
                return;
            }
            canUserOperate = false;
            await Task.Run(() =>
            {
                foreach (var reg in configRegs)
                {
                    //只有有写操作的时候才会将寄存器的值在界面上更新。只读的时候不更新
                    //更新regval的操作放在每一个操作之前。
                    if (reg.OperateType == RegOperateType.Write || reg.OperateType == RegOperateType.WriteRead)
                    {
                        rms[reg.Register.RegAddr] = new Tuple <uint, uint>(rms[reg.Register.RegAddr].Item1, rms[reg.Register.RegAddr].Item1); //需要更新LastVal
                        rms[reg.Register.RegAddr] = new Tuple <uint, uint>(reg.Register.RegVal, rms[reg.Register.RegAddr].Item2);             //再更新RegVal
                    }

                    switch (reg.OperateType)
                    {
                    case RegOperateType.Write:
                        rms.WriteRegs(new UInt32[] { reg.Register.RegAddr }); break;

                    case RegOperateType.Read:
                        rms.ReadRegs(new UInt32[] { reg.Register.RegAddr }); break;

                    case RegOperateType.WriteRead:
                        rms.WriteRegs(new UInt32[] { reg.Register.RegAddr });
                        Thread.Sleep(100);
                        rms.ReadRegs(new UInt32[] { reg.Register.RegAddr });
                        break;
                    }
                    Thread.Sleep(100);
                }
            });

            canUserOperate = true;
            WriteAllRegCmd.RaiseCanExecuteChanged();
        }