You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.1 KiB
C#

using Admin.Core.Common;
using Aucma.Core.RunPlc;
using log4net;
using Microsoft.AspNetCore.Builder;
using System;
1 year ago
using System.Text;
using System.Threading.Tasks;
namespace Admin.Core.Extensions
{
/// <summary>
///PLC
/// </summary>
public static class PlcMildd
{
private static readonly ILog log = LogManager.GetLogger(typeof(PlcMildd));
public static async void UsePlcMildd(this IApplicationBuilder app, IRunPlcService plc)
{
if (app == null) throw new ArgumentNullException(nameof(app));
try
{
if (Appsettings.app("Middleware", "Plc", "Enabled").ObjToBool())
{
1 year ago
//计算程序运行时间
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
StringBuilder sb = new StringBuilder();
stopwatch.Start(); // 开始监视代码
///////////////////////////////////////操作代码/////////////////////////////////////////////////////
await plc.StartMelsecMcSeverAsync();
await plc.StartSiemensSever();
await plc.StartMelsecPlcAsync();
await plc.StartSiemensPlcAsync();
////////////////////////////////////////////////////////////////////////////////////////////////////
stopwatch.Stop(); // 停止监视
TimeSpan timeSpan = stopwatch.Elapsed; // 获取总时间
double hours = timeSpan.TotalHours; // 小时
double minutes = timeSpan.TotalMinutes; // 分钟
double seconds = timeSpan.TotalSeconds; // 秒数
double milliseconds = timeSpan.TotalMilliseconds; // 毫秒数
Console.WriteLine($"秒数:{seconds},毫秒数:{milliseconds}");
}
}
catch (Exception e)
{
log.Error($"An error was reported when starting the job service.\n{e.Message}");
throw;
}
}
}
}