Skip to content

Commit 406228e

Browse files
authored
Merge branch 'thomas-v2:master' into master
2 parents d55d2f6 + 51f1fd9 commit 406228e

File tree

4 files changed

+61
-44
lines changed

4 files changed

+61
-44
lines changed

src/S7CommPlusDriver/Alarming/AlarmsAlarmTexts.cs

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace S7CommPlusDriver.Alarming
2020
{
2121
public class AlarmsAlarmTexts
2222
{
23+
public int LanguageId;
2324
public string Infotext = String.Empty;
2425
public string AlarmText = String.Empty;
2526
public string AdditionalText1 = String.Empty;
@@ -31,65 +32,74 @@ public class AlarmsAlarmTexts
3132
public string AdditionalText7 = String.Empty;
3233
public string AdditionalText8 = String.Empty;
3334
public string AdditionalText9 = String.Empty;
34-
35+
3536
// These two values we get in addition when browsing for the alarmtexts
3637
// Don't know if they are useful for something.
3738
public ushort UnknownValue1;
3839
public ushort UnknownValue2;
3940

40-
public static AlarmsAlarmTexts FromNotificationBlob(ValueBlobSparseArray blob)
41+
public static AlarmsAlarmTexts FromNotificationBlob(ValueBlobSparseArray blob, int languageId)
4142
{
4243
var at = new AlarmsAlarmTexts();
4344
string s;
45+
int lcid;
46+
int textid;
47+
at.LanguageId = languageId;
4448
foreach (var v in blob.Value)
4549
{
4650
s = Utils.GetUtfString(v.Value.value, 0, (uint)v.Value.value.Length);
4751
// Values in older CPUs, from: 0xa09c8001..0xa09c800b (2694610945..2694610955)
4852
// Current CPUs use: 0x04070001..0x0407000b ( 67567617.. 67567627)
49-
// Did they change the key-values? Or depending on CPU?
50-
switch (v.Key)
53+
// Where the left word is the language ID, 0x0407 = 1031, and the right word is the text id.
54+
// The blob may contain several languages. If you need them all, you need to call this multiple times.
55+
lcid = (int)(v.Key >> 16);
56+
textid = (int)(v.Key & 0xffff);
57+
if (lcid == languageId)
5158
{
52-
case 67567617:
53-
at.Infotext = s;
54-
break;
55-
case 67567618:
56-
at.AlarmText = s;
57-
break;
58-
case 67567619:
59-
at.AdditionalText1 = s;
60-
break;
61-
case 67567620:
62-
at.AdditionalText2 = s;
63-
break;
64-
case 67567621:
65-
at.AdditionalText3 = s;
66-
break;
67-
case 67567622:
68-
at.AdditionalText4 = s;
69-
break;
70-
case 67567623:
71-
at.AdditionalText5 = s;
72-
break;
73-
case 67567624:
74-
at.AdditionalText6 = s;
75-
break;
76-
case 67567625:
77-
at.AdditionalText7 = s;
78-
break;
79-
case 67567626:
80-
at.AdditionalText8 = s;
81-
break;
82-
case 67567627:
83-
at.AdditionalText9 = s;
84-
break;
59+
switch (textid)
60+
{
61+
case 1:
62+
at.Infotext = s;
63+
break;
64+
case 2:
65+
at.AlarmText = s;
66+
break;
67+
case 3:
68+
at.AdditionalText1 = s;
69+
break;
70+
case 4:
71+
at.AdditionalText2 = s;
72+
break;
73+
case 5:
74+
at.AdditionalText3 = s;
75+
break;
76+
case 6:
77+
at.AdditionalText4 = s;
78+
break;
79+
case 7:
80+
at.AdditionalText5 = s;
81+
break;
82+
case 8:
83+
at.AdditionalText6 = s;
84+
break;
85+
case 9:
86+
at.AdditionalText7 = s;
87+
break;
88+
case 10:
89+
at.AdditionalText8 = s;
90+
break;
91+
case 11:
92+
at.AdditionalText9 = s;
93+
break;
94+
}
8595
}
8696
}
8797
return at;
8898
}
8999

90100
public override string ToString()
91101
{
92-
string s = "<AlarmsAlarmTexts>" + Environment.NewLine;
102+
string s = "<AlarmsAlarmTexts LanguageId=\"" + LanguageId.ToString() + "\">" + Environment.NewLine;
93103
s += "<Infotext>" + Infotext.ToString() + "</Infotext>" + Environment.NewLine;
94104
s += "<AlarmText>" + AlarmText.ToString() + "</AlarmText>" + Environment.NewLine;
95105
s += "<AdditionalText1>" + AdditionalText1.ToString() + "</AdditionalText1>" + Environment.NewLine;

src/S7CommPlusDriver/Alarming/AlarmsDai.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override string ToString()
5353
return s;
5454
}
5555

56-
public static AlarmsDai FromNotificationObject(PObject pobj)
56+
public static AlarmsDai FromNotificationObject(PObject pobj, int alarmtextsLanguageId)
5757
{
5858
var dai = new AlarmsDai();
5959
dai.ObjectVariableTypeName = ((ValueWString)pobj.GetAttribute(Ids.ObjectVariableTypeName)).GetValue();
@@ -82,7 +82,7 @@ public static AlarmsDai FromNotificationObject(PObject pobj)
8282
}
8383
dai.AsCgs = AlarmsAsCgs.FromValueStruct(str);
8484
dai.AsCgs.SubtypeId = dai_id;
85-
dai.AlarmTexts = AlarmsAlarmTexts.FromNotificationBlob(((ValueBlobSparseArray)pobj.GetAttribute(Ids.DAI_AlarmTexts_Rid)));
85+
dai.AlarmTexts = AlarmsAlarmTexts.FromNotificationBlob(((ValueBlobSparseArray)pobj.GetAttribute(Ids.DAI_AlarmTexts_Rid)), alarmtextsLanguageId);
8686
return dai;
8787
}
8888
}

src/S7CommPlusDriver/Alarming/AlarmsHandler.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public partial class S7CommPlusConnection
2626
// * how to use it, and how to later integrate *
2727
// * this into the complete library! *
2828
// *************************************************
29+
//
30+
// Example code for testing:
31+
// CultureInfo ci = new CultureInfo("en-US");
32+
// conn.AlarmSubscriptionCreate();
33+
// conn.TestWaitForAlarmNotifications(20000, 3, ci.LCID);
34+
// conn.AlarmSubscriptionDelete();
2935

3036
uint m_AlarmSubscriptionRelationId = 0x7fffc001; // TODO! Unknown value! See also Subscription.cs
3137
uint m_AlarmSubscriptionRefRelationId = 0x51010001; // TODO! Unknown value!
@@ -116,7 +122,7 @@ public int AlarmSubscriptionCreate()
116122
return res;
117123
}
118124

119-
public int TestWaitForAlarmNotifications(int waitTimeout, int untilNumberOfAlarms)
125+
public int TestWaitForAlarmNotifications(int waitTimeout, int untilNumberOfAlarms, int alarmTextsLanguageId)
120126
{
121127
int res = 0;
122128
short creditLimitStep = 5;
@@ -142,7 +148,7 @@ public int TestWaitForAlarmNotifications(int waitTimeout, int untilNumberOfAlarm
142148
Console.Write("Notification: CreditTick=" + noti.NotificationCreditTick + " SequenceNumber=" + noti.NotificationSequenceNumber);
143149
Console.WriteLine(String.Format(" PLC-Timestamp={0}.{1:D03}", noti.Add1Timestamp.ToString(), noti.Add1Timestamp.Millisecond));
144150

145-
var dai = AlarmsDai.FromNotificationObject(noti.P2Objects[0]);
151+
var dai = AlarmsDai.FromNotificationObject(noti.P2Objects[0], alarmTextsLanguageId);
146152
Console.WriteLine(dai.ToString());
147153
if (noti.NotificationCreditTick >= m_AlarmNextCreditLimit - 1) // Set new limit one tick before it expires, to get a constant flow of data
148154
{

src/S7CommPlusDriver/Alarming/BrowseAlarms.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ public int ExploreASAlarms(ref Dictionary<ulong, AlarmData> Alarms, int language
213213
var tloa_2 = tloa[1].GetValue();
214214
var tloa_3 = tloa[2].GetValue();
215215

216-
GetTexts(tloa_1, tloa_2, tloa_3, tlsa, ref Alarms);
216+
GetTexts(tloa_1, tloa_2, tloa_3, tlsa, ref Alarms, languageId);
217217

218218
#endregion
219219

220220
return 0;
221221
}
222222

223-
private void GetTexts(byte[] tloa_1, byte[] tloa_2, byte[] tloa_3, byte[] tlsa, ref Dictionary<ulong, AlarmData> Alarms)
223+
private void GetTexts(byte[] tloa_1, byte[] tloa_2, byte[] tloa_3, byte[] tlsa, ref Dictionary<ulong, AlarmData> Alarms, int languageId)
224224
{
225225
uint pos1, pos2, pos3;
226226
uint t1_count, t1_relid, t1_relid_off;
@@ -266,6 +266,7 @@ private void GetTexts(byte[] tloa_1, byte[] tloa_2, byte[] tloa_3, byte[] tlsa,
266266
Trace.WriteLine(String.Format("BrowseAlarms GetTexts(): CPU Alarm Id {0:X} is not in dictionary!", cpualarmid));
267267
continue;
268268
}
269+
Alarms[cpualarmid].AlText.LanguageId = languageId;
269270

270271
// Step 3: Get offsets to text array from table 3
271272
pos3 = t2_off;

0 commit comments

Comments
 (0)