dev
liuwf 1 year ago
parent f53c8d83fc
commit 3e5fc00241

@ -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;
/// <summary>
@ -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());
}
///// <summary>
///// 采集数据
///// </summary>
//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;

@ -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
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
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);
}

@ -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
}

Loading…
Cancel
Save