Browse Source

调整主动获取外设状态

样式分支
applelon 2 years ago
parent
commit
822962451a
6 changed files with 97 additions and 5 deletions
  1. +1
    -0
      BPASmartClient.Device/BPASmartClient.Device.csproj
  2. +24
    -1
      BPASmartClient.Device/BaseDevice.cs
  3. +58
    -2
      BPASmartClient.MorkS/Control.cs
  4. +1
    -1
      BPASmartClient.MorkT/Device_MorkT.cs
  5. +7
    -1
      BPASmartClient.Peripheral/BasePeripheral.cs
  6. +6
    -0
      BPASmartClient.Peripheral/IPeripheral.cs

+ 1
- 0
BPASmartClient.Device/BPASmartClient.Device.csproj View File

@@ -9,6 +9,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmartClient.Helper\BPASmartClient.Helper.csproj" />
<ProjectReference Include="..\BPASmartClient.Peripheral\BPASmartClient.Peripheral.csproj" />
</ItemGroup>



+ 24
- 1
BPASmartClient.Device/BaseDevice.cs View File

@@ -1,10 +1,13 @@
using BPA.Message.Enum;
using BPASmartClient.Helper;
using BPASmartClient.Peripheral;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BPASmartClient.Device
@@ -43,6 +46,10 @@ namespace BPASmartClient.Device
/// </summary>
public bool IsHealth { get; protected set; }

//外设状态
protected ConcurrentDictionary<string, object> peripheralStatus = new ConcurrentDictionary<string, object>();
private List<IPeripheral> peripherals;

public void Initliaze()
{
}
@@ -54,10 +61,26 @@ namespace BPASmartClient.Device
p.DeviceId = this.DeviceId;
p.Init();
});
this.peripherals = peripherals;
}

public abstract void StartMain();
public virtual void StartMain()
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
foreach (var peripheral in peripherals)
{
foreach (var key in peripheral.GetAllStatus().Keys)
{
peripheralStatus[key] = peripheral.GetAllStatus()[key];
}
}
Thread.Sleep(100);
}), "ResetProgram");
DoMain();
}

public abstract void DoMain();
public abstract void Stop();
}
}

+ 58
- 2
BPASmartClient.MorkS/Control.cs View File

@@ -32,7 +32,7 @@ namespace BPASmartClient.MorkS
int OrderCount;
bool Initing;

public override void StartMain()
public override void DoMain()
{
ServerInit();
DataParse();
@@ -105,7 +105,62 @@ namespace BPASmartClient.MorkS

private void ReadPLCData()
{
/*替换为内部主动读取
ThreadManage.GetInstance().StartLong(new Action(() =>
{

var bools = (bool[])peripheralStatus["M0.3"];
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotOutMeal = bools[1];
mORKS.MoveTurntable = bools[2];

bools = (bool[])peripheralStatus["M100.0"];
mORKS.InitComplete = bools[0];
mORKS.TakeBowlIdle = bools[1];
mORKS.TemperatureReached = bools[2];
mORKS.AllowFallNoodle = bools[3];
mORKS.RbTakeNoodleComplete = bools[4];
mORKS.RbFallNoodleComplete = bools[5];
mORKS.RbOutMealComplete = bools[6];
mORKS.RobotIdle = bools[7];
mORKS.TakeMealDetect = bools[8];
mORKS.MissingBowl = bools[9];
Initing = bools[10];
mORKS.TurntableLowerLimit = bools[11];
mORKS.MissingBowlSignal2 = bools[12];
mORKS.TurntableUpLimit = bools[13];
mORKS.FeedComplete = bools[14];
mORKS.TurntableMoveInPlace = bools[15];

bools = (bool[])peripheralStatus["M235.0"];
mORKS.Error = bools[0];

bools = (bool[])peripheralStatus["M102.0"];
for (int i = 0; i < 6; i++)
{
mORKS.NoodleCookerStatus[i] = bools[i];
}
mORKS.Feeding = bools[6];

bools = (bool[])peripheralStatus["M103.0"];
for (int i = 0; i < 6; i++)
{
mORKS.CookNoodlesComplete[i] = bools[i];
}

EventBus.EventBus.GetInstance().Publish(new ReadModel() { Id = DeviceId, Address = "VW372", Length = 1 }, (o) =>
{
if (o != null && o.Length > 0 && o[0] is ushort value)
{
mORKS.TurntableFeedbackloc = value;
}
});

Thread.Sleep(500);
}), "ReadPLCData", true);

#region 替换为内部主动读取
/*
ThreadManage.GetInstance().StartLong(new Action(() =>
{
@@ -186,6 +241,7 @@ namespace BPASmartClient.MorkS
Thread.Sleep(500);
}), "ReadPLCData", true);
*/
#endregion
}

/// <summary>


+ 1
- 1
BPASmartClient.MorkT/Device_MorkT.cs View File

@@ -12,7 +12,7 @@ namespace BPASmartClient.MorkT
{
public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKIC; } }

public override void StartMain()
public override void DoMain()
{
}



+ 7
- 1
BPASmartClient.Peripheral/BasePeripheral.cs View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -27,7 +28,7 @@ namespace BPASmartClient.Peripheral
/// <summary>
/// 外设状态集合
/// </summary>
protected Dictionary<string, object> status = new Dictionary<string, object>();
protected ConcurrentDictionary<string, object> status = new ConcurrentDictionary<string, object>();

/// <summary>
/// 初始化外设状态
@@ -47,5 +48,10 @@ namespace BPASmartClient.Peripheral
public abstract void Stop();

public abstract void Init();

public ConcurrentDictionary<string, object> GetAllStatus()
{
return status;
}
}
}

+ 6
- 0
BPASmartClient.Peripheral/IPeripheral.cs View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -22,6 +23,11 @@ namespace BPASmartClient.Peripheral
/// <returns>状态值</returns>
object? GetStatus(string statusName);
/// <summary>
/// 获取所有状态
/// </summary>
/// <returns>状态值</returns>
ConcurrentDictionary<string, object> GetAllStatus();
/// <summary>
/// 初始化
/// </summary>
void Init();


Loading…
Cancel
Save