页面调试
This commit is contained in:
@@ -37,7 +37,7 @@ namespace 头罩视野.Views
|
||||
public PageTest()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("页面加载了!111111111");
|
||||
_timer = InitDispatcherTimer();
|
||||
// 2. 初始化定时器:500毫秒 执行一次
|
||||
|
||||
@@ -80,7 +80,8 @@ namespace 头罩视野.Views
|
||||
{
|
||||
((Button)sender).CaptureMouse();
|
||||
_isPressing = true;
|
||||
await Task.Run(() => {
|
||||
await Task.Run(() =>
|
||||
{
|
||||
//重新占位写入
|
||||
_modbusMaster.WriteSingleCoilAsync(1, 10, true);
|
||||
Task.Delay(100);
|
||||
@@ -102,7 +103,8 @@ namespace 头罩视野.Views
|
||||
((Button)sender).CaptureMouse();
|
||||
_isPressing1 = true;
|
||||
|
||||
await Task.Run(() => {
|
||||
await Task.Run(() =>
|
||||
{
|
||||
//重新占位写入
|
||||
_modbusMaster.WriteSingleCoilAsync(1, 11, true);
|
||||
System.Diagnostics.Debug.WriteLine("正传start");
|
||||
@@ -123,7 +125,7 @@ namespace 头罩视野.Views
|
||||
private void Button_Click_Test(object sender, RoutedEventArgs e)
|
||||
|
||||
{
|
||||
|
||||
|
||||
testTimer.Start();
|
||||
ma.BtnClickFunction(Function.ButtonType.复归型, 101);
|
||||
}
|
||||
@@ -164,6 +166,8 @@ namespace 头罩视野.Views
|
||||
private void Page_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
testTimer?.Stop();
|
||||
_timer?.Stop();
|
||||
|
||||
}
|
||||
//停止btn
|
||||
private void Button_Click_Stop(object sender, RoutedEventArgs e)
|
||||
@@ -205,7 +209,7 @@ namespace 头罩视野.Views
|
||||
{
|
||||
var timer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(100)
|
||||
Interval = TimeSpan.FromMilliseconds(500)
|
||||
};
|
||||
timer.Tick += async (s, e) =>
|
||||
{
|
||||
@@ -228,16 +232,15 @@ namespace 头罩视野.Views
|
||||
// 创建任务列表
|
||||
var tasks = new List<Task>
|
||||
{
|
||||
ReadAndUpdateFloatAsync(200, 2, fbspeed, "F2", "°"),
|
||||
ReadAndUpdateFloatAsync(202, 2, dqangle, "F2", "°"),
|
||||
ReadAndUpdateFloatAsync(310, 2, zdangle, "F2", "°/S"),
|
||||
|
||||
ReadAndUpdateFloatAsync(204, 2, zmsyarea, "F2", "cm²"),
|
||||
ReadAndUpdateFloatAsync(208, 2, smsyarea, "F2", "cm²"),
|
||||
//ReadAndUpdateFloatAsync(200, 2, fbspeed, "F2", "°"),
|
||||
//ReadAndUpdateFloatAsync(202, 2, dqangle, "F2", "°"),
|
||||
//ReadAndUpdateFloatAsync(204, 2, zmsyarea, "F2", "cm²"),
|
||||
//ReadAndUpdateFloatAsync(206 ,2, xfsyarea, "F2", " "),
|
||||
//ReadAndUpdateFloatAsync(208, 2, smsyarea, "F2", "cm²"),
|
||||
//ReadAndUpdateFloatAsync(210 ,2, ymsyarea, "F2", " "),
|
||||
ReadAndUpdateFloatRangeAsync(200, 12, "F2", "°"),
|
||||
ReadAndUpdateFloatAsync(424 ,2, kbsyarea, "F2", "cm²"),
|
||||
|
||||
ReadAndUpdateFloatAsync(210 ,2, ymsyarea, "F2", " "),
|
||||
ReadAndUpdateFloatAsync(206 ,2, xfsyarea, "F2", " "),
|
||||
ReadAndUpdateFloatAsync(310, 2, zdangle, "F2", "°/S"),
|
||||
ReadAndUpdateFloatAsync(430 ,2, sybhl, "F2", " "),
|
||||
};
|
||||
|
||||
@@ -274,6 +277,53 @@ namespace 头罩视野.Views
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task ReadAndUpdateFloatRangeAsync(int address, int length, string format, string unit)
|
||||
{
|
||||
try
|
||||
{
|
||||
ushort[] registers = await Task.Run(async () =>
|
||||
await _modbusMaster?.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
);
|
||||
|
||||
if (registers != null && registers.Length >= 2)
|
||||
{
|
||||
float value = c.UshortToFloat(registers[1], registers[0]);
|
||||
float value2 = c.UshortToFloat(registers[3], registers[2]);
|
||||
float value3 = c.UshortToFloat(registers[5], registers[4]);
|
||||
float value4 = c.UshortToFloat(registers[7], registers[6]);
|
||||
float value5 = c.UshortToFloat(registers[9], registers[8]);
|
||||
float value6 = c.UshortToFloat(registers[11], registers[10]);
|
||||
|
||||
|
||||
|
||||
//ReadAndUpdateFloatAsync(200, 2, fbspeed, "F2", "°"),
|
||||
//ReadAndUpdateFloatAsync(202, 2, dqangle, "F2", "°"),
|
||||
//ReadAndUpdateFloatAsync(204, 2, zmsyarea, "F2", "cm²"),
|
||||
//ReadAndUpdateFloatAsync(206 ,2, xfsyarea, "F2", " "),
|
||||
//ReadAndUpdateFloatAsync(208, 2, smsyarea, "F2", "cm²"),
|
||||
//ReadAndUpdateFloatAsync(210 ,2, ymsyarea, "F2", " "),
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
|
||||
{
|
||||
fbspeed.Text = value.ToString(format) + unit;
|
||||
dqangle.Text = value2.ToString(format) + unit;
|
||||
zmsyarea.Text = value3.ToString(format) + unit;
|
||||
xfsyarea.Text = value4.ToString(format) + unit;
|
||||
smsyarea.Text = value5.ToString(format) + unit;
|
||||
ymsyarea.Text = value6.ToString(format) + unit;
|
||||
//control.Text = value.ToString(format) + unit);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"读取地址{address}失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReadAndUpdateFloatAsync(int address, int length, System.Windows.Controls.TextBlock control, string format, string unit)
|
||||
{
|
||||
try
|
||||
@@ -349,15 +399,21 @@ namespace 头罩视野.Views
|
||||
//错误信息提示
|
||||
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
private void GoHome(object s, RoutedEventArgs e) => NavigationService.Content = null;
|
||||
private void GoTest(object s, RoutedEventArgs e) => NavigationService.Content = new Views.PageTest();
|
||||
private void GoTest(object s, RoutedEventArgs e)
|
||||
{
|
||||
_timer.Stop();
|
||||
NavigationService.Content = new Views.PageTest();
|
||||
}
|
||||
private void GoRecord(object s, RoutedEventArgs e) => NavigationService.Content = new Views.RecordDate();
|
||||
private void GoView(object s, RoutedEventArgs e) => NavigationService.Content = new Views.RecordPage();
|
||||
|
||||
|
||||
private void Page_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("页面加载了!112222222");
|
||||
_timer.Start();
|
||||
ma = new Function(_modbusMaster);
|
||||
c = new DataChange();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user