Browse Source

MQTT物料推送修改

样式分支
pry 2 years ago
parent
commit
03db3ddd5f
6 changed files with 139 additions and 100 deletions
  1. +12
    -16
      BPASmartClient.Business/Plugin/DeviceMgr.cs
  2. +16
    -2
      BPASmartClient.Business/Plugin/OrderProxy.cs
  3. +2
    -2
      BPASmartClient.Device/IDevice.cs
  4. +2
    -2
      BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs
  5. +2
    -2
      BPASmartClient.Modbus/ModbusTcp.cs
  6. +105
    -76
      BPASmartClient.MorkS/Control_Morks.cs

+ 12
- 16
BPASmartClient.Business/Plugin/DeviceMgr.cs View File

@@ -65,7 +65,6 @@ namespace BPASmartClient.Business
{

string Namespace = device.DeviceNamespace.Substring(0, device.DeviceNamespace.LastIndexOf('.'));
//string startModel = device.DeviceNamespace.Substring(device.DeviceNamespace.LastIndexOf('.') + 1);
var deviceTemp = Assembly.Load(Namespace).CreateInstance(device.DeviceNamespace) as IDevice;
deviceTemp.Name = device?.DeviceName;
deviceTemp.DeviceId = int.Parse(device.DeviceId);
@@ -75,7 +74,6 @@ namespace BPASmartClient.Business
foreach (var comms in device.communicationDevcies)//通讯集合
{
string IPeripheralNamespace = comms.CommunicationNamespace.Substring(0, comms.CommunicationNamespace.LastIndexOf('.'));
//string IPeripheralStartModel = comms.CommunicationNamespace.Substring(comms.CommunicationNamespace.LastIndexOf('.'));
var peripheralTemp = Assembly.Load(IPeripheralNamespace).CreateInstance(comms.CommunicationNamespace) as IPeripheral;
peripheralTemp.variables = comms.variables;
peripheralTemp.communicationPar = comms.communicationPar;
@@ -141,24 +139,22 @@ namespace BPASmartClient.Business

if (PushType == 1)
{
device.recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result);
//EventBus.EventBus.GetInstance().Publish(new RecipeBomEvent()
//{
// DeviceId = device.DeviceId,
// recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result)
//});
MessageLog.GetInstance.Show("接收到辅料信息");
new RecipeBomEvent()
{
DeviceId = device.DeviceId,
recipeBoms = JsonConvert.DeserializeObject<RecipeBoms>(result)
}.Publish();
MessageLog.GetInstance.Show("接收到【 API 】获取的辅料信息");
}
else if (PushType == 0)
{
var apiData = JsonConvert.DeserializeObject<OrderMaterialDelivery>(result);
device.orderMaterialDelivery = apiData;
//EventBus.EventBus.GetInstance().Publish(new MaterialDeliveryEvent()
//{
// DeviceId = device.DeviceId,
// orderMaterialDelivery = apiData
//});
MessageLog.GetInstance.Show("接收到物料信息");
new MaterialDeliveryEvent()
{
DeviceId = device.DeviceId,
orderMaterialDelivery = apiData
}.Publish();
MessageLog.GetInstance.Show("接收到【 API 】获取的物料信息");
apiData?.BatchingInfo?.ForEach(x =>
{
MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");


+ 16
- 2
BPASmartClient.Business/Plugin/OrderProxy.cs View File

@@ -78,12 +78,26 @@ namespace BPASmartClient.Business
//辅料信息
else if (message is RecipeBoms recipe)
{

new RecipeBomEvent()
{
DeviceId = recipe.DeviceId,
recipeBoms = recipe
}.Publish();
MessageLog.GetInstance.Show("接收到 【 MQTT 】 的辅料信息");
}
//物料消息
else if (message is OrderMaterialDelivery delivery)
{

new MaterialDeliveryEvent()
{
DeviceId = delivery.DeviceId,
orderMaterialDelivery = delivery
}.Publish();
MessageLog.GetInstance.Show("接收到 【 MQTT 】 的物料信息");
delivery?.BatchingInfo?.ForEach(x =>
{
MessageLog.GetInstance.Show($"物料ID:=[{x.BatchingId}],{x.BatchingLoc}号位置:{x.BatchingCount}");
});
}
});



+ 2
- 2
BPASmartClient.Device/IDevice.cs View File

@@ -32,12 +32,12 @@ namespace BPASmartClient.Device
/// <summary>
/// 订单物料信息
/// </summary>
OrderMaterialDelivery orderMaterialDelivery { get; set; }
//OrderMaterialDelivery orderMaterialDelivery { get; set; }

/// <summary>
/// 配方数据信息
/// </summary>
RecipeBoms recipeBoms { get; set; }
//RecipeBoms recipeBoms { get; set; }

/// <summary>
/// 设备所有状态


+ 2
- 2
BPASmartClient.MORKSM.BK.PLC/PLCMachine.cs View File

@@ -35,7 +35,7 @@ namespace BPASmartClient.PLC
{
if (par?.Address.Length > 0)
{
var res = modbusTcp.READD(par.Address, (ushort)par.ReadLeng);
var res = modbusTcp.Read(par.Address, (ushort)par.ReadLeng);
if (status.ContainsKey(par.Address))
{
status[par.Address] = res;
@@ -106,7 +106,7 @@ namespace BPASmartClient.PLC
if (@event == null) return;
var par = @event as WriteModel;

modbusTcp.WRITEE(par?.Address, par?.Value);
modbusTcp.Write(par?.Address, par?.Value);
//ushort address = (ushort)modbusTcp.GetAddress(par?.Address);
//if (par.Address.ToUpper().Contains("M"))
//{


+ 2
- 2
BPASmartClient.Modbus/ModbusTcp.cs View File

@@ -129,7 +129,7 @@ namespace BPASmartClient.Modbus
// }
//}

public object READD(string address, ushort len = 1, byte slaveAddress = 1)
public object Read(string address, ushort len = 1, byte slaveAddress = 1)
{
if (address == null || tcpClient == null) return default(object);
ushort startAddress = (ushort)GetAddress(address);
@@ -164,7 +164,7 @@ namespace BPASmartClient.Modbus
return default(object);
}

public void WRITEE<T>(string address, T value, byte slaveAddress = 1)
public void Write<T>(string address, T value, byte slaveAddress = 1)
{
if (address == null || tcpClient == null) return;
ushort startAddress = (ushort)GetAddress(address);


+ 105
- 76
BPASmartClient.MorkS/Control_Morks.cs View File

@@ -73,116 +73,145 @@ namespace BPASmartClient.MorkS
EventBus.EventBus.GetInstance().Publish(new OrderStatusChangedEvent() { GoodName = goodName, Status = oRDER_STATUS, SubOrderId = subid, deviceClientType = DeviceType });
}

private void ReadData(string address, ushort len = 1, Action<bool[]> action = null)
{
EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = address, Length = len }, (o) =>
{
if (o != null && o.Length > 0 && o[0] is bool[] bools)
{
action(bools);
}
});
}
private void GetStatus(string key, Action<bool[]> action)
//private void ReadData(string address, ushort len = 1, Action<bool[]> action = null)
//{
// EventBus.EventBus.GetInstance().Publish(new ReadModel() { DeviceId = DeviceId, Address = address, Length = len }, (o) =>
// {
// if (o != null && o.Length > 0 && o[0] is bool[] bools)
// {
// action(bools);
// }
// });
//}
private void GetStatus(string key, Action<object> action)
{
if (peripheralStatus.ContainsKey(key))
{
if (peripheralStatus[key] is bool[] bools)
if (peripheralStatus[key] != null)
{
action?.Invoke(bools);
action?.Invoke(peripheralStatus[key]);
}
//action((bool[])peripheralStatus[key]);
//if (peripheralStatus[key] is bool[] bools)
//{
// action?.Invoke(bools);
//}
}
}

public override void ReadData()
{
GetStatus("M230.0", new Action<bool[]>((bools) =>
GetStatus("M230.0", new Action<object>((obj) =>
{
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.DeviceEstop = bools[10];
alarm.RobotInitError = bools[11];
alarm.RobotUrgentStop = bools[12];
alarm.RobotNotInRemoteMode = bools[13];
alarm.RobotNotInReady = bools[14];
alarm.RobotSelfInException = bools[15];
alarm.LeftLackWater = bools[16];
alarm.RightLackWater = bools[17];
alarm.SvrewInitFail = bools[18];
alarm.TurntableInitFail = bools[19];
alarm.RobotInitFail = bools[20];
alarm.NoodleCookerInitFail = bools[21];
alarm.PushBowlInitFail1 = bools[22];
alarm.PushBowlInitFail2 = bools[23];
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 24)
{
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.DeviceEstop = bools[10];
alarm.RobotInitError = bools[11];
alarm.RobotUrgentStop = bools[12];
alarm.RobotNotInRemoteMode = bools[13];
alarm.RobotNotInReady = bools[14];
alarm.RobotSelfInException = bools[15];
alarm.LeftLackWater = bools[16];
alarm.RightLackWater = bools[17];
alarm.SvrewInitFail = bools[18];
alarm.TurntableInitFail = bools[19];
alarm.RobotInitFail = bools[20];
alarm.NoodleCookerInitFail = bools[21];
alarm.PushBowlInitFail1 = bools[22];
alarm.PushBowlInitFail2 = bools[23];
}
}));

GetStatus("M0.3", new Action<bool[]>((bools) =>
GetStatus("M0.3", new Action<object>((obj) =>
{
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotOutMeal = bools[1];
mORKS.MoveTurntable = bools[2];
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 3)
{
mORKS.RobotTakeNoodle = bools[0];
mORKS.RobotOutMeal = bools[1];
mORKS.MoveTurntable = bools[2];
}
}));

GetStatus("M100.0", new Action<bool[]>((bools) =>
GetStatus("M100.0", new Action<object>((obj) =>
{
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];
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 16)
{
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];
}

}));

GetStatus("M235.0", new Action<bool[]>((bools) =>
GetStatus("M235.0", new Action<object>((obj) =>
{
mORKS.Error = bools[0];
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 1)
{
mORKS.Error = bools[0];
}
}));


GetStatus("M102.0", new Action<bool[]>((bools) =>
GetStatus("M102.0", new Action<object>((obj) =>
{
for (int i = 0; i < 6; i++)
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 7)
{
mORKS.NoodleCookerStatus[i] = bools[i];
for (int i = 0; i < 6; i++)
{
mORKS.NoodleCookerStatus[i] = bools[i];
}
mORKS.Feeding = bools[6];
}
mORKS.Feeding = bools[6];
}));

GetStatus("M103.0", new Action<bool[]>((bools) =>
GetStatus("M103.0", new Action<object>((obj) =>
{
for (int i = 0; i < 6; i++)
if (obj is bool[] bools && bools.Length > 0 && bools.Length <= 6)
{
mORKS.CookNoodlesComplete[i] = bools[i];
for (int i = 0; i < 6; i++)
{
mORKS.CookNoodlesComplete[i] = bools[i];
}
}

}));

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

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

/// <summary>


Loading…
Cancel
Save