diff --git a/ConsoleApp/MainCentralControl.cs b/ConsoleApp/MainCentralControl.cs
index 7a3122c..120fe4e 100644
--- a/ConsoleApp/MainCentralControl.cs
+++ b/ConsoleApp/MainCentralControl.cs
@@ -38,7 +38,12 @@ namespace ConsoleApp
private string _workAskAddress;
//PLC工作完成放行请求地址
private string _completeAskAddress;
-
+ //PLC产品码地址
+ private string _productBarcode;
+ //PLC支线码1地址
+ private string _semiBarcode1;
+ //PLC支线码2地址
+ private string _semiBarcode2;
public MainCentralControl(IHost host)
{
@@ -68,11 +73,16 @@ namespace ConsoleApp
case "S130-1":
_plcHeartBeatAddress = "D7777";
_completeAskAddress = "D7703";
+ _productBarcode = "";
+ _semiBarcode1 = "D7701";
break;
case "S130-2":
_plcHeartBeatAddress = "D7777";
- _workAskAddress = "";
- _completeAskAddress = "";
+ _workAskAddress = "D7803";
+ _completeAskAddress = "D7804";
+ _productBarcode = "";
+ _semiBarcode1 = "D7801";
+ _semiBarcode2 = "D7802";
break;
}
}
@@ -117,12 +127,6 @@ namespace ConsoleApp
//根据转子码查询上工位是否合格
SelectStationQuality(Plc);
}
- //读取PLC放行请求
- if (Plc.readInt16ByAddress(_completeAskAddress) == 1)
- {
- Plc.writeInt16ByAddress(_completeAskAddress, 0);
- //存盘
- }
break;
}
@@ -138,6 +142,27 @@ namespace ConsoleApp
}
});
}
+ private void BarCodeRelationShipBinding(PlcAbsractFactory Plc)
+ {
+ try
+ {
+ //前盖码
+ byte[] _QGBarcode = Plc.readValueByAddress(_semiBarcode2, 20);
+ string QGBarCode = ByteTransform.TransString(_QGBarcode, 0, 20, Encoding.ASCII);
+ _logger.Info("前盖码:"+ QGBarCode);
+
+ //转子码
+ byte[] _ZZBarcode = Plc.readValueByAddress(_semiBarcode1, 20);
+ string ZZBarCode = ByteTransform.TransString(_ZZBarcode, 0, 20, Encoding.ASCII);
+ _logger.Info("转子码:" + QGBarCode);
+ //下发PLC
+ Plc.writeInt16ByAddress(_completeAskAddress, 1);
+ }
+ catch (Exception ex)
+ {
+ _logger.Error($"BarCodeRelationShipBinding方法异常:" + ex.StackTrace);
+ }
+ }
///
/// 判断数据库表是否已存在条码数据,存在则更新,不存在则插入
///
@@ -148,7 +173,6 @@ namespace ConsoleApp
Datastation datastation = null;
try
{
- SqlSugarClient.Queryable().Any(x => x.Partsns.Contains(ProductBarCode));
datastation = SqlSugarClient.Queryable().First(it => it.Partsns.Contains(ProductBarCode));
if (datastation != null)
{
@@ -169,7 +193,7 @@ namespace ConsoleApp
{
try
{ //主线码
- byte[] SemBarCode = Plc.readValueByAddress("D7701", 20);
+ byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
string barcode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
partsns partsns = new partsns();
partsns.sn.Add(barcode);
@@ -285,22 +309,46 @@ namespace ConsoleApp
{
try
{
- byte[] SemBarCode = Plc.readValueByAddress("D7701", 20);
+ byte[] SemBarCode = Plc.readValueByAddress(_semiBarcode1, 20);
string ZZBarCode = ByteTransform.TransString(SemBarCode, 0, 20, Encoding.ASCII);
+ _logger.Info("转子码:" + ZZBarCode);
Datastation datastation = IsExistData(ZZBarCode);
if (datastation != null)
{
if (datastation.Ng != 0)
{
+ _logger.Info("上工位不合格");
//下发PLC上工位不合格
- Plc.writeInt16ByAddress("", 1);
+ Plc.writeInt16ByAddress(_completeAskAddress, 2);
+ }
+ else
+ {
+ //存盘
+ //前盖码
+ byte[] _QGBarcode = Plc.readValueByAddress(_semiBarcode2, 20);
+ string QGBarCode = ByteTransform.TransString(_QGBarcode, 0, 20, Encoding.ASCII);
+ _logger.Info("前盖码:" + QGBarCode);
+ //根据前盖码查询Productid
+ SqlSugarClient.Queryable().Any(x => x.Sn == QGBarCode);
+ var Dipsn = SqlSugarClient.Queryable().First(it => it.Sn == QGBarCode);
+ if (Dipsn != null)
+ {
+
+ int id = SqlSugarClient.Insertable(datastation).ExecuteReturnIdentity();
+ }
+
+
+ //下发PLC上工位合格
+ Plc.writeInt16ByAddress(_completeAskAddress, 1);
+ //BarCodeRelationShipBinding(Plc);
}
}
//上工位无数据
else
{
+ _logger.Info("上工位不合格");
//下发PLC上工位不合格
- Plc.writeInt16ByAddress("", 1);
+ Plc.writeInt16ByAddress(_completeAskAddress, 2);
}
}
catch (Exception ex)
diff --git a/ConsoleApp/appsettings.json b/ConsoleApp/appsettings.json
index 1cc7369..21cd226 100644
--- a/ConsoleApp/appsettings.json
+++ b/ConsoleApp/appsettings.json
@@ -57,6 +57,6 @@
],
"redisConfig": "175.27.215.92:6379,password=redis@2023",
- "StationCode": "S130-1"
+ "StationCode": "S130-2"
}
}
diff --git a/SlnMesnac.Serilog/SerilogHelper.cs b/SlnMesnac.Serilog/SerilogHelper.cs
index b303d0f..eb09aa9 100644
--- a/SlnMesnac.Serilog/SerilogHelper.cs
+++ b/SlnMesnac.Serilog/SerilogHelper.cs
@@ -47,6 +47,7 @@ namespace SlnMesnac.Serilog
///
public void Info(string msg, [System.Runtime.CompilerServices.CallerFilePath] string callerFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int callerLineNumber = 0)
{
+ Console.WriteLine(msg);
var className = Path.GetFileNameWithoutExtension(callerFilePath);
Info_logger.ForContext("ClassName", className).ForContext("LineNumber", callerLineNumber).Information(msg);
}
diff --git a/SlnMesnac.iMES/Program.cs b/SlnMesnac.iMES/Program.cs
new file mode 100644
index 0000000..c4740b2
--- /dev/null
+++ b/SlnMesnac.iMES/Program.cs
@@ -0,0 +1,85 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using SlnMesnac.Config;
+using SlnMesnac.Quartz;
+using TouchSocket.Sockets;
+using SlnMesnac.Extensions;
+using Microsoft.AspNetCore.Hosting;
+using Serilog;
+using Autofac.Extensions.DependencyInjection;
+using SlnMesnac.Serilog;
+
+namespace ConsoleApp
+{
+ internal class Program
+ {
+ private static SerilogHelper? serilogHelper;
+ static void Main(string[] args)
+ {
+ try
+ {
+ Thread.CurrentThread.Name = "Main";
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler; //全局异常捕获
+ var host = CreateHostBuilder(args).Build();
+
+ var hostTask = host.RunAsync();
+ var appConfig = host.Services.GetService();
+ //var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
+ //Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}");
+ serilogHelper = host.Services.GetRequiredService();
+
+ MainCentralControl mainCentralControl = new MainCentralControl(host);
+ mainCentralControl.Start();
+
+ serilogHelper.Info("iMES系统启动成功");
+ while (true)
+ {
+ Console.ReadLine();
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ if (serilogHelper != null)
+ {
+ serilogHelper.Error("系统启动失败,异常:" + ex.Message);
+ }
+ }
+
+ }
+ private static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e)
+ {
+ //当前线程名称
+ Thread.CurrentThread.Name = "Error";
+ if (e.ExceptionObject is Exception exception)
+ {
+ Console.WriteLine("全局异常捕获:");
+ Console.WriteLine(exception.Message);
+ Console.WriteLine(exception.StackTrace);
+ if (serilogHelper != null)
+ {
+ serilogHelper.Error("全局异常捕获:" + exception.Message + "\n" + exception.StackTrace);
+ }
+ }
+ else
+ {
+ Console.WriteLine("未知异常捕获:");
+ Console.WriteLine(e.ExceptionObject);
+ if (serilogHelper != null)
+ {
+ serilogHelper.Error("未知异常捕获:" + e.ExceptionObject);
+ }
+ }
+ }
+ public static IHostBuilder CreateHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .UseSerilog()
+ .UseServiceProviderFactory(new AutofacServiceProviderFactory())
+ .ConfigureWebHostDefaults(webBuilder =>
+ {
+ webBuilder.UseStartup();
+ });
+ }
+}
diff --git a/SlnMesnac.iMES/SlnMesnac.iMES.csproj b/SlnMesnac.iMES/SlnMesnac.iMES.csproj
new file mode 100644
index 0000000..74abf5c
--- /dev/null
+++ b/SlnMesnac.iMES/SlnMesnac.iMES.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+