修改页面中点击按钮显示冰箱温度,添加两个冰箱设置

This commit is contained in:
maqiao 2024-06-27 16:49:04 +08:00
parent 6252aca09a
commit e5f3877af5
7 changed files with 155 additions and 22 deletions

View File

@ -72,6 +72,14 @@
<add key="AlarmState" value="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"/>
<!-- 抽屉串口的串口号 --><!-- <!-- 抽屉串口的串口号 --><!--
<add key="DrawerPortPath" value="COM11" /> <add key="DrawerPortPath" value="COM11" />

View File

@ -27,7 +27,7 @@ namespace DM_Weight.Common
bool bERange = int.TryParse(rang[1], out int eRange); bool bERange = int.TryParse(rang[1], out int eRange);
if (bSRange && bERange) if (bSRange && bERange)
{ {
if (sRange < 2 || eRange > 8) if ((sRange < 2 || eRange > 8||sRange>8||eRange<2))
{ {
tips = "温度区间设置2-8度请检查输入"; tips = "温度区间设置2-8度请检查输入";
return new ValidationResult(flag, tips); return new ValidationResult(flag, tips);

View File

@ -1498,7 +1498,7 @@ namespace DM_Weight.Port
/// 获取冰箱温度 /// 获取冰箱温度
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<float> GetFridgeTemperature() public async Task<float> GetFridgeTemperature(int iIndex)
{ {
float temperature = 0.0f; float temperature = 0.0f;
try try

View File

@ -32,6 +32,18 @@ namespace DM_Weight.ViewModels
CommonClass.SaveAppSetting("temperatureRange", _temperatureRange); 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 defaultValue = Convert.ToSingle(CommonClass.ReadAppSetting("temperatureValue"));
//温度值 //温度值
private float _temperatureValue = 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); 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 _defaultLoginMode;//1开0关
private int _defaultAlarmMode;//1开0关 private int _defaultAlarmMode;//1开0关
@ -121,6 +149,20 @@ namespace DM_Weight.ViewModels
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("FridgeState", "1"); 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)) //if (AlarmState != _defaultAlarmMode.Equals(1))
@ -138,6 +180,20 @@ namespace DM_Weight.ViewModels
Thread.Sleep(100); Thread.Sleep(100);
CommonClass.SaveAppSetting("AlarmState", "1"); 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) //if (retTemperature != TemperatureValue)
@ -147,7 +203,7 @@ namespace DM_Weight.ViewModels
// CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString()); // CommonClass.SaveAppSetting("temperatureValue", TemperatureValue.ToString());
//} //}
//设定冰箱温度区间 //设定冰箱1温度区间
string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-'); string[] range = ConfigurationManager.AppSettings["temperatureRange"].Split('-');
string[] newRange = TemperatureRange.Split('-'); string[] newRange = TemperatureRange.Split('-');
if (range.Length >= 2) if (range.Length >= 2)
@ -166,13 +222,39 @@ namespace DM_Weight.ViewModels
if (Max != Convert.ToSingle(newRange[1])) if (Max != Convert.ToSingle(newRange[1]))
{ {
Thread.Sleep(100); Thread.Sleep(100);
//设定冰箱温度最 //设定冰箱温度最
await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1])); await _portUtil.FridgeMaxSetting(Convert.ToSingle(newRange[1]));
Thread.Sleep(100); 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; _portUtil.FridgeOperate = false;
AlertMsg alertMsg = new AlertMsg AlertMsg alertMsg = new AlertMsg
{ {

View File

@ -281,7 +281,7 @@ namespace DM_Weight.ViewModels
{ {
string retStr = string.Empty; string retStr = string.Empty;
byte[] data = null; byte[] data = null;
float retT = await _portUtil.GetFridgeTemperature(); float retT = await _portUtil.GetFridgeTemperature(1);
Thread.Sleep(80); Thread.Sleep(80);
WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃"; WD = $"恒温冷藏抽屉当前温度:{Math.Round((retT - 1.5), 2)}℃";
} }
@ -293,9 +293,11 @@ namespace DM_Weight.ViewModels
{ {
string retStr = string.Empty; string retStr = string.Empty;
byte[] data = null; byte[] data = null;
float retT = await _portUtil.GetFridgeTemperature(); float retT = await _portUtil.GetFridgeTemperature(1);
Thread.Sleep(80); 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> /// <summary>
@ -330,6 +332,17 @@ namespace DM_Weight.ViewModels
} }
return "数据异常"; return "数据异常";
} }
/// <summary>
/// 查看冰箱温度
/// </summary>
public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); }
private void CheckAction()
{
GetWD();
}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截continuationCallback(false)拦截本次操作 //这个方法用于拦截请求,continuationCallback(true)就是不拦截continuationCallback(false)拦截本次操作
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback) public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{ {
@ -403,20 +416,20 @@ namespace DM_Weight.ViewModels
}; };
timer.Start(); timer.Start();
} }
#region //#region 温度查询定
int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); //int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
if (interval > 0) //if (interval > 0)
{ //{
WDTimer = new System.Timers.Timer(); // WDTimer = new System.Timers.Timer();
WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD); // WDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWD);
WDTimer.Interval = interval; // WDTimer.Interval = interval;
//WDTimer.Start(); // //WDTimer.Start();
//WDTimer.AutoReset = true; // //WDTimer.AutoReset = true;
//WDTimer.Enabled = true; // //WDTimer.Enabled = true;
} //}
#endregion //#endregion
GetWD(); //GetWD();
if (stopRecord > 0) if (stopRecord > 0)
{ {
System.Timers.Timer timer = new System.Timers.Timer(); System.Timers.Timer timer = new System.Timers.Timer();

View File

@ -15,7 +15,8 @@
</i:Interaction.Behaviors> </i:Interaction.Behaviors>
<Grid Width="400"> <Grid Width="400">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/> <ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -41,6 +42,19 @@
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </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" /> <!--<TextBlock Text="冰箱温度:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="14" FontWeight="Bold" />
<TextBox Grid.Row="1" <TextBox Grid.Row="1"
Grid.Column="1" Grid.Column="1"
@ -61,6 +75,14 @@
x:Name="MaterialDesignFilledTextBoxEnabledComboBox" x:Name="MaterialDesignFilledTextBoxEnabledComboBox"
Style="{StaticResource MaterialDesignActionToggleButton}" Style="{StaticResource MaterialDesignActionToggleButton}"
IsChecked="{Binding FridgeState}" 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="冰箱状态" ToolTip="冰箱状态"
Content="打开" Content="打开"
materialDesign:ToggleButtonAssist.OnContent="关闭" /> materialDesign:ToggleButtonAssist.OnContent="关闭" />
@ -69,6 +91,13 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Style="{StaticResource MaterialDesignActionToggleButton}" Style="{StaticResource MaterialDesignActionToggleButton}"
IsChecked="{Binding AlarmState}" 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="报警状态" ToolTip="报警状态"
Content="打开" Content="打开"
materialDesign:ToggleButtonAssist.OnContent="关闭" /> materialDesign:ToggleButtonAssist.OnContent="关闭" />

View File

@ -118,7 +118,8 @@
<Grid Grid.Column="2"> <Grid Grid.Column="2">
<StackPanel Margin="6" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Margin="6" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="储物箱" Command="{Binding OpenRecoverCommand}" Visibility="{Binding Is16Drawer, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MaterialDesignFlatSecondaryLightButton}" /> <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> </StackPanel>
</Grid> </Grid>