|
|
|
|
using Aucma.Core.Scanner;
|
|
|
|
|
using Aucma.Scada.HikRobot;
|
|
|
|
|
using HighWayIot.Config;
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
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 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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭PLC
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisConnectPlc()
|
|
|
|
|
{
|
|
|
|
|
plcPool.disConnectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开启海康扫码器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitHikRobot()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
MvCodeHelper.DeviceListAcq();//获取创建设备
|
|
|
|
|
MvCodeHelper.StartGrab(); // 开启触发扫码接收数据
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MvCodeHelper.CloseAllDevice();
|
|
|
|
|
InitHikRobot();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭海康扫码器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ExitHikRobot()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
MvCodeHelper.CloseAllDevice();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|