Browse Source

广告页添加,转台控制流程修改

master
pry 2 years ago
parent
commit
e2662b613a
13 changed files with 315 additions and 101 deletions
  1. +61
    -32
      HBLConsole.MORKD/Control_MORKD.cs
  2. +9
    -9
      HBLConsole.MORKD/GVL_MORKD.cs
  3. +19
    -0
      HBLConsole/AdvertiseWindow/MORKD_Window_Left.xaml
  4. +27
    -0
      HBLConsole/AdvertiseWindow/MORKD_Window_Left.xaml.cs
  5. +19
    -0
      HBLConsole/AdvertiseWindow/MORKD_Window_Right.xaml
  6. +27
    -0
      HBLConsole/AdvertiseWindow/MORKD_Window_Right.xaml.cs
  7. +3
    -3
      HBLConsole/App.config
  8. +42
    -1
      HBLConsole/App.xaml.cs
  9. +10
    -0
      HBLConsole/HBLConsole.csproj
  10. +2
    -2
      HBLConsole/SqlHelper.cs
  11. +1
    -1
      HBLConsole/View/MainView.xaml
  12. +13
    -7
      HBLConsole/View/VariableMonitorView.xaml
  13. +82
    -46
      HBLConsole/ViewModel/VariableMonitorViewModel.cs

+ 61
- 32
HBLConsole.MORKD/Control_MORKD.cs View File

@@ -111,8 +111,6 @@ namespace HBLConsole.MORKD
}), "MainTask");
}



public void ReadData()
{
ThreadOperate.GetInstance.StartLong(new Action(() =>
@@ -142,11 +140,12 @@ namespace HBLConsole.MORKD
mORKD.TakeSoupRobotIdle = bools[24];
mORKD.TakeSoupComplete = bools[27];
mORKD.PutNoodleTakeMealComplete = bools[28];
Initing = bools[28];
Initing = bools[29];
if (Initing) MessageLog.GetInstance.Show("初始化中.....");
}));


ModbusTcpHelper.GetInstance.Readbool(1200, 11, new Action<bool[]>((bools) =>
ModbusTcpHelper.GetInstance.Readbool(1280, 11, new Action<bool[]>((bools) =>
{
mORKD.TurntableLowerLimit = bools[0];
mORKD.TurntableUpLimit = bools[1];
@@ -163,7 +162,7 @@ namespace HBLConsole.MORKD
mORKD.TemperatureReached = bools[10];
}));

var ResLoc = ModbusTcpHelper.GetInstance.Read(286, ReadType.HoldingRegisters);
var ResLoc = ModbusTcpHelper.GetInstance.Read(720, ReadType.HoldingRegisters);
if (ResLoc != null)
{
if (ResLoc is ushort loc)
@@ -186,8 +185,12 @@ namespace HBLConsole.MORKD
{
if (item >= 1 && item <= 5)
{
mORKD.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
MessageLog.GetInstance.Show($"添加订单:面条位置【{item}】");
var res = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.FirstOrDefault(p => p.BatchingLoc == item.ToString());
if (res != null)
{
mORKD.RBTakeNoodleTask.Enqueue(new OrderLocInfo() { Loc = item, BatchingId = res.BatchingId, SuborderId = subId });
MessageLog.GetInstance.Show($"添加订单:面条位置【{item}】");
}
}
if (item >= 6 && item <= 10)
{
@@ -196,8 +199,8 @@ namespace HBLConsole.MORKD
}
if (item >= 11 && item <= 12)
{
mORKD.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = item, SuborderId = subId });
MessageLog.GetInstance.Show($"添加订单:碗位置【{item}】");
mORKD.TakeBowlTask.Enqueue(new OrderLocInfo() { Loc = (ushort)(item - 10), SuborderId = subId });
MessageLog.GetInstance.Show($"添加订单:碗位置【{item - 10}】");
}
}
}
@@ -252,7 +255,7 @@ namespace HBLConsole.MORKD
mORKD.AxisAllowInvertedNoodleID[mORKD.AxisIdleIndex] = orderLocInfo.SuborderId;
mORKD.DropBowlStart((ushort)mORKD.AxisIdleIndex, orderLocInfo.Loc);
mORKD.AxisIdleLock[mORKD.AxisIdleLockIndex] = true;
MessageLog.GetInstance.Show($"执行取碗控制,位置:[{orderLocInfo.Loc}]");
MessageLog.GetInstance.Show($"执行取碗控制,位置:[{orderLocInfo.Loc}],轴位置:[{mORKD.AxisIdleIndex}]");
}
}
}
@@ -264,41 +267,67 @@ namespace HBLConsole.MORKD
/// </summary>
private void TurntableControl()
{
if (mORKD.InitComplete && !mORKD.TurntableInterlock && !mORKD.AllowTakeNoodle && mORKD.RBTakeNoodleTask.Count > 0)
if (mORKD.TurntableInPlace && mORKD.InitComplete && !mORKD.AllowTakeNoodle && mORKD.RBTakeNoodleTask.Count > 0)
{
var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKD.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
if (result != null)
if (mORKD.TurntableLowerLimit)
{
if (mORKD.TurntableFeedbackloc == mORKD.RBTakeNoodleTask.ElementAt(0).Loc)
{
mORKD.TurntableLocLists.Clear();
mORKD.AllowTakeNoodle = true;
MessageLog.GetInstance.Show("转台位置OK,执行机器人取面");
}
else
{
if (!mORKD.TurntableInterlock)
{
mORKD.TurntableStart(mORKD.RBTakeNoodleTask.ElementAt(0).Loc);
MessageLog.GetInstance.Show($"有物料检测,反馈位置不同的转台启动控制,转台位置:[{mORKD.RBTakeNoodleTask.ElementAt(0).Loc}]");
}
}
}
else
{
foreach (var item in result)
if (!mORKD.TurntableInterlock)
{
if (ushort.TryParse(item.BatchingLoc, out ushort loc))
var result = Json<BatchingInfoPar>.Data.orderMaterialDelivery.BatchingInfo.Where(p => p.BatchingId == mORKD.RBTakeNoodleTask.ElementAt(0).BatchingId).ToList();
result?.ForEach(item =>
{
if (mORKD.TurntableFeedbackloc != loc && !mORKD.TurntableLocLists.Contains(loc))
if (ushort.TryParse(item.BatchingLoc, out ushort loc))
{
mORKD.TurntableStart(loc);
return;
if (mORKD.TurntableFeedbackloc != loc && !mORKD.TurntableLocLists.Contains(loc))
{
mORKD.TurntableStart(loc);
MessageLog.GetInstance.Show($"没有物料检测的启动转台控制,转台位置:[{loc}]");
return;
}
else if (mORKD.TurntableFeedbackloc == loc) mORKD.TurntableLocLists.Add(loc);
}
}
});
}

}
}

//转台到位检测
if (RTrig.GetInstance("TurntableInPlace").Start(mORKD.TurntableInPlace))
{
if (mORKD.TurntableInterlock)
{
if (mORKD.TurntableLowerLimit)
{
mORKD.TurntableLocLists.Clear();
mORKD.AllowTakeNoodle = true;
}
else
{
mORKD.TurntableInterlock = false;
mORKD.AllowTakeNoodle = false;
}
}
mORKD.TurntableInterlock = false;
//if (mORKD.TurntableInterlock)
//{
// if (mORKD.TurntableLowerLimit)
// {
// mORKD.TurntableLocLists.Clear();
// mORKD.AllowTakeNoodle = true;
// MessageLog.GetInstance.Show("转台位置检测OK");
// }
// else
// {
// mORKD.TurntableInterlock = false;
// mORKD.AllowTakeNoodle = false;
// MessageLog.GetInstance.Show("转台位置检测失败,重新启动转台");
// }
//}
}
}



+ 9
- 9
HBLConsole.MORKD/GVL_MORKD.cs View File

@@ -253,11 +253,11 @@ namespace HBLConsole.MORKD
public bool Initing { get; set; }

/// <summary>
/// 转台位置
/// PLC -> VW372
/// ModbusTcp -> 286
/// 转台反馈位置
/// PLC -> VW1240
/// ModbusTcp -> 720
/// </summary>
[VariableMonitor("设备初始化中", "VW372", "286")]
[VariableMonitor("转台反馈位置", "VW1240", "720")]
public ushort TurntableFeedbackloc { get; set; }
#endregion

@@ -267,7 +267,7 @@ namespace HBLConsole.MORKD
/// PLC --> M120.0
/// ModbusTcp --> 1200
/// </summary>
[VariableMonitor("转台下限位", "M120.0", "1200")]
[VariableMonitor("转台下限位", "M120.0", "1280")]
public bool TurntableLowerLimit { get; set; }

/// <summary>
@@ -275,7 +275,7 @@ namespace HBLConsole.MORKD
/// PLC --> M120.1
/// ModbusTcp --> 1201
/// </summary>
[VariableMonitor("转台上限位", "M120.1", "1201")]
[VariableMonitor("转台上限位", "M120.1", "1281")]
public bool TurntableUpLimit { get; set; }

/// <summary>
@@ -283,7 +283,7 @@ namespace HBLConsole.MORKD
/// PLC --> M120.2 -- M120.6
/// ModbusTcp --> 1202 -- 1206
/// </summary>
[VariableMonitor("浇头缺料", "M120.2", "1202")]
[VariableMonitor("浇头缺料", "M120.2", "1282")]
public bool[] SoupMaterialShortage { get; set; } = new bool[5] { false, false, false, false, false };

/// <summary>
@@ -291,7 +291,7 @@ namespace HBLConsole.MORKD
/// PLC --> M120.7 -- M121.1
/// ModbusTcp --> 1207 -- 1209
/// </summary>
[VariableMonitor("出餐口检测", "M120.7", "1207")]
[VariableMonitor("出餐口检测", "M120.7", "1287")]
public bool[] OutMealDetect { get; set; } = new bool[3] { false, false, false };

/// <summary>
@@ -299,7 +299,7 @@ namespace HBLConsole.MORKD
/// PLC --> M121.2
/// ModbusTcp --> 1210
/// </summary>
[VariableMonitor("温度到达", "M121.2", "1210")]
[VariableMonitor("温度到达", "M121.2", "1290")]
public bool TemperatureReached { get; set; }
#endregion



+ 19
- 0
HBLConsole/AdvertiseWindow/MORKD_Window_Left.xaml View File

@@ -0,0 +1,19 @@
<Window
x:Class="HBLConsole.AdvertiseWindow.MORKD_Window_Left"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HBLConsole.AdvertiseWindow"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wv="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
Title="MORKD_Window_Left"
Width="800"
Height="450"
Background="{x:Null}"
Topmost="True"
WindowStyle="None"
mc:Ignorable="d">
<Grid>
<wv:WebView2 Source="http://www.baidu.com" />
</Grid>
</Window>

+ 27
- 0
HBLConsole/AdvertiseWindow/MORKD_Window_Left.xaml.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HBLConsole.AdvertiseWindow
{
/// <summary>
/// MORKD_Window_Left.xaml 的交互逻辑
/// </summary>
public partial class MORKD_Window_Left : Window
{
public MORKD_Window_Left()
{
InitializeComponent();
}
}
}

+ 19
- 0
HBLConsole/AdvertiseWindow/MORKD_Window_Right.xaml View File

@@ -0,0 +1,19 @@
<Window
x:Class="HBLConsole.AdvertiseWindow.MORKD_Window_Right"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HBLConsole.AdvertiseWindow"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:v="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
Title="MORKD_Window_Right"
Width="800"
Height="450"
Background="{x:Null}"
Topmost="True"
WindowStyle="None"
mc:Ignorable="d">
<Grid>
<v:WebView2 Source="http://www.baidu.com" />
</Grid>
</Window>

+ 27
- 0
HBLConsole/AdvertiseWindow/MORKD_Window_Right.xaml.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HBLConsole.AdvertiseWindow
{
/// <summary>
/// MORKD_Window_Right.xaml 的交互逻辑
/// </summary>
public partial class MORKD_Window_Right : Window
{
public MORKD_Window_Right()
{
InitializeComponent();
}
}
}

+ 3
- 3
HBLConsole/App.config View File

@@ -11,7 +11,7 @@

<!--客户端ID-->
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13-->
<add key="ClientId" value="4"/>
<add key="ClientId" value="5"/>
<!--IOT大屏上报-->
<add key="ProductKey" value="grgpECHSL7q"/>
<add key="DeviceName" value="test"/>
@@ -24,8 +24,8 @@
<add key="COM_IceCream" value="COM5"/>
<add key="BAUD_IceCream" value="9600"/>
<add key="IceCream_CXB_Threshold" value="90"/>
<add key="COM_ICChip" value="COM10"/>
<add key="BAUD_IChip" value="9600"/>
<add key="COM_ICChip" value="COM10"/>
<add key="BAUD_IChip" value="9600"/>

</appSettings>
</configuration>

+ 42
- 1
HBLConsole/App.xaml.cs View File

@@ -14,16 +14,24 @@ using HBLConsole.MainConsole;
using HBLConsole.GVL;
using BPA.Message.Enum;
using HBLConsole.Business;
using HBLConsole.AdvertiseWindow;
using System.Windows.Forms;
using System.Drawing;

//问题.net core项目中引用 using System.Windows.Forms; 失败
//解决方案:在 csproj 文件的 PropertyGroup里面添加 <UseWindowsForms>true</UseWindowsForms>

namespace HBLConsole
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : System.Windows.Application
{
MainView mainView;
MORKD_Window_Left left;
ListDialogView listDialogView;
MORKD_Window_Right right;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
@@ -34,10 +42,43 @@ namespace HBLConsole
ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData");
mainView = new MainView();
mainView.Show();
SplitScreenDisplay();
NoCompleteOrderInit();
MainConsole.Main.GetInstance.BusinessInit();
}

/// <summary>
/// 分屏显示
/// </summary>
private void SplitScreenDisplay()
{
if (Screen.AllScreens.Length == 3)
{
left = new MORKD_Window_Left();
right = new MORKD_Window_Right();

Screen[] screen = Screen.AllScreens;
Rectangle[] rectangle = new Rectangle[screen.Length];
Window[] windows = new Window[screen.Length];
windows[0] = mainView;
windows[1] = left;
windows[2] = right;
for (int i = 0; i < screen.Length; i++)
{
rectangle[i] = screen[i].WorkingArea;
windows[i].Height = rectangle[i].Height;
windows[i].Width = rectangle[i].Width;
windows[i].Top = rectangle[i].Top;
windows[i].Left = rectangle[i].Left;
}

left.Show();
right.Show();
windows[1].Owner = windows[0];
windows[2].Owner = windows[0];
}
}

/// <summary>
/// 未完成订单初始化
/// </summary>


+ 10
- 0
HBLConsole/HBLConsole.csproj View File

@@ -5,9 +5,19 @@
<TargetFramework>net5.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\Images\hbl.ico</ApplicationIcon>
</PropertyGroup>

<!--<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>-->



<ItemGroup>
<None Remove="Resources\Fonts\iconfont.ttf" />
<None Remove="Resources\Images\acida.ico" />


+ 2
- 2
HBLConsole/SqlHelper.cs View File

@@ -19,8 +19,8 @@ namespace HBLConsole
{
get
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB"));
return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\{GVL.GeneralConfig.DeviceType.ToString()}_{typeof(VariableInfo).Name}.db";
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FilePath));
return $"{AppDomain.CurrentDomain.BaseDirectory}{FilePath}\\{typeof(VariableInfo).Name}.db";
}
}



+ 1
- 1
HBLConsole/View/MainView.xaml View File

@@ -13,7 +13,7 @@
Height="850"
AllowsTransparency="True"
Background="{x:Null}"
Topmost="True"
Topmost="False"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
mc:Ignorable="d">


+ 13
- 7
HBLConsole/View/VariableMonitorView.xaml View File

@@ -55,12 +55,13 @@

<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<!--<RowDefinition Height="30" />-->
<RowDefinition Height="30" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<!--<Button
<!--<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
-->
<!--<Button
Margin="20,0,20,0"
Command="{Binding GenerateData}"
Content="添加数据" />
@@ -68,10 +69,11 @@
Margin="20,0,20,0"
Command="{Binding SaveData}"
Content="保存数据" />-->
</StackPanel>
<!--
</StackPanel>-->

<!--#region 表格标题栏设置-->
<Grid Grid.Row="1" Background="#dd2AB2E7">
<Grid Background="#dd2AB2E7">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*" />
<ColumnDefinition />
@@ -152,7 +154,7 @@

<!--#region 表格数据显示-->
<ScrollViewer
Grid.Row="2"
Grid.Row="1"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding VariableMonitors}">
@@ -166,7 +168,6 @@
<ColumnDefinition />
<ColumnDefinition Width="0.7*" />
<ColumnDefinition Width="0.7*" />
<!--<ColumnDefinition Width="0.5*" />-->
</Grid.ColumnDefinitions>

<TextBlock
@@ -180,6 +181,7 @@

<Grid Grid.Column="1">
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
FontSize="14"
@@ -191,6 +193,7 @@

<TextBlock
Grid.Column="2"
Margin="5,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
FontSize="14"
@@ -199,6 +202,7 @@

<Grid Grid.Column="3">
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
FontSize="14"
@@ -209,6 +213,7 @@

<Grid Grid.Column="4">
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
FontSize="14"
@@ -219,6 +224,7 @@

<TextBlock
Grid.Column="5"
Margin="5,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
FontSize="14"


+ 82
- 46
HBLConsole/ViewModel/VariableMonitorViewModel.cs View File

@@ -8,6 +8,8 @@ using HBLConsole.Model;
using HBLConsole.Factory;
using HBLConsole.Attributes;
using System.Reflection;
using HBLConsole.Service;
using System.Threading;

namespace HBLConsole.ViewModel
{
@@ -35,45 +37,69 @@ namespace HBLConsole.ViewModel
var modadd = item.GetCustomAttribute<VariableMonitorAttribute>()?.ModbusTcpAddress;
var notes = item.GetCustomAttribute<VariableMonitorAttribute>()?.Notes;

if (item.PropertyType?.BaseType?.Name == "Array" && plcadd?.Length > 0)
if (item.PropertyType?.BaseType?.Name == "Array")
{
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL, null);
if (arrayRes != null && arrayRes is Array arr)
if (plcadd?.Length > 0)
{
for (int i = 0; i < arr.Length; i++)
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL, null);
if (arrayRes != null && arrayRes is Array arr)
{
var res = VariableMonitors.FirstOrDefault(p => p.VarName == $"{item.Name}_{i + 1}");
if (res == null)
for (int i = 0; i < arr.Length; i++)
{
string[] plc = plcadd?.Substring(1).Split('.');
string TempPlcAddress = string.Empty;
if (plc?.Length == 2)
var res = VariableMonitors.FirstOrDefault(p => p.VarName == $"{item.Name}_{i + 1}");
if (res == null)
{
int add = int.Parse(plc[1]);
int firstAdd = int.Parse(plc[0]);
if (add >= 0 && add < 7)
string[] plc = plcadd?.Substring(1).Split('.');
string TempPlcAddress = string.Empty;
if (plc?.Length == 2)
{
add += i;
int add = int.Parse(plc[1]);
int firstAdd = int.Parse(plc[0]);
if (add >= 0 && add < 7)
{
add += i;
}
else if (add >= 7)
{
add = 0;
firstAdd++;
}
plc[0] = firstAdd.ToString();
plc[1] = add.ToString();
TempPlcAddress = $"M{plc[0]}.{plc[1]}";
}
else if (add >= 7)

VariableMonitors.Add(new VariableMonitor()
{
add = 0;
firstAdd++;
}
plc[0] = firstAdd.ToString();
plc[1] = add.ToString();
TempPlcAddress = $"M{plc[0]}.{plc[1]}";
}
Id = VariableMonitors.Count,
VarName = $"{item.Name}_{i + 1}",
Notes = $"{notes}_{i + 1}",
ModbusTcpAddress = $"{int.Parse(modadd) + i}",
PLCAddress = TempPlcAddress,

VariableMonitors.Add(new VariableMonitor()
});
}
}
}
}
else
{
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL, null);
if (arrayRes != null && arrayRes is Array arr)
{
for (int i = 0; i < arr.Length; i++)
{
var res = VariableMonitors.FirstOrDefault(p => p.VarName == $"{item.Name}_{i + 1}");
if (res == null)
{
Id = VariableMonitors.Count,
VarName = $"{item.Name}_{i + 1}",
Notes = $"{notes}_{i + 1}",
ModbusTcpAddress = $"{int.Parse(modadd) + i}",
PLCAddress = TempPlcAddress,
VariableMonitors.Add(new VariableMonitor()
{
Id = VariableMonitors.Count,
VarName = $"{item.Name}_{i + 1}",
Notes = $"{notes}_{i + 1}",

});
});
}
}
}
}
@@ -102,37 +128,47 @@ namespace HBLConsole.ViewModel
private static void UpdateValue()
{
if (SimpleFactory.GetInstance.GVL == null) return;

foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties())
ThreadOperate.GetInstance.StartLong(new Action(() =>
{
if (item.CustomAttributes.Count() > 0)
foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties())
{
if (item.PropertyType?.BaseType?.Name == "Array")
if (item.CustomAttributes.Count() > 0)
{
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL);
if (arrayRes != null && arrayRes is Array arr)
if (item.PropertyType?.BaseType?.Name == "Array")
{
for (int i = 0; i < arr.Length; i++)
var arrayRes = item.GetValue(SimpleFactory.GetInstance.GVL);
if (arrayRes != null && arrayRes is Array arr)
{
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == $"{item.Name}_{i + 1}");
if (index >= 0 && index < VariableMonitors.Count)
for (int i = 0; i < arr.Length; i++)
{
VariableMonitors.ElementAt(index).CurrentValue = arr.GetValue(i)?.ToString();
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == $"{item.Name}_{i + 1}");
if (index >= 0 && index < VariableMonitors.Count)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
VariableMonitors.ElementAt(index).CurrentValue = arr.GetValue(i)?.ToString();
}));

}
}
}
}
}
else
{
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == item.Name);
if (index >= 0 && index < VariableMonitors.Count)
else
{
VariableMonitors.ElementAt(index).CurrentValue = item.GetValue(SimpleFactory.GetInstance.GVL)?.ToString();
int index = Array.FindIndex(VariableMonitors.ToArray(), p => p.VarName == item.Name);
if (index >= 0 && index < VariableMonitors.Count)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
VariableMonitors.ElementAt(index).CurrentValue = item.GetValue(SimpleFactory.GetInstance.GVL)?.ToString();
}));
}
}
}

}
}
}
Thread.Sleep(1000);
}), "变量监控");
}




Loading…
Cancel
Save