using CompressorXN_HelperLib;
using CompressorXN_Model.ViewModel.Plc;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace CompressorXN_Communication.MyPlc
{
public class LoadPlcAddress
{
///
/// 加载PLC配置文件
///
///
public static DeviceInfo LoadPlcConfigFile()
{
DeviceInfo deviceInfo = new DeviceInfo
{
CommGroupList = new List()
};
//获取PLC点位集合
var filePath = $"{Application.StartupPath}/MyPlc/FileConfig/PlcCommConfig.xlsx";
if (!File.Exists(filePath))
{
MessageBox.Show("PLC点位配置文件不存在!");
return null;
}
deviceInfo.CommGroupList = GetPointList(filePath, "通信组");
List variableList = GetPointList(filePath, "变量表");
foreach (var item in deviceInfo.CommGroupList)
{
item.VariableList = variableList.Where(m => m.GroupName == item.GroupName).ToList();
}
return deviceInfo;
}
///
/// 获取点位列表
///
///
///
///
///
static List GetPointList(string strFilePath, string tbName = "dt1") where T : new()
{
var dt = ExcelHelper.GetExcel(strFilePath, tbName);
return ExcelHelper.ConvertDataTableToList(dt);
}
}
}