add:增加文档和上位机
This commit is contained in:
118
上位机/YKC/Pages/ChargerPage.xaml.cs
Normal file
118
上位机/YKC/Pages/ChargerPage.xaml.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace YKC
|
||||
{
|
||||
public partial class ChargerPage : Page
|
||||
{
|
||||
public ChargerPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void SetPileId_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string idx = txtSetPileIdx.Text.Trim();
|
||||
string id = txtSetPileId.Text.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(id) || id.Length != 14)
|
||||
{
|
||||
ShowResult(txtSetResult, "序列号需14位HEX", false);
|
||||
return;
|
||||
}
|
||||
|
||||
ShowResult(txtSetResult, "发送中...", true);
|
||||
|
||||
await System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var result = UdpClientHolder.Instance.SendSync(new JObject
|
||||
{
|
||||
["cmd"] = Config.Cmd["SET_PILE_ID"],
|
||||
["pile_index"] = int.Parse(idx),
|
||||
["pile_id"] = id
|
||||
});
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (result.Value<bool>("success"))
|
||||
ShowResult(txtSetResult, "写入成功", true);
|
||||
else
|
||||
ShowResult(txtSetResult, result.Value<string>("error") ?? "失败", false);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private async void GetPileInfo_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string idx = txtInfoPileIdx.Text.Trim();
|
||||
panelInfo.Visibility = Visibility.Visible;
|
||||
txtInfoResult.Text = "查询中...";
|
||||
txtInfoResult.Foreground = new System.Windows.Media.SolidColorBrush(
|
||||
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#64748B"));
|
||||
|
||||
await System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var result = UdpClientHolder.Instance.SendSync(new JObject
|
||||
{
|
||||
["cmd"] = Config.Cmd["GET_PILE_INFO"],
|
||||
["pile_index"] = int.Parse(idx)
|
||||
});
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (result.Value<bool>("success") && result["serial"] != null)
|
||||
{
|
||||
txtInfoSerial.Text = result.Value<string>("serial") ?? "--";
|
||||
txtInfoType.Text = result.Value<string>("type") ?? "--";
|
||||
txtInfoGuns.Text = result.Value<string>("gun_num") ?? "--";
|
||||
txtInfoProto.Text = result.Value<string>("protocol_ver") ?? "--";
|
||||
txtInfoSw.Text = result.Value<string>("software_ver") ?? "--";
|
||||
txtInfoSim.Text = result.Value<string>("sim") ?? "--";
|
||||
txtInfoResult.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
txtInfoSerial.Text = "--"; txtInfoType.Text = "--";
|
||||
txtInfoGuns.Text = "--"; txtInfoProto.Text = "--";
|
||||
txtInfoSw.Text = "--"; txtInfoSim.Text = "--";
|
||||
ShowResult(txtInfoResult, result.Value<string>("error") ?? "查询失败", false);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private async void Reboot_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialogResult = MessageBox.Show("确认重启设备?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
if (dialogResult != MessageBoxResult.Yes) return;
|
||||
|
||||
ShowResult(txtRebootResult, "发送中...", true);
|
||||
|
||||
await System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var result = UdpClientHolder.Instance.SendSync(new JObject
|
||||
{
|
||||
["cmd"] = Config.Cmd["REBOOT"]
|
||||
});
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (result.Value<bool>("success"))
|
||||
ShowResult(txtRebootResult, "重启指令已发送", true);
|
||||
else
|
||||
ShowResult(txtRebootResult, result.Value<string>("error") ?? "失败", false);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowResult(TextBlock el, string msg, bool ok)
|
||||
{
|
||||
el.Text = msg;
|
||||
el.Foreground = new System.Windows.Media.SolidColorBrush(
|
||||
(System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(
|
||||
ok ? "#10B981" : "#EF4444"));
|
||||
var timer = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromSeconds(4) };
|
||||
timer.Tick += (s, _) => { el.Text = ""; timer.Stop(); };
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user