|
@@ -11,6 +11,7 @@ namespace ShakerControl.ViewModel
|
|
|
|
|
|
internal class PowerAmplifierViewModel : ViewModelBase<Shaker.Model.PowerAmplifierModel>
|
|
internal class PowerAmplifierViewModel : ViewModelBase<Shaker.Model.PowerAmplifierModel>
|
|
{
|
|
{
|
|
|
|
+ private const int SLEEP_TIME = 500;
|
|
public ShakerControlViewModel Parent { get; init; }
|
|
public ShakerControlViewModel Parent { get; init; }
|
|
private IPLCControl _control;
|
|
private IPLCControl _control;
|
|
private object locker = new object();
|
|
private object locker = new object();
|
|
@@ -44,19 +45,25 @@ namespace ShakerControl.ViewModel
|
|
public ICommand StopCommand => new DelegateCommand(StopControl);
|
|
public ICommand StopCommand => new DelegateCommand(StopControl);
|
|
public ICommand ResetCommand => new DelegateCommand(ResetControl);
|
|
public ICommand ResetCommand => new DelegateCommand(ResetControl);
|
|
public ICommand GainSwitchCommand => new DelegateCommand<ExCommandParameter>(GainSwitchControl);
|
|
public ICommand GainSwitchCommand => new DelegateCommand<ExCommandParameter>(GainSwitchControl);
|
|
- public void StartControl()
|
|
|
|
|
|
+ public async void StartControl()
|
|
{
|
|
{
|
|
Parent.PublishLog("启动功放");
|
|
Parent.PublishLog("启动功放");
|
|
|
|
+ _control.WriteBit(Model.StartAddress, Model.StopBitIndex, false);
|
|
|
|
+ await Task.Delay(SLEEP_TIME);
|
|
_control.WriteBit(Model.StartAddress, Model.StartBitIndex, true);
|
|
_control.WriteBit(Model.StartAddress, Model.StartBitIndex, true);
|
|
}
|
|
}
|
|
- public void StopControl()
|
|
|
|
|
|
+ public async void StopControl()
|
|
{
|
|
{
|
|
Parent.PublishLog("停止功放");
|
|
Parent.PublishLog("停止功放");
|
|
|
|
+ _control.WriteBit(Model.StopAddress, Model.StopBitIndex, false);
|
|
|
|
+ await Task.Delay(SLEEP_TIME);
|
|
_control.WriteBit(Model.StopAddress, Model.StopBitIndex, true);
|
|
_control.WriteBit(Model.StopAddress, Model.StopBitIndex, true);
|
|
}
|
|
}
|
|
- public void ResetControl()
|
|
|
|
|
|
+ public async void ResetControl()
|
|
{
|
|
{
|
|
Parent.PublishLog("复位报警");
|
|
Parent.PublishLog("复位报警");
|
|
|
|
+ _control.WriteBit(Model.ResetAddress, Model.StopBitIndex, false);
|
|
|
|
+ await Task.Delay(SLEEP_TIME);
|
|
_control.WriteBit(Model.ResetAddress, Model.ResetBitIndex, true);
|
|
_control.WriteBit(Model.ResetAddress, Model.ResetBitIndex, true);
|
|
}
|
|
}
|
|
public void GainSwitchControl(ExCommandParameter parameter)
|
|
public void GainSwitchControl(ExCommandParameter parameter)
|
|
@@ -66,9 +73,11 @@ namespace ShakerControl.ViewModel
|
|
GainSwitchControl(switchon);
|
|
GainSwitchControl(switchon);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public void GainSwitchControl(bool switchon)
|
|
|
|
|
|
+ public async void GainSwitchControl(bool switchon)
|
|
{
|
|
{
|
|
Parent.PublishLog($"{(switchon ? "打开" : "关闭")}增益");
|
|
Parent.PublishLog($"{(switchon ? "打开" : "关闭")}增益");
|
|
|
|
+ _control.WriteBit(Model.GainSwitchAddress, Model.StopBitIndex, false);
|
|
|
|
+ await Task.Delay(SLEEP_TIME);
|
|
_control.WriteBit(Model.GainSwitchAddress, Model.GainSwitchBitIndex, switchon);
|
|
_control.WriteBit(Model.GainSwitchAddress, Model.GainSwitchBitIndex, switchon);
|
|
if (!switchon) SetGain(0);
|
|
if (!switchon) SetGain(0);
|
|
}
|
|
}
|