Control Architect provides custom API methods to facilitate Control Conversion tasks. The API methods can be used within a Control Binding C# generated script to facilitate common data retrieval and manipulation requirements.
LookUp API Method
This API Method allows users to search for data in another Worksheet in the same Excel Workbook being processed or in an external Excel Workbook file.
Prior to the development of this API method, users were entirely limited to using data within the Excel Worksheet that was currently being processed for conversion. Users often had to resort to using VLookup Excel functions to copy data from other Worksheets to the Worksheet with the primary data, which added time and complexity for the engineering task. This new LookUp(...) method eliminates this entirely.
This method is located in the Namespace: ControlConversion.Support.Core.Conversion
LookUp(string excelFileName, string excelWorksheetName, string excelColumnName, string primaryKeyLookupValue, string lookupColumnName)
Name
|
Description
|
excelFileName
|
The name of the Excel Workbook file that contains the data value to find.
|
excelWorksheetName
|
The name of the Excel Worksheet within the Workbook file that contains the data value to find.
|
excelColumnName
|
The name of the Worksheet Column that contains the lookup key to search for.
|
primaryKeyLookupValue
|
The value to search for in the lookup key.
|
lookupColumnName
|
The name of the Worksheet column in the looked up data row to return its value from.
|
Usage Examples
This example below shows how to use the LookUp(...) method together with the use of user defined Custom variables. One of the LookUp methods below is referencing data from an Excel Workbook file as shown below.
This method call is referencing a lookup value in the Workbook file below:
var rtu = ControlConversion.Support.Core.Conversion.LookUp($<C_CONVERT_RESOURCES_FILENAME>$, "Resources", "NAME", "DI_RTU", "VALUE");
The Custom Variable usage $<C_CONVERT_RESOURCES_FILENAME>$ is defined to contain the file path to this Excel Workbook file as defined in the referenced User Defined Variable file:
Note the use of Source_PVSOURCE.Substring(0, Source_PVSOURCE.IndexOf('.')) , which takes the current value of the bound Source property DISRC(1) and extracts the connection reference Entity name component for the Lookup value. For example DISCR(1) would contain an EntityName.Parameter value as in 3HA3000.PVFL where we need to extract the substring value 3HA3000 to lookup in the [DIINNIM] Worksheet and return the value in the column named PLCADDR.
This is the C# script that is generated when a Control Binding is established. We modified the default script code in the generated Property get accessor to return a value for the target Property name. The custom code starts with the comment line: // Custom code starts here and ends with the get accessor returning a value.
// Binded to Source Control Property Value [DISRC(1)]
public System.String Source_PVSOURCE;
// Converted Target Control Property
private System.String _PVSOURCE;
[PropertyBinderAttribute("DISRC(1)", "PVSOURCE")]
[PropertyRoundingAttribute("2", false)]
[PropertyDefaultValueAttribute("")]
[IsCMPropertyAttribute(false)]
public System.String PVSOURCE
{
get
{
// Custom code starts here
int plcAddress = 0;
if (string.IsNullOrWhiteSpace(Source_PVSOURCE) || Source_PVSOURCE.IndexOf('.') == -1)
return string.Empty;
var stringAddress = ControlConversion.Support.Core.Conversion.LookUp($<C_EXCEL_FILENAME>$, "DIINNIM", "NAME", Source_PVSOURCE.Substring(0, Source_PVSOURCE.IndexOf('.')), "PLCADDR");
int.TryParse(stringAddress, out plcAddress);
var rtu = ControlConversion.Support.Core.Conversion.LookUp($<C_CONVERT_RESOURCES_FILENAME>$, "Resources", "NAME", "DI_RTU", "VALUE");
return rtu + ' ' + '0' + (plcAddress - 10000) + " 0";
}
set
{
_PVSOURCE = value;
}
}
ExistsInColumn API Method
This API Method allows users to search and verify that a particular Column name exists in any Worksheet in the same Excel Workbook being processed or in an external Excel Workbook file.
Prior to the development of this API method, users were entirely limited to using data within the Excel Worksheet that was currently being processed for conversion.
This method is located in the Namespace: ControlConversion.Support.Core.Conversion
ExistsInColumn(string excelFileName, string excelWorksheetName, string searchColumnNameQuery)
Name
|
Description
|
excelFileName
|
The name of the Excel Workbook file that contains the data value to find.
|
excelWorksheetName
|
The name of the Excel Worksheet within the Workbook file that contains the data value to find.
|
searchColumnNameQuery
|
The query used to find the specified column name.
|
Usage Examples
This example below shows how to use the ExistsInColumn(...) method together with the use of user defined Custom variables. One of the ExistsInColumn methods below is referencing data from an Excel Workbook file as shown below. This function was developed to allow users to determine if for example a referenced Entity name in a connection reference may exist in another point type table.
In the LCN realm when working with xPM and other controller type data exported in Honeywell Exception Build (EB) files we often have references on a Regulatory Control point type such as "CODSTN(1) = 45FY123.OP", which is typically the Analog Output Channel point that drives the final element in the field. This output reference could be an Analog Output point or it could be the setpoint being pushed as in "CODSTN(1) = 45FC124.SP". When building Templates for a simple PID strategy it will typically contain an Analog Input channel block, a PID function block, and an Analog Output channel block. During processing we can determine if this PID function is driving a hardwired AO Channel block, by parsing the connection reference "45FY123.OP" to get "45FY123" and search for this entity reference name in the "ANOUTNIM" Excel point table. If not found, then we can assume we don't want this Analog Output channel block in this PID strategy as it is driving another block.parameter type. So we can return the value "BLOCK_DELETE" to notify the conversion process to remove this Analog Output channel block during processing.
Without the help of this function a user would have to provide this data manually embedded in the Worksheet point table that is being processed using various Excel function calls. Use of this function helps to minimize the amount of modification and pre-processing of the Excel data for use in a Control Conversion solution.
This method call is referencing a lookup value in the Workbook file below:
String source = _CODSTN_2_; // Reference Excel Source column name "CODSTN(2)" value.
if (String.IsNullOrEmpty(source)) // If the retrieved value is Null or Empty return "BLOCK_DELETE" to force deletion of the Block in the CM.
return "BLOCK_DELETE";
var source1 = source.Substring(0, source.IndexOf(".")); Retrieve a BlockName value and extract the Entity name from the Entity.Block reference.
var result = ControlConversion.Support.Core.Conversion.ExistsInColumn($<C_EXCEL_FILENAME>$, "ANOUTNIM", "NAME='" + source1 + "'");
return result.Item1? "" : "BLOCK_DELETE";
This string component in the function call above "NAME=' " + source1 + " ' " is the format for specifying a query when concatenating string values.
If source1 has the value of 54FY123 then the query becomes "NAME='54FY123'" where NAME is the name of the Excel worksheet (table) column to search for an Entity name reference in.
The return value is a Tuple<bool, string> type where item1 (bool) returns True if the specified column name exists, otherwise False; Item2 (string) returns an error string if item1 returns False.
The Custom Variable usage $<C_EXCEL_FILENAME>$ is defined to contain the file path to this Excel Workbook file as defined in the referenced User Defined Variable file:
This is the C# script that is generated when a Control Binding is established. We modified the default script code in the generated Property get accessor to return a value for the target Property name. The custom code starts with the comment line: // Custom code starts here and ends with the get accessor returning a value.
// Binded to Source Control Property Value [<Constant>]
public System.String Source_AOCHANNELB_Block;
// Converted Target Control Property
private System.String _AOCHANNELB_Block;
[PropertyBinderAttribute("<Constant>", "AOCHANNELB.Block")]
[PropertyRoundingAttribute("2", false)]
[PropertyDefaultValueAttribute("")]
[IsCMPropertyAttribute(false)]
public System.String AOCHANNELB_Block
{
get
{
// Custom code starts here
String source = _CODSTN_2_;
if (String.IsNullOrEmpty(source))
return "BLOCK_DELETE";
var source1 = source.Substring(0, source.IndexOf("."));
var result = ControlConversion.Support.Core.Conversion.ExistsInColumn($<C_EXCEL_FILENAME>$, "ANOUTNIM", "NAME='" + source1 + "'");
return result.Item1? "" : "BLOCK_DELETE";
}
set
{
_AOCHANNELB_Block = value;
}
}