private static void AppendPouSource(ArrayList alPouSources, ViHardwareType hardwareType, string sourceFile, Func <string, ViPouSource> factory) { sourceFile = GetPouSrcFileName(hardwareType, sourceFile); if (string.IsNullOrEmpty(sourceFile)) { return; } // 自动创建 PouSource 字典对象 if (_pouSources == null) { _pouSources = new Dictionary <string, ViPouSource>(); } // 可能会在 UI/Build 线程中调用,因此互斥访问 lock (_pouSources) { // 先在字典中查找,如果找不到,则自动创建 string sourceKey = (hardwareType.HardwareName + ':' + sourceFile).ToUpper(); if (_pouSources.ContainsKey(sourceKey)) { alPouSources.Add(_pouSources[sourceKey]); } else { ViPouSource pouSource = factory(sourceFile); if (pouSource != null) { _pouSources[sourceKey] = pouSource; alPouSources.Add(pouSource); } } } }
private static string GetPouSrcFileName(ViHardwareType hardwareType, string sourceFile) { if (FileName.GetFilePathType(sourceFile) != FileName.FilePathType.Absolute) { string newFile = FileName.GetAbsoluteFileName(hardwareType.DetailPathName, sourceFile); if (!File.Exists(newFile)) { newFile = FileName.GetAbsoluteFileName(ProjODKPath + @"System\", sourceFile); } // sourceFile = newFile; } if (!File.Exists(sourceFile)) { return(null); } return(sourceFile); }
/// <summary> /// 得到指定硬件类型的公共 PouSource 列表。 /// </summary> /// <param name="_hardwareType">硬件类型名称</param> /// <returns>公共 PouSource 列表</returns> public static ArrayList GetPouSources(string _hardwareType) { ViHardwareType hardwareType = GetHardwareType(_hardwareType); if (hardwareType == null) { return(null); } ArrayList alPouSources = new ArrayList(); AppendPouSource(alPouSources, hardwareType, "GLOBWRAP.INC", (sourceFile) => new ViIncPouSource(sourceFile, hardwareType.IniFileName, ViPouAttributes.LDWrapper | ViPouAttributes.Protected)); AppendPouSource(alPouSources, hardwareType, "GLOBPROT.INC", (sourceFile) => new ViIncPouSource(sourceFile, hardwareType.IniFileName, ViPouAttributes.Manufacturer | ViPouAttributes.Public)); AppendPouSource(alPouSources, hardwareType, ProjODKPath + (ShowLadder ? "IEC_STANDARD_FUN_CFCFBD.INC" : "IEC_STANDARD_FUN_CFCFBD_BL.INC"), (sourceFile) => new ViIncPouSource(sourceFile, hardwareType.IniFileName, ViPouAttributes.CFCFBDStandardFuns | ViPouAttributes.Public)); return(alPouSources); }