I'm trying to retrieve a Parameter's name using its ID and element data (From an alarmInfo string).
I don't see this in the Element class, so I assume it would be in the element.protocol object. Unfortunately the link to documentation about this is broken (See below), so I'm not sure how to (or if) I can accomplish this. I currently can access the "GetProtocolInfoResponseMessage" object of the desired Protocol, but not sure how to proceed.
For reference here are all the references I can find to GetProtocolInfoResponseMessage, which all appear to be broken links:
Element.Protocol: Property Protocol | DataMiner Docs
Dummy.Protocol: Property Protocol | DataMiner Docs
IActionableElement.Protocol: Property Protocol | DataMiner Docs
IConnection.GetProtocol(): Method GetProtocol | DataMiner Docs
Thanks!
Hi Nick,
If you already have access to the Element object, you can retrieve the parameter name as follows:
Element element;
int parameterId = 123;var protocol = element.Protocol;
var parameter = protocol.Parameters.FirstOrDefault(p => p.ID == parameterId);
var name = parameter.Name;
Actually, now that I’m testing the script it’s throwing this error:
error CS1061: ‘ParameterInfo[]’ does not contain a definition for ‘FirstOrDefault’ and no accessible extension method ‘FirstOrDefault’ accepting a first argument of type ‘ParameterInfo[]’ could be found (are you missing a using directive or an assembly reference?)
.
.
Here is my implementation:
string alarmInfo = engine.GetScriptParam(65006).Value;
string[] parts = alarmInfo.Split(‘|’);
…
dmaID = Tools.ToInt32(parts[1]);
elementID = Tools.ToInt32(parts[2]);
int parameterID = Tools.ToInt32(parts[3]);
…
Element elem = engine.FindElement(dmaID, elementID);
var protocol = elem.Protocol;
var param = protocol.Parameters.FirstOrDefault(p => p.ID == parameterID);
string parameterName = param.Name;
.
.
Any ideas what’s causing this?
Not sure why that method isn’t working, but this does work:
…
Element elem = engine.FindElement(DmaID, ElementID);
string parameterName = “”;
foreach (var param in elem.Protocol.Parameters)
{
if (param.ID == ParameterID)
{
parameterName = param.Name;
break;
}
}
The reason why you get that error is because a using statement for “System.Linq” is missing at the top of the file. After adding that you should be able to use the FirstOrDefault method. But good to see that you found an alternative that also works fine.
Hi Nick, in the meantime we have also fixed the references to GetProtocolInfoResponseMessage in the docs. Thanks for bringing that to our attention.
Thank you, exactly what I was looking for!