|
|
|
@ -11,32 +11,34 @@ namespace Aucma.Core.RunPlc
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RunPlcService : IRunPlcService
|
|
|
|
|
{
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(3000);//创建定时器,设置间隔时间为1000毫秒;
|
|
|
|
|
System.Timers.Timer timer1 = new System.Timers.Timer(3000);
|
|
|
|
|
#region 构造函数
|
|
|
|
|
public RunPlcService()
|
|
|
|
|
{
|
|
|
|
|
StartMelsecMcPlcServer();
|
|
|
|
|
StartSiemensPlcServer();
|
|
|
|
|
//StartMelsecMcPlcServer();
|
|
|
|
|
//StartSiemensPlcServer();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 心跳
|
|
|
|
|
public Task StartPlcAsync()
|
|
|
|
|
public async Task StartMelsecPlcAsync()
|
|
|
|
|
{
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(3000);
|
|
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecMelsecMcHeartTask); //到达时间的时候执行事件;
|
|
|
|
|
timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
|
|
|
|
|
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它,
|
|
|
|
|
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
|
|
|
|
|
|
|
|
|
|
timer1.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask);
|
|
|
|
|
timer1.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
|
|
|
|
|
timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它,
|
|
|
|
|
timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
public async Task StartSiemensPlcAsync()
|
|
|
|
|
{
|
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer(3000);//创建定时器,设置间隔时间为1000毫秒
|
|
|
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask);
|
|
|
|
|
timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
|
|
|
|
|
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它,
|
|
|
|
|
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void StartMelsecMcPlcServer()
|
|
|
|
|
{
|
|
|
|
|
var allPlcServices = Appsettings.app<PlcModel>("PLCServer").ToList();
|
|
|
|
@ -87,8 +89,8 @@ namespace Aucma.Core.RunPlc
|
|
|
|
|
{
|
|
|
|
|
var item = PlcHelper.melsecList.Where(c => c.Id == i).FirstOrDefault();
|
|
|
|
|
if (item == null) continue;
|
|
|
|
|
|
|
|
|
|
if (item.plc.Read("D6050").Result)
|
|
|
|
|
var test = item.plc.ReadInt16("D6050");
|
|
|
|
|
if (item.plc.Read("M100").Result)
|
|
|
|
|
{
|
|
|
|
|
item.IsConnect = true;
|
|
|
|
|
item.plc.IsConnected = true;
|
|
|
|
|