Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 175 additions & 175 deletions src/S7CommPlusDriver/Alarming/AlarmsHandler.cs

Large diffs are not rendered by default.

74 changes: 71 additions & 3 deletions src/S7CommPlusDriver/Alarming/BrowseAlarms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,74 @@ private void GetTexts(byte[] tloa_1, byte[] tloa_2, byte[] tloa_3, byte[] tlsa,
}
}
}

/// <summary>
/// Reads the active program alarms from the Plc (single poll).
///
/// Call example:
/// CultureInfo ci = new CultureInfo("de-DE");
/// var alarmList = new List<AlarmsDai>();
/// conn.GetActiveAlarms(out alarmList, ci.LCID);
/// foreach (var a in alarmList)
/// {
/// Console.WriteLine(a.ToString());
/// }
/// </summary>
/// <param name="alarmList">Contains the alarms, empty if there is no active alarm</param>
/// <param name="languageId">Language id for retrieving the text entries, use language code e.g. 1031 for german</param>
/// <returns>0 on success</returns>
public int GetActiveAlarms(out List<AlarmsDai> alarmList, int languageId)
{
int res;

alarmList = new List<AlarmsDai>();

var exploreReq = new ExploreRequest(ProtocolVersion.V2);
exploreReq.ExploreId = Ids.NativeObjects_theAlarmSubsystem_Rid;
exploreReq.ExploreRequestId = Ids.AlarmSubsystem_itsUpdateRelevantDAI;
exploreReq.ExploreChildsRecursive = 1;
exploreReq.ExploreParents = 0;

// Add the requestes attributes.
// Request the same attributes we get from an alarm notification, so we can reuse other methods.
exploreReq.AddressList.Add(Ids.DAI_CPUAlarmID);
exploreReq.AddressList.Add(Ids.DAI_AllStatesInfo);
exploreReq.AddressList.Add(Ids.DAI_AlarmDomain);
exploreReq.AddressList.Add(Ids.DAI_Coming);
exploreReq.AddressList.Add(Ids.DAI_Going);
exploreReq.AddressList.Add(Ids.DAI_MessageType);
exploreReq.AddressList.Add(Ids.DAI_HmiInfo);
// Extra ones which we only need for compatibility with notification.
exploreReq.AddressList.Add(Ids.ObjectVariableTypeName);
exploreReq.AddressList.Add(Ids.DAI_SequenceCounter);
exploreReq.AddressList.Add(Ids.DAI_AlarmTexts_Rid);

res = SendS7plusFunctionObject(exploreReq);
if (res != 0)
{
return res;
}
m_LastError = 0;
WaitForNewS7plusReceived(m_ReadTimeout);
if (m_LastError != 0)
{
return m_LastError;
}

var exploreRes = ExploreResponse.DeserializeFromPdu(m_ReceivedPDU, true);
res = checkResponseWithIntegrity(exploreReq, exploreRes);
if (res != 0)
{
return res;
}

foreach (var obj in exploreRes.Objects)
{
alarmList.Add(AlarmsDai.FromNotificationObject(obj, languageId));
}

return 0;
}
}

public class AlarmData
Expand All @@ -345,10 +413,10 @@ public ulong GetCpuAlarmId()
{
return ((ulong)(RelationId) << 32) | ((ulong)(MultipleStai.Alid) << 16);
}

public uint RelationId;

public AlarmsMultipleStai MultipleStai;
public AlarmsMultipleStai MultipleStai;
public AlarmsAlarmTexts AlText = new AlarmsAlarmTexts();

public int Deserialize(Stream buffer)
Expand All @@ -364,7 +432,7 @@ public override string ToString()
string s = "";
s += "<AlarmData>" + Environment.NewLine;
s += "<CpuAlarmId>" + GetCpuAlarmId().ToString() + "</CpuAlarmId>" + Environment.NewLine;
s += "<RelationId>" + RelationId.ToString() + Environment.NewLine +"</RelationId>" + Environment.NewLine;
s += "<RelationId>" + RelationId.ToString() + Environment.NewLine + "</RelationId>" + Environment.NewLine;
s += "<MultipleStai>" + Environment.NewLine + MultipleStai.ToString() + "</MultipleStai>" + Environment.NewLine;
s += "<AlText>" + Environment.NewLine;
s += "<Infotext>" + AlText.Infotext + "</Infotext>" + Environment.NewLine;
Expand Down
Loading