Przeglądaj źródła

添加按钮及写入功能

reconfiguration
ZhaoGang 2 miesięcy temu
rodzic
commit
e206285d16
3 zmienionych plików z 611 dodań i 522 usunięć
  1. +13
    -5
      BPASmartClient.Academy/50L/PlcControl.cs
  2. +537
    -517
      BPASmartClient.Academy/View/ReactionKettle50LView.xaml
  3. +61
    -0
      BPASmartClient.Academy/View/ReactionKettle50LView.xaml.cs

+ 13
- 5
BPASmartClient.Academy/50L/PlcControl.cs Wyświetl plik

@@ -15,7 +15,7 @@ namespace BPASmartClient.Academy._50L
private volatile static PlcControl _Instance;
public static PlcControl GetInstance => _Instance ?? (_Instance = new PlcControl());
private PlcControl() { }
public bool? IsConnect => comm.IsReconnect;
public bool IsConnect => comm.IsConnected();
public DeviceStatus DeviceStatus { get; set; } = new DeviceStatus();
private ICommSiemens comm = CommHelper.Siemens;

@@ -145,19 +145,27 @@ namespace BPASmartClient.Academy._50L

}

public void Write(BoolAddEnum add, bool value)
public OperateResult Write(BoolAddEnum add, bool value)
{
if (boolAdds.ContainsKey(add))
{
comm.Write(boolAdds[add], value);
return comm.Write(boolAdds[add], value);
}
else
{
return OperateResult.Failed($"未查找到该地址{add.ToString()}");
}
}

public void Write(FloatAddEnum add, float value)
public OperateResult Write(FloatAddEnum add, float value)
{
if (floatAdds.ContainsKey(add))
{
comm.Write(floatAdds[add], value);
return comm.Write(floatAdds[add], value);
}
else
{
return OperateResult.Failed($"未查找到该地址{add.ToString()}");
}
}



+ 537
- 517
BPASmartClient.Academy/View/ReactionKettle50LView.xaml
Plik diff jest za duży
Wyświetl plik


+ 61
- 0
BPASmartClient.Academy/View/ReactionKettle50LView.xaml.cs Wyświetl plik

@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
@@ -32,5 +33,65 @@ namespace BPASmartClient.Academy.View
private void ReactionKettle50LView_Loaded(object sender, RoutedEventArgs e)
{
}

private void PipeLineTR_Loaded(object sender, RoutedEventArgs e)
{

}

private void open_Click(object sender, RoutedEventArgs e)
{
if (sender is ButtonBase button && !string.IsNullOrWhiteSpace(button.Tag.ToString().Trim()))
{
if (PlcControl.GetInstance.IsConnect)
{
var tag = button.Tag.ToString().Trim();
BoolAddEnum addr=(BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag);
var result= PlcControl.GetInstance.Write(addr, true);
if (result !=null && result.IsSuccess)
{
Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:True");
}
else
{
Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:True\n{result.Message}");
}
}
else
{
Notify(EnumPromptType.Error, "失败", "设备未连接");
}
}
}

private void close_Click(object sender, RoutedEventArgs e)
{
if (sender is ButtonBase button && !string.IsNullOrWhiteSpace(button.Tag.ToString().Trim()))
{
if (PlcControl.GetInstance.IsConnect)
{
var tag = button.Tag.ToString().Trim();
BoolAddEnum addr = (BoolAddEnum)Enum.Parse(typeof(BoolAddEnum), tag);
var result = PlcControl.GetInstance.Write(addr, false);
if (result != null && result.IsSuccess)
{
Notify(EnumPromptType.Success, $"写入成功", $"成功:写入{tag}:False");
}
else
{
Notify(EnumPromptType.Error, $"写入失败", $"失败:写入{tag}:False\n{result.Message}");
}
}
else
{
Notify(EnumPromptType.Error, "失败", "设备未连接");
}
}
}

private void Notify(EnumPromptType promptType,string title,string msg)
{
NoticeDemoViewModel.OpenMsg(promptType, App.Current.MainWindow, title, msg);
}
}
}

Ładowanie…
Anuluj
Zapisz