使用json存储通道信息
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1955,6 +1955,7 @@ namespace JinYuan.ControlCenters
|
||||
CommonMethods.mesConfig.equipNum,
|
||||
CommonMethods.mesConfig.MaterialCode);//分档查询
|
||||
|
||||
var channels = CommonMethods.mesConfig.ChannelConfig.Channels;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1964,44 +1965,59 @@ namespace JinYuan.ControlCenters
|
||||
list[i].Mes_sorting_scheme = mesResFangAnType[0];
|
||||
if (success && mesResType[0] != "NULL")
|
||||
{
|
||||
#region 注释代码
|
||||
//if (mesResType[0].Equals(CommonMethods.mesConfig.Grading1))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[0]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading2))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[1]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading3))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[2]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading4))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[3]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading5))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[4]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading6))
|
||||
//{
|
||||
// listGradeResult[i] = (short)(CommonMethods.MESGradingSet[5]);
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// listGradeResult[i] = (short)(97);// 走分档NG
|
||||
// list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},MES未反馈正确档位";
|
||||
// throw new Exception("MES未反馈正确档位");
|
||||
//}
|
||||
#endregion
|
||||
|
||||
if (mesResType[0].Equals(CommonMethods.mesConfig.Grading1))
|
||||
// MES分档查询
|
||||
var channel = channels.FirstOrDefault(it => it.Gears.Contains(mesResType[0]));
|
||||
|
||||
if (channel != null)
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[0] );
|
||||
listGradeResult[i] = (short)channel.DefaultValue;
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading2))
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[1]);
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading3))
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[2]);
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading4))
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[3]);
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading5))
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[4]);
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else if (mesResType[0].Equals(CommonMethods.mesConfig.Grading6))
|
||||
{
|
||||
listGradeResult[i] = (short)(CommonMethods.MESGradingSet[5]);
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},{listGradeResult[i]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
listGradeResult[i] = (short)(97);// 走分档NG
|
||||
list[i].Remark = $"出站条码[{list[i].BarCode}],MES反馈档位:{mesResType[0]},MES未反馈正确档位";
|
||||
throw new Exception("MES未反馈正确档位");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
<Compile Include="Hourprod.cs" />
|
||||
<Compile Include="BGearEntity.cs" />
|
||||
<Compile Include="SysConfig\ChallengeCode.cs" />
|
||||
<Compile Include="SysConfig\ChannelConfig.cs" />
|
||||
<Compile Include="SysConfig\Device.cs" />
|
||||
<Compile Include="CPKModel.cs" />
|
||||
<Compile Include="DeviceOEE.cs" />
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JinYuan.Models.SysConfig
|
||||
{
|
||||
public class ChannelConfig
|
||||
{
|
||||
public List<Channel> Channels { get; set; } = new List<Channel>();
|
||||
}
|
||||
|
||||
public class Channel
|
||||
{
|
||||
public int ChannelId { get; set; }
|
||||
public int DefaultValue { get; set; }
|
||||
public List<string> Gears { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace JinYuan.Models
|
||||
namespace JinYuan.Models.SysConfig
|
||||
{
|
||||
public class SysConfig
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ using JinYuan.DAL;
|
||||
using JinYuan.Helper;
|
||||
using JinYuan.MES;
|
||||
using JinYuan.Models;
|
||||
using JinYuan.Models.SysConfig;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -311,83 +313,96 @@ namespace JinYuan.VirtualDataLibrary
|
||||
{
|
||||
DateTime Date = DateTime.Now;
|
||||
|
||||
#region 档位写入
|
||||
MESGradingSet = new short[6];
|
||||
var gradingMap = new Dictionary<string, short>();
|
||||
var gGradingMap = new Dictionary<string, short>();
|
||||
short normalStart = 21;
|
||||
short gStart = 31;
|
||||
string[] specialGrading = new string[] { "NG", "扫码NG" };
|
||||
|
||||
var gradings = new[] {
|
||||
mesConfig.Grading1.Trim(),
|
||||
mesConfig.Grading2.Trim(),
|
||||
mesConfig.Grading3.Trim(),
|
||||
mesConfig.Grading4.Trim(),
|
||||
mesConfig.Grading5.Trim(),
|
||||
mesConfig.Grading6.Trim()
|
||||
};
|
||||
#region 档位写入
|
||||
//var gradingMap = new Dictionary<string, short>();
|
||||
//var gGradingMap = new Dictionary<string, short>();
|
||||
//short normalStart = 21;
|
||||
//short gStart = 31;
|
||||
//string[] specialGrading = new string[] { "NG", "扫码NG" };
|
||||
|
||||
for (int i = 0; i < gradings.Length; i++)
|
||||
{
|
||||
string grading = gradings[i];
|
||||
if (!specialGrading.Contains(grading) && grading.EndsWith("G"))
|
||||
{
|
||||
if (gGradingMap.TryGetValue(grading, out short value))
|
||||
MESGradingSet[i] = value;
|
||||
else
|
||||
{
|
||||
MESGradingSet[i] = gStart;
|
||||
gGradingMap.Add(grading, gStart);
|
||||
gStart++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gradingMap.TryGetValue(grading, out short value))
|
||||
MESGradingSet[i] = value;
|
||||
else
|
||||
{
|
||||
MESGradingSet[i] = normalStart;
|
||||
gradingMap.Add(grading, normalStart);
|
||||
normalStart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//var gradings = new[] {
|
||||
// mesConfig.Grading1.Trim(),
|
||||
// mesConfig.Grading2.Trim(),
|
||||
// mesConfig.Grading3.Trim(),
|
||||
// mesConfig.Grading4.Trim(),
|
||||
// mesConfig.Grading5.Trim(),
|
||||
// mesConfig.Grading6.Trim()
|
||||
//};
|
||||
|
||||
#region 更新默认档位
|
||||
for (int i = 0; i < gradings.Length; i++)
|
||||
{
|
||||
switch (gradings[i])
|
||||
{
|
||||
/* 性能NG */
|
||||
case "NG":
|
||||
MESGradingSet[i] = 98;
|
||||
break;
|
||||
/* 外观检NG
|
||||
case "E63yG":
|
||||
MESGradingSet[i] = 31;
|
||||
break;
|
||||
case "F63yG":
|
||||
MESGradingSet[i] = 32;
|
||||
break;
|
||||
*/
|
||||
/* 其它NG */
|
||||
case "拦截":
|
||||
case "扫码NG":
|
||||
case "其它":
|
||||
MESGradingSet[i] = 97;
|
||||
break;
|
||||
/* 性能NG */
|
||||
case "不设置":
|
||||
MESGradingSet[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
//for (int i = 0; i < gradings.Length; i++)
|
||||
//{
|
||||
// string grading = gradings[i];
|
||||
// if (!specialGrading.Contains(grading) && grading.EndsWith("G"))
|
||||
// {
|
||||
// if (gGradingMap.TryGetValue(grading, out short value))
|
||||
// MESGradingSet[i] = value;
|
||||
// else
|
||||
// {
|
||||
// MESGradingSet[i] = gStart;
|
||||
// gGradingMap.Add(grading, gStart);
|
||||
// gStart++;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (gradingMap.TryGetValue(grading, out short value))
|
||||
// MESGradingSet[i] = value;
|
||||
// else
|
||||
// {
|
||||
// MESGradingSet[i] = normalStart;
|
||||
// gradingMap.Add(grading, normalStart);
|
||||
// normalStart++;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//#region 更新默认档位
|
||||
//for (int i = 0; i < gradings.Length; i++)
|
||||
//{
|
||||
// switch (gradings[i])
|
||||
// {
|
||||
// /* 性能NG */
|
||||
// case "NG":
|
||||
// MESGradingSet[i] = 98;
|
||||
// break;
|
||||
// /* 外观检NG
|
||||
// case "E63yG":
|
||||
// MESGradingSet[i] = 31;
|
||||
// break;
|
||||
// case "F63yG":
|
||||
// MESGradingSet[i] = 32;
|
||||
// break;
|
||||
// */
|
||||
// /* 其它NG */
|
||||
// case "拦截":
|
||||
// case "扫码NG":
|
||||
// case "其它":
|
||||
// MESGradingSet[i] = 97;
|
||||
// break;
|
||||
// /* 性能NG */
|
||||
// case "不设置":
|
||||
// MESGradingSet[i] = 0;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
//#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
// 读取Chanel列表的默认值写入PLC
|
||||
if (mesConfig.ChannelConfig?.Channels == null || mesConfig.ChannelConfig.Channels.Count != 6)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Channel.json 不满足要求,文件不存在或没有6个通道");
|
||||
}
|
||||
|
||||
var channels = mesConfig.ChannelConfig.Channels;
|
||||
for (int i = 0; i < channels.Count; i++)
|
||||
{
|
||||
MESGradingSet[i] = (short)channels[i].DefaultValue;
|
||||
}
|
||||
|
||||
var isWrite1 = PlcLink.WriteValue("D2600", MESGradingSet[0], Data_Type.Short);
|
||||
var isWrite2 = PlcLink.WriteValue("D2601", MESGradingSet[1], Data_Type.Short);
|
||||
var isWrite3 = PlcLink.WriteValue("D2602", MESGradingSet[2], Data_Type.Short);
|
||||
@@ -519,6 +534,23 @@ namespace JinYuan.VirtualDataLibrary
|
||||
public static string iniFilePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "ini\\Configure.ini");
|
||||
|
||||
|
||||
public static string ChannelPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "Config\\settings.json");
|
||||
|
||||
#region 读取json配置
|
||||
public static Models.SysConfig.ChannelConfig LoadFromJson(string filePath)
|
||||
{
|
||||
var json = File.ReadAllText(filePath);
|
||||
return JsonConvert.DeserializeObject<ChannelConfig>(json);
|
||||
}
|
||||
|
||||
// 保存
|
||||
public static void SaveToJson(string filePath, ChannelConfig config)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
|
||||
File.WriteAllText(filePath, json);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 读取配置文件
|
||||
/// <summary>
|
||||
@@ -549,7 +581,7 @@ namespace JinYuan.VirtualDataLibrary
|
||||
mesConfig.Grading4 = IniConfigHelper.ReadIniData("MES配置", "Grading4", "false");
|
||||
mesConfig.Grading5 = IniConfigHelper.ReadIniData("MES配置", "Grading5", "false");
|
||||
mesConfig.Grading6 = IniConfigHelper.ReadIniData("MES配置", "Grading6", "false");
|
||||
|
||||
mesConfig.ChannelConfig = LoadFromJson(ChannelPath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\LargeSquareOne\Lib\JinYuan.CommunicationLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PLCCommunication, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\HBG_NegativeElectrodeWeld\Lib\PLCCommunication.dll</HintPath>
|
||||
@@ -104,6 +107,7 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Resources\感叹号提示-块红色.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using JinYuan.Models.SysConfig;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JinYuan.VirtualDataLibrary
|
||||
{
|
||||
@@ -139,6 +140,11 @@ namespace JinYuan.VirtualDataLibrary
|
||||
/// </summary>
|
||||
public string Grading6 = "拦截";
|
||||
|
||||
/// <summary>
|
||||
/// 通道档位设置
|
||||
/// </summary>
|
||||
public Models.SysConfig.ChannelConfig ChannelConfig = new ChannelConfig();
|
||||
|
||||
/// <summary>
|
||||
/// 设备状态
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
|
||||
</packages>
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"channels": [
|
||||
{
|
||||
"channelId": 1,
|
||||
"default": 21,
|
||||
"gears": [ "E63y", "F63y" ]
|
||||
},
|
||||
{
|
||||
"channelId": 2,
|
||||
"default": 31,
|
||||
"gears": [ "E63yG", "F63yG" ]
|
||||
},
|
||||
{
|
||||
"channelId": 3,
|
||||
"default": 98,
|
||||
"gears": [ "NG" ]
|
||||
},
|
||||
{
|
||||
"channelId": 4,
|
||||
"default": 97,
|
||||
"gears": [ "拦截" ]
|
||||
},
|
||||
{
|
||||
"channelId": 5,
|
||||
"default": 97,
|
||||
"gears": [ "拦截" ]
|
||||
},
|
||||
{
|
||||
"channelId": 6,
|
||||
"default": 97,
|
||||
"gears": [ "拦截" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -417,6 +417,9 @@
|
||||
<None Include="Assts\Fonts\Zen圓体-Regular.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Config\Channel.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Config\Configure.ini">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
Reference in New Issue
Block a user