|
@@ -2,6 +2,7 @@
|
|
|
using System.Net.NetworkInformation;
|
|
|
using System.Reflection;
|
|
|
using System.Runtime.InteropServices;
|
|
|
+using System.Threading.Channels;
|
|
|
|
|
|
namespace WCS.Core
|
|
|
{
|
|
@@ -25,17 +26,17 @@ namespace WCS.Core
|
|
|
return id.ToString();
|
|
|
}
|
|
|
|
|
|
- public DataBlock(DBInfo ent,World world) : base(ent)
|
|
|
+ public DataBlock(DBInfo ent, World world) : base(ent)
|
|
|
{
|
|
|
- this.World= world;
|
|
|
+ this.World = world;
|
|
|
DBList.Add(this);
|
|
|
id = DBList.Count;
|
|
|
}
|
|
|
|
|
|
- DateTime faildTime = DateTime.MinValue;
|
|
|
+ private DateTime faildTime = DateTime.MinValue;
|
|
|
|
|
|
public void RefreshData()
|
|
|
- {
|
|
|
+ {
|
|
|
try
|
|
|
{
|
|
|
var plc = Entity.PLCInfo.Ex(World);
|
|
@@ -45,28 +46,43 @@ namespace WCS.Core
|
|
|
{
|
|
|
throw new Exception($"{Entity.PLCInfo.IP}无法访问");
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
Start = (ushort)ProxyList.Min(v => v.Info.Position);
|
|
|
var last = ProxyList.OrderBy(v => v.Info.Position).Last();
|
|
|
Length = (ushort)(last.Info.Position + last.BytesCount);
|
|
|
var data = new byte[0];
|
|
|
+ //Console.ForegroundColor = ConsoleColor.Red;
|
|
|
+ //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--开始");
|
|
|
+ //Console.ResetColor();
|
|
|
lock (plc)
|
|
|
{
|
|
|
+ //Console.ForegroundColor = ConsoleColor.Red;
|
|
|
+ //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--读取中");
|
|
|
+ //Console.ResetColor();
|
|
|
data = plc.Accessor.ReadBytes(Entity.No, Start, (ushort)(Length - Start));
|
|
|
+ //Console.ForegroundColor = ConsoleColor.Red;
|
|
|
+ //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--读取结束");
|
|
|
+ //Console.ResetColor();
|
|
|
}
|
|
|
+ //Console.ForegroundColor = ConsoleColor.Red;
|
|
|
+ //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--处理中");
|
|
|
+ //Console.ResetColor();
|
|
|
if (!Data.SequenceEqual(data))
|
|
|
{
|
|
|
Data = data;
|
|
|
DbChanged?.Invoke(Data);
|
|
|
}
|
|
|
Failed = false;
|
|
|
+ //Console.ForegroundColor = ConsoleColor.Red;
|
|
|
+ //Console.WriteLine($"{plc.Entity.IP}--{Entity.No}--结束");
|
|
|
+ //Console.ResetColor();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- Failed = true;
|
|
|
+ Failed = true;
|
|
|
throw;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public PlcItem<T> Regist<T>(ProtocolProxyBase proxy, string objid, string name, int start, byte arrLen = 1, byte strLen = 0)
|
|
|
{
|
|
@@ -117,7 +133,7 @@ namespace WCS.Core
|
|
|
{
|
|
|
throw new Exception("只支持一维数组");
|
|
|
}
|
|
|
- var arr = Array.CreateInstance(t, arrLength);
|
|
|
+ var arr = Array.CreateInstance(t, arrLength);
|
|
|
|
|
|
for (int i = 0; i < arr.Length; i++)
|
|
|
{
|