修改页面中点击按钮显示冰箱温度,添加两个冰箱设置
This commit is contained in:
parent
6252aca09a
commit
e5f3877af5
|
@ -70,6 +70,14 @@
|
|||
<add key="FridgeState" value="0"/>
|
||||
<!--报警状态1关闭;0打开-->
|
||||
<add key="AlarmState" value="0"/>
|
||||
|
||||
|
||||
<!--冰箱2抽屉温度区间-->
|
||||
<add key="temperatureRange2" value="2-8"/>
|
||||
<!--冰箱2状态1关闭;0打开-->
|
||||
<add key="FridgeState2" value="0"/>
|
||||
<!--冰箱2报警状态1关闭;0打开-->
|
||||
<add key="AlarmState2" value="0"/>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace DM_Weight.Common
|
|||
bool bERange = int.TryParse(rang[1], out int eRange);
|
||||
if (bSRange && bERange)
|
||||
{
|
||||
if (sRange < 2 || eRange > 8)
|
||||
if ((sRange < 2 || eRange > 8||sRange>8||eRange<2))
|
||||
{
|
||||
tips = "温度区间设置2-8度,请检查输入";
|
||||
return new ValidationResult(flag, tips);
|
||||
|
|
|
@ -1498,7 +1498,7 @@ namespace DM_Weight.Port
|
|||
/// 获取冰箱温度
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<float> GetFridgeTemperature()
|
||||
public async Task<float> GetFridgeTemperature(int iIndex)
|
||||
{
|
||||
float temperature = 0.0f;
|
||||
try
|
||||
|
|
|
@ -32,6 +32,18 @@ namespace DM_Weight.ViewModels
|
|||
CommonClass.SaveAppSetting("temperatureRange", _temperatureRange);
|
||||
}
|
||||
}
|
||||
//冰箱2温度区间
|
||||
private string _temperatureRange2 = CommonClass.ReadAppSetting("temperatureRange2").ToString();
|
||||
public string TemperatureRange2
|
||||
{
|
||||
get => _temperatureRange2;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _temperatureRange2, value);
|
||||
//更新配置文件中冰箱温度区间
|
||||
CommonClass.SaveAppSetting("temperatureRange2", _temperatureRange2);
|
||||
}
|
||||
}
|
||||
private float defaultValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
|
||||
//温度值
|
||||
private float _temperatureValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
|
||||
|
@ -77,6 +89,22 @@ namespace DM_Weight.ViewModels
|
|||
set => SetProperty(ref _alarmState, value);
|
||||
}
|
||||
|
||||
|
||||
//冰箱2状态:true关;false开
|
||||
private bool _fridgeState2;
|
||||
public bool FridgeState2
|
||||
{
|
||||
get => _fridgeState2;
|
||||
set => SetProperty(ref _fridgeState2, value);
|
||||
}
|
||||
//冰箱2报警状态:true关;false开
|
||||
private bool _alarmState2;
|
||||
public bool AlarmState2
|
||||
{
|
||||
get => _alarmState2;
|
||||
set => SetProperty(ref _alarmState2, value);
|
||||
}
|
||||
|
||||
private int _defaultLoginMode;//1开0关
|
||||
|
||||
private int _defaultAlarmMode;//1开0关
|
||||
|
@ -121,6 +149,20 @@ namespace DM_Weight.ViewModels
|
|||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("FridgeState", "1");
|
||||
}
|
||||
|
||||
//冰箱2 发送冰箱使能/失能指令
|
||||
if (_fridgeState2)
|
||||
{
|
||||
await _portUtil.FridgeOff();
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("FridgeState2", "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
await _portUtil.FridegOpen();
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("FridgeState2", "1");
|
||||
}
|
||||
//}
|
||||
//温度报警设定
|
||||
//if (AlarmState != _defaultAlarmMode.Equals(1))
|
||||
|
@ -138,6 +180,20 @@ namespace DM_Weight.ViewModels
|
|||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("AlarmState", "1");
|
||||
}
|
||||
|
||||
//冰箱2 发送警报使能/失能指令
|
||||
if (_alarmState2)
|
||||
{
|
||||
await _portUtil.FridgeAlarmOff();
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("AlarmState2", "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
await _portUtil.FridgeAlarmOn();
|
||||
Thread.Sleep(100);
|
||||
CommonClass.SaveAppSetting("AlarmState2", "1");
|
||||
}
|
||||
//}
|
||||
|
||||
//if (retTemperature != TemperatureValue)
|
||||
|
@ -147,7 +203,7 @@ namespace DM_Weight.ViewModels
|
|||
|
||||
// CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString());
|
||||
//}
|
||||
//设定冰箱温度区间
|
||||
//设定冰箱1温度区间
|
||||
string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
|
||||
string[] newRange = TemperatureRange.Split('-');
|
||||
if (range.Length >= 2)
|
||||
|
@ -166,13 +222,39 @@ namespace DM_Weight.ViewModels
|
|||
if (Max != Convert.ToSingle(newRange[1]))
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
//设定冰箱温度最有值
|
||||
//设定冰箱温度最大值
|
||||
await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]));
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//设定冰箱2温度区间
|
||||
string[] range2 = ConfigurationManager.AppSettings["temperatureRange2"].Split('-');
|
||||
string[] newRange2 = TemperatureRange2.Split('-');
|
||||
if (range2.Length >= 2)
|
||||
{
|
||||
bool bMix = float.TryParse(range2[0], out float Min);
|
||||
bool bMax = float.TryParse(range2[1], out float Max);
|
||||
|
||||
if (bMix && bMax)
|
||||
{
|
||||
if (Min != Convert.ToSingle(newRange2[0]))
|
||||
{
|
||||
//设定冰箱温度最小值
|
||||
await _portUtil.FridgeMinSetting(Convert.ToSingle(newRange2[0]));
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
if (Max != Convert.ToSingle(newRange2[1]))
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
//设定冰箱温度最大值
|
||||
await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange2[1]));
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_portUtil.FridgeOperate = false;
|
||||
AlertMsg alertMsg = new AlertMsg
|
||||
{
|
||||
|
|
|
@ -281,7 +281,7 @@ namespace DM_Weight.ViewModels
|
|||
{
|
||||
string retStr = string.Empty;
|
||||
byte[] data = null;
|
||||
float retT = await _portUtil.GetFridgeTemperature();
|
||||
float retT = await _portUtil.GetFridgeTemperature(1);
|
||||
Thread.Sleep(80);
|
||||
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃";
|
||||
}
|
||||
|
@ -293,9 +293,11 @@ namespace DM_Weight.ViewModels
|
|||
{
|
||||
string retStr = string.Empty;
|
||||
byte[] data = null;
|
||||
float retT = await _portUtil.GetFridgeTemperature();
|
||||
float retT = await _portUtil.GetFridgeTemperature(1);
|
||||
Thread.Sleep(80);
|
||||
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃";
|
||||
float retTemp = await _portUtil.GetFridgeTemperature(2);
|
||||
Thread.Sleep(80);
|
||||
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃;{retTemp}℃";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -330,6 +332,17 @@ namespace DM_Weight.ViewModels
|
|||
}
|
||||
return "数据异常";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看冰箱温度
|
||||
/// </summary>
|
||||
public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); }
|
||||
private void CheckAction()
|
||||
{
|
||||
GetWD();
|
||||
}
|
||||
|
||||
|
||||
//这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作
|
||||
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
|
||||
{
|
||||
|
@ -403,20 +416,20 @@ namespace DM_Weight.ViewModels
|
|||
};
|
||||
timer.Start();
|
||||
}
|
||||
#region 温度查询定时
|
||||
int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
||||
if (interval > 0)
|
||||
{
|
||||
WDTimer = new System.Timers.Timer();
|
||||
//#region 温度查询定时
|
||||
//int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
||||
//if (interval > 0)
|
||||
//{
|
||||
// WDTimer = new System.Timers.Timer();
|
||||
|
||||
WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD);
|
||||
WDTimer.Interval = interval;
|
||||
//WDTimer.Start();
|
||||
//WDTimer.AutoReset = true;
|
||||
//WDTimer.Enabled = true;
|
||||
}
|
||||
#endregion
|
||||
GetWD();
|
||||
// WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD);
|
||||
// WDTimer.Interval = interval;
|
||||
// //WDTimer.Start();
|
||||
// //WDTimer.AutoReset = true;
|
||||
// //WDTimer.Enabled = true;
|
||||
//}
|
||||
//#endregion
|
||||
//GetWD();
|
||||
if (stopRecord > 0)
|
||||
{
|
||||
System.Timers.Timer timer = new System.Timers.Timer();
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
</i:Interaction.Behaviors>
|
||||
<Grid Width="400">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
|
@ -41,6 +42,19 @@
|
|||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
materialDesign:HintAssist.Hint="温度区间2-8度以-分隔"
|
||||
Margin="6 0 0 10"
|
||||
Style="{StaticResource MaterialDesignOutlinedTextBox}">
|
||||
<TextBox.Text>
|
||||
<Binding Path="TemperatureRange2" Delay="1000" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
|
||||
<Binding.ValidationRules>
|
||||
<rules:TemperatureRangeRule/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<!--<TextBlock Text="冰箱温度:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="14" FontWeight="Bold" />
|
||||
<TextBox Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
|
@ -61,6 +75,14 @@
|
|||
x:Name="MaterialDesignFilledTextBoxEnabledComboBox"
|
||||
Style="{StaticResource MaterialDesignActionToggleButton}"
|
||||
IsChecked="{Binding FridgeState}"
|
||||
ToolTip="冰箱状态"
|
||||
Content="打开"
|
||||
materialDesign:ToggleButtonAssist.OnContent="关闭" />
|
||||
<ToggleButton Grid.Row="2" Grid.Column="2" Width="38" Height="38" Margin="6 18 0 0"
|
||||
HorizontalAlignment="Left"
|
||||
|
||||
Style="{StaticResource MaterialDesignActionToggleButton}"
|
||||
|
||||
ToolTip="冰箱状态"
|
||||
Content="打开"
|
||||
materialDesign:ToggleButtonAssist.OnContent="关闭" />
|
||||
|
@ -69,6 +91,13 @@
|
|||
HorizontalAlignment="Left"
|
||||
Style="{StaticResource MaterialDesignActionToggleButton}"
|
||||
IsChecked="{Binding AlarmState}"
|
||||
ToolTip="报警状态"
|
||||
Content="打开"
|
||||
materialDesign:ToggleButtonAssist.OnContent="关闭" />
|
||||
<ToggleButton Grid.Row="3" Grid.Column="2" Width="38" Height="38" Margin="6 18 0 0"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{StaticResource MaterialDesignActionToggleButton}"
|
||||
|
||||
ToolTip="报警状态"
|
||||
Content="打开"
|
||||
materialDesign:ToggleButtonAssist.OnContent="关闭" />
|
||||
|
|
|
@ -118,7 +118,8 @@
|
|||
<Grid Grid.Column="2">
|
||||
<StackPanel Margin="6" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="储物箱" Command="{Binding OpenRecoverCommand}" Visibility="{Binding Is16Drawer, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MaterialDesignFlatSecondaryLightButton}" />
|
||||
<TextBlock Margin="0,10,10,0" Text="{Binding WD}" Foreground="White" FontWeight="Bold" FontSize="14"/>
|
||||
<!--<TextBlock Margin="0,10,10,0" Text="{Binding WD}" Foreground="White" FontWeight="Bold" FontSize="14"/>-->
|
||||
<Button Content="查看冰箱温度" Command="{Binding CheckWDCommand}" Style="{StaticResource MaterialDesignFlatSecondaryLightButton}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
|
|
Loading…
Reference in New Issue