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.
109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
using Aucma.Core.Scanner;
|
|
using Aucma.Scada.HikRobot;
|
|
using HighWayIot.Config;
|
|
using HighWayIot.Log4net;
|
|
using HighWayIot.Plc;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Aucma.Scada.Business
|
|
{
|
|
public sealed class MainBusiness
|
|
{
|
|
#region 单例实现
|
|
private static readonly Lazy<MainBusiness> lazy = new Lazy<MainBusiness>(() => new MainBusiness());
|
|
private LogHelper logHelper = LogHelper.Instance;
|
|
|
|
public static MainBusiness Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 对象引用
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
|
|
private PlcConfig plcConfig = PlcConfig.Instance;
|
|
|
|
private PlcSpaceConfig spaceConfig = PlcSpaceConfig.Instance;
|
|
|
|
private PlcPool plcPool = PlcPool.Instance;
|
|
|
|
|
|
#endregion
|
|
|
|
private MainBusiness()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化PLC
|
|
/// </summary>
|
|
public async void InitPlc()
|
|
{
|
|
//初始化Plc
|
|
plcPool.InitPlc("MelsecBinaryPlc", plcConfig.shell_Plc_Ip, plcConfig.shell_Plc_Port, appConfig.shellStoreCode);
|
|
plcPool.InitPlc("MelsecBinaryPlc", plcConfig.liner_Plc_Ip, plcConfig.liner_Plc_Port, appConfig.linerStoreCode);
|
|
// 心跳
|
|
await plcPool.StartMelsecPlcAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭PLC
|
|
/// </summary>
|
|
public void DisConnectPlc()
|
|
{
|
|
plcPool.disConnectAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启海康扫码器
|
|
/// </summary>
|
|
public void InitHikRobot()
|
|
{
|
|
try
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(2000);
|
|
|
|
MvCodeHelper.Shell();
|
|
});
|
|
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(4000);
|
|
|
|
MvCodeHelper.Liner();
|
|
});
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
logHelper.Error("InitHikRobotAndGun()开启海康扫码器和扫码枪方法异常" + ex.Message.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭海康扫码器
|
|
/// </summary>
|
|
public void ExitHikRobot()
|
|
{
|
|
try
|
|
{
|
|
//MvCodeHelper.CloseAllDevice();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|