Browse Source

morks调试

样式分支
pry 2 years ago
parent
commit
0094518fec
17 changed files with 307 additions and 330 deletions
  1. +5
    -5
      BPASmartClient.Business/MainConsole.cs
  2. +28
    -41
      BPASmartClient.Business/Plugin/OrderProxy.cs
  3. +2
    -1
      BPASmartClient.Business/Plugin/StatusMgr.cs
  4. +4
    -3
      BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml
  5. +87
    -87
      BPASmartClient.CustomResource/Themes/GenricStyle.xaml
  6. +4
    -1
      BPASmartClient.CustomResource/UserControls/IcoButton.xaml
  7. +20
    -6
      BPASmartClient.Helper/ActionManage.cs
  8. +9
    -0
      BPASmartClient.Helper/ExpandMethod.cs
  9. +6
    -2
      BPASmartClient.Helper/ThreadManage.cs
  10. +1
    -1
      BPASmartClient.MORKSM.BK.PLC/MorksMachine.cs
  11. +8
    -4
      BPASmartClient.Modbus/ModbusTcp.cs
  12. +22
    -86
      BPASmartClient.MorkS/Control.cs
  13. +2
    -2
      BPASmartClient.ViewModel/MainViewModel.cs
  14. +87
    -74
      BPASmartClient.ViewModel/OrderStatusViewModel.cs
  15. +1
    -1
      BPASmartClient/App.xaml
  16. +6
    -1
      BPASmartClient/Control/OrderStatusView.xaml
  17. +15
    -15
      BPASmartClient/DeviceInfo.xml

+ 5
- 5
BPASmartClient.Business/MainConsole.cs View File

@@ -22,14 +22,14 @@ namespace BPASmartClient.Business
InternetInfo.InitConfig();
//业务插件初始化
Plugin.GetInstance().Init();
//设备开启
Plugin.GetInstance().GetPlugin<DeviceMgr>().StartService();

MessageLog.GetInstance.InfoNotify = new Action<string>((msg =>
{
Console.WriteLine(msg);
}));
//MessageLog.GetInstance.InfoNotify = new Action<string>((msg =>
//{
// Console.WriteLine(msg);
//}));
}

/// <summary>


+ 28
- 41
BPASmartClient.Business/Plugin/OrderProxy.cs View File

@@ -1,4 +1,5 @@
using BPA.Message;
//#define test
using BPA.Message;
using BPA.Message.Enum;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
@@ -28,12 +29,32 @@ namespace BPASmartClient.Business
private bool running = false;
//设备管理
private DeviceMgr deviceMgr;
ConcurrentQueue<MorkOrderPush> morkOrderPushes = new ConcurrentQueue<MorkOrderPush>();
/// <summary>
/// 初始化
/// </summary>
public void Initialize()
{
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>();
#if test
ThreadManage.GetInstance().StartLong(new Action(() =>
{
while (morkOrderPushes.Count > 0)
{
if (morkOrderPushes.TryDequeue(out MorkOrderPush mork))
{
Thread.Sleep(3000);
new OrderStatusChangedEvent() { Status = ORDER_STATUS.COOKING, SubOrderId = mork.SuborderId }.Publish();
Thread.Sleep(5000);
new OrderStatusChangedEvent() { Status = ORDER_STATUS.COMPLETED_COOK, SubOrderId = mork.SuborderId }.Publish();
Thread.Sleep(5000);
new OrderStatusChangedEvent() { Status = ORDER_STATUS.COMPLETED_TAKE, SubOrderId = mork.SuborderId }.Publish();
Thread.Sleep(2000);
}
}
Thread.Sleep(1000);
}), "sim order");
#endif
}

public void Start()
@@ -84,48 +105,13 @@ namespace BPASmartClient.Business
{
if (orders[deviceId].TryDequeue(out MorkOrderPush temp))
{
#if test
morkOrderPushes.Enqueue(temp);
#endif
var orderEvent = DoOrderEvent.Make(temp);
orderEvent.Id = device.DeviceId;
orderEvent.Publish();

#region 添加订单
ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
observableCollection.Add(new MorkOrder()
{
OrderStatus = ORDER_STATUS.WAIT
});
var res = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.DeviceId == deviceId.ToString());
if (res == null)
{
Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
{
DeviceId = device.ToString(),
IsAllSelect = true,
morkOrderPushes = observableCollection
});
}
else
{
res.morkOrderPushes.Add(new MorkOrder() { OrderPush = temp });
}

#endregion




//Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
//{
// DeviceId = device.ToString(),
// IsAllSelect = true,
// morkOrderPushes = observableCollection
//});
//Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
//{
// IsSelected = true,
// OrderPush = temp,
// OrderStatus = BPA.Message.Enum.ORDER_STATUS.WAIT
//});
ActionManage.GetInstance.Send("AddOrder", new object[] { temp, device });
}
}
Thread.Sleep(50);
@@ -149,7 +135,8 @@ namespace BPASmartClient.Business
MessageLog.GetInstance.ShowEx(ex.ToString());
}
var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
MessageLog.GetInstance.ShowEx(string.Format("订单状态改变,调用API执行结果{0}", res == null ? false : res.isSuccess));
ActionManage.GetInstance.Send("OrderStatusChange", orderStatusChangedEvent);
MessageLog.GetInstance.Show(string.Format("订单状态改变,调用API执行结果{0}", res == null ? false : res.isSuccess));
}

/// <summary>


+ 2
- 1
BPASmartClient.Business/Plugin/StatusMgr.cs View File

@@ -57,6 +57,7 @@ namespace BPASmartClient.Business
{
wholeDeviceStatus[device.DeviceId] = device.Status.GetStatus();
deviceStatus.Healthy = device.IsHealth ? BPA.Message.Enum.DeviceHealthy.Health : BPA.Message.Enum.DeviceHealthy.UnHealth;
deviceStatus.DeviceType = device.DeviceType;
var msg = BPAPackage.Make(deviceStatus, device.DeviceId, device.DeviceType);
mqttMgr.Publish(TopicDefine.GetInstance().PushHeartbeatTopics[device.DeviceType], msg.Serialize());
}
@@ -70,6 +71,6 @@ namespace BPASmartClient.Business
running = false;
}

}
}

+ 4
- 3
BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml View File

@@ -1,6 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters">
<!-- 文本框的字体颜色 -->
<SolidColorBrush x:Key="TextBlockForeground" Color="#9934F7F7" />
<!--<con:StringToIconConverter x:Key="StringToIconConverter"/>-->

+ 87
- 87
BPASmartClient.CustomResource/Themes/GenricStyle.xaml View File

@@ -557,93 +557,6 @@
<SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
<ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
<VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
<VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#FF448DCA"
Duration="0" />
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#FF448DCA" />
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="Highlight"
Storyboard.TargetProperty="(UIElement.Opacity)"
Duration="00:00:00.001">
<SplineDoubleKeyFrame KeyTime="0" Value="1" />
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid
Width="19"
Height="18"
@@ -764,6 +677,93 @@
Source="/BPASmartClient.CustomResource;component/Image/日历.png" />

</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
<VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
<VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
To="#FF448DCA"
Duration="0" />
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#FF448DCA" />
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="Highlight"
Storyboard.TargetProperty="(UIElement.Opacity)"
Duration="00:00:00.001">
<SplineDoubleKeyFrame KeyTime="0" Value="1" />
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF" />
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
BeginTime="0"
Storyboard.TargetName="BackgroundGradient"
Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
Duration="00:00:00.001">
<SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Grid.Resources>


+ 4
- 1
BPASmartClient.CustomResource/UserControls/IcoButton.xaml View File

@@ -64,7 +64,10 @@
FontFamily="../Fonts/#iconfont"
Text="{Binding Path=IcoText, Mode=TwoWay, Converter={StaticResource StringToIconConverter}}" />-->

<TextBlock x:Name="tbx" Foreground="Red" FontSize="14" />
<TextBlock
x:Name="tbx"
FontSize="14"
Foreground="Red" />
<!--<Button Name="a">
<Button.Style>
<Style TargetType="Button">


+ 20
- 6
BPASmartClient.Helper/ActionManage.cs View File

@@ -14,6 +14,7 @@ namespace BPASmartClient.Helper
public static ActionManage GetInstance => _Instance ?? (_Instance = new ActionManage());
private ActionManage() { }

//private static ConcurrentDictionary<string, delegate> actions = new ConcurrentDictionary<string, delegate>();
private static ConcurrentDictionary<string, Delegation> actions = new ConcurrentDictionary<string, Delegation>();

static readonly object SendLock = new object();
@@ -40,11 +41,18 @@ namespace BPASmartClient.Helper
{
lock (SendLock)
if (actions.ContainsKey(key)) actions[key].ActionPar.Invoke(par, Callback);
//if (actions[key].ActionPar != null)
//{
// actions[key].ActionPar(par);
// if (Callback != null) Callback();
//}
}

/// <summary>
/// 执行注册过的委托
/// </summary>
/// <param name="key">注册委托的key</param>
/// <param name="par">委托参数</param>
/// <param name="Callback">委托回调</param>
public void Send(string key, object[] par, Action Callback = null)
{
lock (SendLock)
if (actions.ContainsKey(key)) actions[key].ActionPars.Invokes(par, Callback);
}

/// <summary>
@@ -89,6 +97,9 @@ namespace BPASmartClient.Helper
if (action is Action<object> actionObj)
actions.TryAdd(key, new Delegation() { ActionPar = actionObj });

if (action is Action<object[]> actionObjs)
actions.TryAdd(key, new Delegation() { ActionPars = actionObjs });

if (action is Func<object> funcObj)
actions.TryAdd(key, new Delegation() { FuncObj = funcObj });

@@ -110,10 +121,13 @@ namespace BPASmartClient.Helper
/// </summary>
public Action<object> ActionPar { get; set; }
/// <summary>
/// 带参数的委托
/// </summary>
public Action<object[]> ActionPars { get; set; }
/// <summary>
/// 无参数的委托
/// </summary>
public Action ActionBus { get; set; }
public Action CallBack { get; set; }
/// <summary>
/// 有返回值的委托
/// </summary>


+ 9
- 0
BPASmartClient.Helper/ExpandMethod.cs View File

@@ -63,6 +63,15 @@ namespace BPASmartClient.Helper
}
}

public static void Invokes(this Action<object[]> action, object[] par, Action callback)
{
if (action != null)
{
action(par);
if (callback != null) callback();
}
}



///// <summary>


+ 6
- 2
BPASmartClient.Helper/ThreadManage.cs View File

@@ -86,7 +86,6 @@ namespace BPASmartClient.Helper
/// <param name="key"></param>
public void Start(Action action, string key, bool isRestart = true)
{
MessageLog.GetInstance.Show($"线程 【{key}】启动");
CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource());
bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() =>
{
@@ -96,7 +95,7 @@ namespace BPASmartClient.Helper
}
catch (Exception ex)
{
MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常");
MessageLog.GetInstance.ShowEx(ex.ToString());
if (isRestart)
{
MessageLog.GetInstance.Show($"线程 【{key}】正在重启");
@@ -104,11 +103,16 @@ namespace BPASmartClient.Helper
Threads.TryRemove(guid + key, out Task item2);
Start(action, key, isRestart);
}
else
{
MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常");
}
}
}), CancellationTokenSources[guid + key].Token).ContinueWith(new Action<Task, object>((t, o) =>
{
ThreadStatus(t, o.ToString());
}), guid + key));
MessageLog.GetInstance.Show($"启动线程 【{key}】");
if (!result) MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName");
}



+ 1
- 1
BPASmartClient.MORKSM.BK.PLC/MorksMachine.cs View File

@@ -22,7 +22,7 @@ namespace BPASmartClient.PLC
{
plcReadParameters = PLCReadParameter.DeSerialize(PLCReadAddress);

modbusTcp.ModbusTcpConnect(IpAddress, Port);//PLC 设备连接
Task.Run(new Action(() => { modbusTcp.ModbusTcpConnect(IpAddress, Port); })); //PLC 设备连接

ThreadManage.GetInstance().StartLong(new Action(() =>
{


+ 8
- 4
BPASmartClient.Modbus/ModbusTcp.cs View File

@@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;

namespace BPASmartClient.Modbus
{
@@ -44,8 +44,6 @@ namespace BPASmartClient.Modbus
master.Transport.ReadTimeout = 2000;//读取超时时间
master.Transport.WriteTimeout = 2000;//写入超时时间
master.Transport.Retries = 10;//重试次数
//ActionManage.GetInstance.Send("ConnectOk");
//ActionManage.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk");
MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接成功");
}

@@ -97,7 +95,7 @@ namespace BPASmartClient.Modbus
}
}
}
else if (address.ToUpper().Contains("VW") && address.Length > 3)
else if (address.ToUpper().Contains("VW") && address.Length >= 3)
{
var res = address.Substring(2);
if (res != null && int.TryParse(res, out int tempAddress))
@@ -154,6 +152,12 @@ namespace BPASmartClient.Modbus
action(bools);
}
}
else if (result is bool bl)
{
List<bool> boolLists = new List<bool>();
boolLists.Add(bl);
action(boolLists.ToArray());
}
}
}



+ 22
- 86
BPASmartClient.MorkS/Control.cs View File

@@ -103,74 +103,27 @@ namespace BPASmartClient.MorkS
});
}

private void ReadPLCData()
private void GetStatus(string key, Action<bool[]> action)
{
ThreadManage.GetInstance().StartLong(new Action(() =>
if (peripheralStatus.ContainsKey(key))
{
var bools = (bool[])peripheralStatus["M0.3"];
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);
action((bool[])peripheralStatus[key]);
}
}

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

ReadData("M0.3", 3, new Action<bool[]>((bools) =>
{
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotOutMeal = bools[1];
mORKS.MoveTurntable = bools[2];
}));
GetStatus("M0.3", new Action<bool[]>((bools) =>
{
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotOutMeal = bools[1];
mORKS.MoveTurntable = bools[2];
}));

ReadData("M100.0", 16, new Action<bool[]>((bools) =>
GetStatus("M100.0", new Action<bool[]>((bools) =>
{
mORKS.InitComplete = bools[0];
mORKS.TakeBowlIdle = bools[1];
@@ -190,9 +143,13 @@ namespace BPASmartClient.MorkS
mORKS.TurntableMoveInPlace = bools[15];
}));

ReadData("M235.0", 1, new Action<bool[]>((bools) => { mORKS.Error = bools[0]; }));
GetStatus("M235.0", new Action<bool[]>((bools) =>
{
mORKS.Error = bools[0];
}));


ReadData("M102.0", 7, new Action<bool[]>((bools) =>
GetStatus("M102.0", new Action<bool[]>((bools) =>
{
for (int i = 0; i < 6; i++)
{
@@ -201,7 +158,7 @@ namespace BPASmartClient.MorkS
mORKS.Feeding = bools[6];
}));

ReadData("M103.0", 6, new Action<bool[]>((bools) =>
GetStatus("M103.0", new Action<bool[]>((bools) =>
{
for (int i = 0; i < 6; i++)
{
@@ -209,25 +166,6 @@ namespace BPASmartClient.MorkS
}
}));

//ReadData("M550.0", 20, new Action<bool[]>((bools) =>
//{
// //alarm.MachineLeftLowTemperature = bools[0];
// //alarm.MachineRightLowTemperature = bools[1];
// //alarm.Supply1_LossBowl = bools[2];
// //alarm.Supply2_LossBowl = bools[3];
// //alarm.Supply1_ErrorOutBowl = bools[4];
// //alarm.Supply2_ErrorOutBowl = bools[5];
// //alarm.PushBowlCylinderError = bools[6];
// //alarm.NoodleMacCommunicateError = bools[7];
// //alarm.DosingMacCommunicateError = bools[8];
// //alarm.RobotMacCommunicateError = bools[9];
// //alarm.RobotInitError = bools[11];
// //alarm.RobotUrgentStop = bools[12];
// //alarm.RobotNotInRemoteMode = bools[13];
// //alarm.RobotNotInReady = bools[14];
// //alarm.RobotSelfInException = bools[15];
//}));

EventBus.EventBus.GetInstance().Publish(new ReadModel() { Id = DeviceId, Address = "VW372", Length = 1 }, (o) =>
{
if (o != null && o.Length > 0 && o[0] is ushort value)
@@ -238,8 +176,6 @@ namespace BPASmartClient.MorkS

Thread.Sleep(500);
}), "ReadPLCData", true);
*/
#endregion
}

/// <summary>
@@ -589,7 +525,7 @@ namespace BPASmartClient.MorkS
mORKS.CurrentLoc = loc;
mORKS.TurntableInterlock = true;
mORKS.TurntableLocLists.Add(loc);
WriteData("VW0", loc);
WriteData("VW2", loc);
WriteData("M0.5", true);
}



+ 2
- 2
BPASmartClient.ViewModel/MainViewModel.cs View File

@@ -15,11 +15,11 @@ namespace BPASmartClient.ViewModel
/// <summary>
/// 主界面
/// </summary>
public class MainViewModel :ObservableObject
public class MainViewModel : ObservableObject
{
public MainViewModel()
{
OrderStatusViewModel.Init();
}
}
}

+ 87
- 74
BPASmartClient.ViewModel/OrderStatusViewModel.cs View File

@@ -7,6 +7,8 @@ using System.Threading.Tasks;
using System.Windows;
using BPA.Message;
using BPA.Message.Enum;
using BPASmartClient.Device;
using BPASmartClient.EventBus;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
@@ -23,104 +25,115 @@ namespace BPASmartClient.ViewModel
/// <summary>
/// 订单状态列表
/// </summary>
public static ObservableCollection<OrderData> orderStatusLists
{
get { return Json<KeepDataBase>.Data.orderLists; }
set { Json<KeepDataBase>.Data.orderLists = value; }
}
public static ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();

/// <summary>
/// 等待取餐列表
/// </summary>
public static ObservableCollection<OrderData> WaitTakeMeal { get; set; } = new ObservableCollection<OrderData>();
public static ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>();

/// <summary>
/// MQTT 大屏取餐通知委托
/// </summary>
public void MqttReceive()
public static void Init()
{
//清除订单数据
ActionManage.GetInstance.Register(new Action(() =>
{
Application.Current.Dispatcher.Invoke(() =>
{
orderStatusLists.Clear();
WaitTakeMeal.Clear();
});
}), "ClearOrders");
//ActionManage.GetInstance.Register(new Action(() =>
//{
// Application.Current.Dispatcher.Invoke(() =>
// {
// orderStatusLists.Clear();
// WaitTakeMeal.Clear();
// });
//}), "ClearOrders");

ActionManage.GetInstance.Register(new Action<object>((o) =>
ActionManage.GetInstance.Register(new Action<object[]>((o) =>
{
if (o is MorkOrderPush morkOrderpush)
if (o is object[] obj)
{
System.Windows.Application.Current?.Dispatcher.BeginInvoke((Action)delegate
if (o.Length == 2)
{
//var result = orderStatusLists.FirstOrDefault(p => p.OrderPush.SuborderId == morkOrderpush.SuborderId);
//if (result == null)
//{
// orderStatusLists.Add(new OrderData()
// {
// OrderPush = morkOrderpush,
// OrderStatus = ORDER_STATUS.WAIT,
// IsSelected = true,
// StartDate = DateTime.Now.ToString("HH:mm:ss")
// });
//}
});
if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
{
ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
observableCollection.Add(new MorkOrder()
{
OrderPush = morkOrderpush,
OrderStatus = ORDER_STATUS.WAIT,
StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
});
//var res = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.DeviceId == device.ToString());
//if (res == null)
//{
Application.Current?.Dispatcher.BeginInvoke((Action)delegate
{
Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
{
DeviceId = device.ToString(),
IsAllSelect = true,
morkOrderPushes = observableCollection,

});
orderStatusLists.Add(new MorkOrder()
{
OrderPush = morkOrderpush,
OrderStatus = ORDER_STATUS.WAIT,
StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
});
});
//}
//else
//{
// res.morkOrderPushes.Add(new MorkOrder() { OrderPush = morkOrderpush });
//}

}
}
}

}), "AddOrder");

ActionManage.GetInstance.Register(new Action<object>((o) =>
{
if (o is OrderStatusChange orderStatusChange)
if (o is OrderStatusChangedEvent orderStatusChange)
{
Application.Current?.Dispatcher.BeginInvoke((Action)delegate
int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
switch (orderStatusChange.Status)
{
int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == orderStatusChange.SuborderId) != null);
int index2 = -1;
if (index >= 0 && index < orderStatusLists.Count)
{
index2 = Array.FindIndex(orderStatusLists.ElementAt(index).morkOrderPushes.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SuborderId);
}
if (index2 < 0) return;

switch (orderStatusChange.CookingStatus)
{
case ORDER_STATUS.COOKING:
if (index >= 0 && index < orderStatusLists.Count)
orderStatusLists.ElementAt(index).morkOrderPushes.ElementAt(index2).OrderStatus = orderStatusChange.CookingStatus;
break;
case ORDER_STATUS.COMPLETED_COOK:
if (index >= 0 && index < orderStatusLists.Count)
case ORDER_STATUS.COOKING:
if (index >= 0 && index < orderStatusLists.Count)
orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
break;
case ORDER_STATUS.COMPLETED_COOK:
if (index >= 0 && index < orderStatusLists.Count)
{
Application.Current.Dispatcher.BeginInvoke((Action)delegate
{
Application.Current.Dispatcher.BeginInvoke((Action)delegate
{
orderStatusLists.ElementAt(index).morkOrderPushes.ElementAt(index2).OrderStatus = orderStatusChange.CookingStatus;
orderStatusLists.ElementAt(index).morkOrderPushes.ElementAt(index2).EndDate = DateTime.Now.ToString("HH:mm:ss");
TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).morkOrderPushes.ElementAt(index2).StartDate));
orderStatusLists.ElementAt(index).morkOrderPushes.ElementAt(index2).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
orderStatusLists.RemoveAt(index);
});
}
orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
orderStatusLists.RemoveAt(index);
});
}

break;
case ORDER_STATUS.COMPLETED_TAKE:
var re = WaitTakeMeal.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == orderStatusChange.SuborderId) != null);
if (re != null)
break;
case ORDER_STATUS.COMPLETED_TAKE:
var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
if (re != null)
{
Application.Current.Dispatcher.BeginInvoke((Action)delegate
{
Application.Current.Dispatcher.BeginInvoke((Action)delegate
{
WaitTakeMeal.Remove(re);
Json<KeepDataBase>.Data.orderLists.Remove(re);
});
}
break;
default:
break;
}
});

WaitTakeMeal.Remove(re);
var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
});
}
break;
default:
break;
}
}
}), "OrderStatusChange");
}


+ 1
- 1
BPASmartClient/App.xaml View File

@@ -11,7 +11,7 @@
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecCheckBox.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecTitleBarButton.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/GlobalStyle.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecComboBox.xaml"/>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/RecDictionarys/RecComboBox.xaml" />
<!--<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml"/>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml"/>-->



+ 6
- 1
BPASmartClient/Control/OrderStatusView.xaml View File

@@ -5,11 +5,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.Control"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
Background="{x:Null}"
mc:Ignorable="d">

<UserControl.DataContext>
<vm:OrderStatusViewModel/>
</UserControl.DataContext>

<UserControl.Resources>
<SolidColorBrush x:Key="BorderSolid" Color="#5523CACA" />
<SolidColorBrush x:Key="FontColor" Color="#FF2AB2E7" />
@@ -131,7 +136,7 @@

<TextBlock
Grid.Column="0"
Foreground="{Binding OrderStatus, Converter={StaticResource ColorConverter}}"
Foreground="{Binding OrderStatus, Converter={StaticResource ColorConverter}}"
Style="{StaticResource TextBlockStyle}"
Text="{Binding OrderPush.SortNum}" />



+ 15
- 15
BPASmartClient/DeviceInfo.xml View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<BPADevices>
<!--<Device Name="MorkT" Module="BPASmartClient.MorkT.Device_MorkT" DeviceId="1">
<!--<Device Name="MorkT" Module="BPASmartClient.MorkT.Device_MorkT" DeviceId="1">
<Peripherals>
<Peripheral Module="BPASmartClient.Lebai.LebaiRobot">
<Parameters>
@@ -19,36 +19,36 @@
</Peripherals>
</Device>-->

<Device Name="MorkS" Module="BPASmartClient.MorkS.Control" DeviceId="2">
<!--<Parameters>
<Device Name="MorkS" Module="BPASmartClient.MorkS.Control" DeviceId="2">
<!--<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>-->
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters>
<IpAddress>127.0.0.1</IpAddress>
<Port>502</Port>
<PLCReadAddress>M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102,7;M,M103,6;VW,VW372,1</PLCReadAddress>
</Parameters>
</Peripheral>
<Peripherals>
<Peripheral Module="BPASmartClient.PLC.MorksMachine">
<Parameters>
<IpAddress>192.168.1.11</IpAddress>
<Port>508</Port>
<PLCReadAddress>M,M0.3,3;M,M100.0,16;M,M235.0,1;M,M102.0,7;M,M103.0,6;VW,VW372,1</PLCReadAddress>
</Parameters>
</Peripheral>

<!--<Peripheral Module="BPASmartClient.MORKSM.BK.PLC.MorksMachine">
<!--<Peripheral Module="BPASmartClient.MORKSM.BK.PLC.MorksMachine">
<Parameters>
<IpAddress>127.0.10.1</IpAddress>
<Port>11</Port>
</Parameters>
</Peripheral>-->

<!--<Peripheral Module="BPASmartClient.KLMCoffee.CoffeeMachine">
<!--<Peripheral Module="BPASmartClient.KLMCoffee.CoffeeMachine">
<Parameters>
<PortName>COM8</PortName>
<BaudRate>38400</BaudRate>
</Parameters>
</Peripheral>-->

</Peripherals>
</Device>
</Peripherals>
</Device>





Loading…
Cancel
Save