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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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
{
/// <summary>
/// 加载PLC配置文件
/// </summary>
/// <returns></returns>
public static DeviceInfo LoadPlcConfigFile ( )
{
DeviceInfo deviceInfo = new DeviceInfo
{
CommGroupList = new List < CommGroup > ( )
} ;
//获取PLC点位集合
var filePath = $"{Application.StartupPath}/MyPlc/FileConfig/PlcCommConfig.xlsx" ;
if ( ! File . Exists ( filePath ) )
{
MessageBox . Show ( "PLC点位配置文件不存在! " ) ;
return null ;
}
deviceInfo . CommGroupList = GetPointList < CommGroup > ( filePath , "通信组" ) ;
List < Variable > variableList = GetPointList < Variable > ( filePath , "变量表" ) ;
foreach ( var item in deviceInfo . CommGroupList )
{
item . VariableList = variableList . Where ( m = > m . GroupName = = item . GroupName ) . ToList ( ) ;
}
return deviceInfo ;
}
/// <summary>
/// 获取点位列表
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="strFilePath"></param>
/// <param name="tbName"></param>
/// <returns></returns>
static List < T > GetPointList < T > ( string strFilePath , string tbName = "dt1" ) where T : new ( )
{
var dt = ExcelHelper . GetExcel ( strFilePath , tbName ) ;
return ExcelHelper . ConvertDataTableToList < T > ( dt ) ;
}
}
}