|
|
@@ -17,7 +17,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
public SiemensHelper HK_PLC_S7 = new SiemensHelper(); |
|
|
|
public bool IsConnected => HK_PLC_S7.IsConnected; |
|
|
|
public DB_Read PlcRead = new DB_Read(); |
|
|
|
public DL_DataColl_DB DataColl =new DL_DataColl_DB(); |
|
|
|
public DL_DataColl_DB DataColl = new DL_DataColl_DB(); |
|
|
|
public void Init() |
|
|
|
{ |
|
|
|
try |
|
|
@@ -25,7 +25,8 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
DB_Write PlcWrite = new DB_Write(); |
|
|
|
HK_PLC_S7.WriteClass<DB_Write>(PlcWrite, 99); |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
MessageNotify.GetInstance.ShowRunLog("DB99块初始化值 失败"); |
|
|
|
} |
|
|
|
ThreadManage.GetInstance().StartLong(new Action(() => |
|
|
@@ -55,7 +56,7 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
} |
|
|
|
} |
|
|
|
Thread.Sleep(10); |
|
|
|
}),"海科数据交互",true); |
|
|
|
}), "海科数据交互", true); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 往plc下发配方数据 |
|
|
@@ -64,9 +65,9 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
{ |
|
|
|
if (IsConnected) |
|
|
|
{ |
|
|
|
if (recipe != null) |
|
|
|
if (recipe != null) |
|
|
|
{ |
|
|
|
HK_PLC_S7.Write("DB99.DBW2.0",Convert.ToInt16(recipe.TrayCode)); |
|
|
|
HK_PLC_S7.Write("DB99.DBW2.0", Convert.ToInt16(recipe.TrayCode)); |
|
|
|
HK_PLC_S7.Write("DB99.DBW4.0", Convert.ToInt16(recipe.TrayCode)); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号DB99.DBW2.0:{recipe.TrayCode},下发完成"); |
|
|
|
for (int barrel = 1; barrel < 6; barrel++) |
|
|
@@ -76,59 +77,80 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
for (int loc = 1; loc < 15; loc++) |
|
|
|
{ |
|
|
|
int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc); |
|
|
|
|
|
|
|
#region 新版本 |
|
|
|
int x = 0; |
|
|
|
if (barrel < 3) x = (barrel - 1) * 56 + 6; |
|
|
|
else if (barrel > 3) x = (barrel - 2) * 56 + 6; |
|
|
|
string address = "DB99.DBD" + (x + 4 * (loc - 1)); |
|
|
|
|
|
|
|
if (index == -1) |
|
|
|
{ |
|
|
|
switch (barrel) |
|
|
|
{ |
|
|
|
case 1: |
|
|
|
string address = "DB99.DBD" + (6 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address, 0); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
string address1 = "DB99.DBD" + (62 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address1, 0); |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
string address2 = "DB99.DBD" + (118 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address2, 0); |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
string address3 = "DB99.DBD" + (174 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address3, 0); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
HK_PLC_S7.Write(address, 0); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
switch (barrel) |
|
|
|
{ |
|
|
|
case 1: |
|
|
|
string address = "DB99.DBD" + (6 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
string address1 = "DB99.DBD" + (62 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address1, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
string address2 = "DB99.DBD" + (118 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address2, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
string address3 = "DB99.DBD" + (174 + 4 * (loc - 1)); |
|
|
|
HK_PLC_S7.Write(address3, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
HK_PLC_S7.Write(address, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 旧版本 |
|
|
|
//if (index == -1) |
|
|
|
//{ |
|
|
|
// switch (barrel) |
|
|
|
// { |
|
|
|
// case 1: |
|
|
|
// string address = "DB99.DBD" + (6 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address, 0); |
|
|
|
// break; |
|
|
|
// case 2: |
|
|
|
// string address1 = "DB99.DBD" + (62 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address1, 0); |
|
|
|
// break; |
|
|
|
// case 4: |
|
|
|
// string address2 = "DB99.DBD" + (118 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address2, 0); |
|
|
|
// break; |
|
|
|
// case 5: |
|
|
|
// string address3 = "DB99.DBD" + (174 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address3, 0); |
|
|
|
// break; |
|
|
|
// default: |
|
|
|
// break; |
|
|
|
|
|
|
|
// } |
|
|
|
//} |
|
|
|
//else |
|
|
|
//{ |
|
|
|
// switch (barrel) |
|
|
|
// { |
|
|
|
// case 1: |
|
|
|
// string address = "DB99.DBD" + (6 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
// MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
// break; |
|
|
|
// case 2: |
|
|
|
// string address1 = "DB99.DBD" + (62 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address1, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
// MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
// break; |
|
|
|
// case 4: |
|
|
|
// string address2 = "DB99.DBD" + (118 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address2, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
// MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
// break; |
|
|
|
// case 5: |
|
|
|
// string address3 = "DB99.DBD" + (174 + 4 * (loc - 1)); |
|
|
|
// HK_PLC_S7.Write(address3, recipe.RawMaterial.ElementAt(index).RawMaterialWeight); |
|
|
|
// MessageNotify.GetInstance.ShowRunLog($"配方编号:{recipe.RecipeCode},托盘编号:{recipe.TrayCode},桶号:{barrel},位置:{loc},重量:{recipe.RawMaterial.ElementAt(index).RawMaterialWeight}"); |
|
|
|
// break; |
|
|
|
// default: |
|
|
|
// break; |
|
|
|
// } |
|
|
|
//} |
|
|
|
#endregion |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -244,4 +266,4 @@ namespace BPASmartClient.JXJFoodBigStation.Model.HK_PLC |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |