48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
|
|
using PlcTool.Siemens;
|
|||
|
|
using WcsMain.Common;
|
|||
|
|
using WcsMain.DataBase.Dao;
|
|||
|
|
using WcsMain.DataBase.TableEntity;
|
|||
|
|
using WcsMain.WcsAttribute.AutoFacAttribute;
|
|||
|
|
|
|||
|
|
namespace WcsMain.PlcOperation;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 连接PLC
|
|||
|
|
/// </summary>
|
|||
|
|
[Component]
|
|||
|
|
public class ConnectPLCs(AppPLCDao pLCDao, AppDBDao dBDao)
|
|||
|
|
{
|
|||
|
|
private readonly AppPLCDao _plcDao = pLCDao;
|
|||
|
|
private readonly AppDBDao _dbDao = dBDao;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 连接PLC
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns>返回值表示是否继续检测PLC连接状态</returns>
|
|||
|
|
public bool ConnectPlc()
|
|||
|
|
{
|
|||
|
|
/* 查询所有PLC */
|
|||
|
|
List<AppPLC>? plcs = _plcDao.GetDataWithStatus(1);
|
|||
|
|
if (plcs == default || plcs.Count == 0)
|
|||
|
|
{
|
|||
|
|
ConsoleLog.Tip("$[异常]PLC 数据查找失败,请检查网络是否正常或者是否录入PLC数据");
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
List<AppDB>? dbs = _dbDao.Select();
|
|||
|
|
CommonTool.Siemens = new SiemensS7();
|
|||
|
|
CommonTool.Siemens.SetPlcs(plcs).SetPlcDB(dbs);
|
|||
|
|
var connectResult = CommonTool.Siemens.ConnectPlcs();
|
|||
|
|
if (connectResult.Success)
|
|||
|
|
{
|
|||
|
|
CommonData.IsConnectPlc = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
CommonData.IsConnectPlc = false;
|
|||
|
|
ConsoleLog.Error($"[异常]{connectResult.Message}");
|
|||
|
|
ConsoleLog.Error($"请检查设备网络后重新启动 WCS ");
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|