diff --git a/Admin.Core.Tasks/QuartzNet/Jobs/Job_Perfusion_Quartz.cs b/Admin.Core.Tasks/QuartzNet/Jobs/Job_Perfusion_Quartz.cs index e8b1662d..80b4021c 100644 --- a/Admin.Core.Tasks/QuartzNet/Jobs/Job_Perfusion_Quartz.cs +++ b/Admin.Core.Tasks/QuartzNet/Jobs/Job_Perfusion_Quartz.cs @@ -1,13 +1,14 @@ using Admin.Core.IService; using Admin.Core.IService.ISys; using Admin.Core.Model; -using Aucma.Core.PLc; +using Aucma.Core.HwPLc; using log4net; using NetTaste; using NPOI.SS.Formula.Functions; using Quartz; using System; using System.Linq; +using System.Text; using System.Threading.Tasks; /// @@ -22,7 +23,7 @@ namespace Admin.Core.Tasks protected readonly IPerfusionDeviceStatusServices _perfusionDeviceStatusServices; protected readonly IPerfusionAlarmServices _perfusionAlarmServices; protected readonly IPerfusionRecordServices _perfusionRecordServices; - + private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); public Job_Perfusion_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService, IPerfusionDeviceStatusServices perfusionDeviceStatusServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionRecordServices perfusionRecordServices) @@ -35,10 +36,29 @@ namespace Admin.Core.Tasks } public async Task Execute(IJobExecutionContext context) { - await ExecuteJob(context, async () => await SaveDbRun()); - await ExecuteJob(context, async () => await DeviceStatusRun()); + await ExecuteJob(context, async () => await SaveDbRun()); + // await ExecuteJob(context, async () => await DeviceStatusRun()); + // await ExecuteJob(context, async () => await collect()); } + + ///// + ///// 采集数据 + ///// + //public async Task collect() + //{ + // var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc")); + // if (obj != null && obj.plc.IsConnected) + // { + // byte[] result = obj.plc.Read("DB55.0", 84); + // if (result == null) return; + // string str1 = asciiEncoding.GetString(result.Skip(20).Take(24).ToArray()).Trim('\n'); + // Console.WriteLine(str1); + // } + + //} + + #region 检测设备状态 private async Task DeviceStatusRun() { @@ -62,7 +82,7 @@ namespace Admin.Core.Tasks public async Task SaveDbRun() { string alarmName = string.Empty; - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc")); + var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc")); if (obj.plc.IsConnected) { var endSignal = obj.plc.ReadInt16("DB55.44.0");//任务结束信号存盘 @@ -74,7 +94,11 @@ namespace Admin.Core.Tasks { try { - var barCode = obj.plc.ReadString("DB55.20.0");//箱体条码 + byte[] resultCode = obj.plc.Read("DB55.20", 24); + if (resultCode == null) return; + var barCode = asciiEncoding.GetString(resultCode.Skip(0).Take(24).ToArray()).Trim('\n'); + + // var barCode = obj.plc.ReadString("DB55.20.0");//箱体条码 var perfusionRecord = await _perfusionRecordServices.FirstAsync(d=>d.PerfusionBoxCode.Equals(barCode)); if (perfusionRecord == null) return; diff --git a/Aucam.Core.PerfusionService/Startup.cs b/Aucam.Core.PerfusionService/Startup.cs index 1854a96c..b37520a4 100644 --- a/Aucam.Core.PerfusionService/Startup.cs +++ b/Aucam.Core.PerfusionService/Startup.cs @@ -2,6 +2,7 @@ using Admin.Core.Common; using Admin.Core.Extensions; using Admin.Core.IService.ISys; using Admin.Core.Tasks; +using Aucma.Core.RunPlc; using Autofac; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -57,7 +58,8 @@ namespace Aucam.Core.PerfusionService // services.AddJobSetup(); - + //PLC + services.AddPlcSetup(); //ֱ֧ȫ :֧ System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030") Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); } @@ -78,7 +80,7 @@ namespace Aucam.Core.PerfusionService /// /// /// - public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter) + public void Configure(IApplicationBuilder app, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter, IRunPlcService runPlcService) { // ʹþ̬ļ app.UseStaticFiles(); @@ -86,6 +88,8 @@ namespace Aucam.Core.PerfusionService //app.UseAuthorization(); // QuartzNetJobȷ app.UseQuartzJobMildd(tasksQzService, schedulerCenter); + //PLC + app.UsePlcMildd(runPlcService); } diff --git a/Aucam.Core.PerfusionService/appsettings.json b/Aucam.Core.PerfusionService/appsettings.json index 4e7b2cd7..0e5f75ed 100644 --- a/Aucam.Core.PerfusionService/appsettings.json +++ b/Aucam.Core.PerfusionService/appsettings.json @@ -99,7 +99,7 @@ "ID": 1, "Name": "PerfusionTask", "JobGroup": "DEFAULT", - "Cron": "*/1 * * * * ?", + "Cron": "*/30 * * * * ?", "AssemblyName": "Admin.Core.Tasks", "ClassName": "Job_Perfusion_Quartz", "Remark": "执行灌注设备数据采集程序", @@ -161,6 +161,9 @@ "SubscriptionClientName": "Admin.Core" }, "Middleware": { + "Plc": { + "Enabled": true + }, "QuartzNetJob": { "Enabled": true @@ -170,6 +173,8 @@ { "Id": 1, "EquipName": "PerfusionPlc", + "PlcType": "Siemens", + "Enabled": true, "IP": "127.0.0.1", "Port": 102 }