1313 /****************************************************************************/
1414#endregion
1515
16- using System ;
1716using S7CommPlusDriver . Alarming ;
17+ using System ;
18+ using System . Collections . Generic ;
1819
1920namespace S7CommPlusDriver
2021{
@@ -38,7 +39,7 @@ public partial class S7CommPlusConnection
3839 short m_AlarmNextCreditLimit ;
3940 uint m_AlarmSubscriptionObjectId ;
4041
41- public int AlarmSubscriptionCreate ( )
42+ public int AlarmSubscriptionCreate ( uint [ ] languageIds )
4243 {
4344 int res ;
4445 PObject subsobj = new PObject ( ) ;
@@ -72,7 +73,7 @@ public int AlarmSubscriptionCreate()
7273 asrefsobj . AddAttribute ( Ids . AlarmSubscriptionRef_AlarmDomain2 , new ValueUIntArray ( new ushort [ 1 ] { 65535 } , 0x20 ) ) ; // 0x20 = Adressarray
7374 // OPTION:
7475 // Send text informations with the message, we don't need to browse them in advance.
75- asrefsobj . AddAttribute ( Ids . AlarmSubscriptionRef_AlarmTextLanguages_Rid , new ValueUDIntArray ( new uint [ 0 ] , 0x20 ) ) ; // Empty for all languanges? Otherwise e.g. 1031 for de-de or what you need.
76+ asrefsobj . AddAttribute ( Ids . AlarmSubscriptionRef_AlarmTextLanguages_Rid , new ValueUDIntArray ( languageIds , 0x20 ) ) ; // Empty for all languanges? Otherwise e.g. 1031 for de-de or what you need.
7677 asrefsobj . AddAttribute ( Ids . AlarmSubscriptionRef_SendAlarmTexts_Rid , new ValueBool ( true ) ) ;
7778
7879 asrefsobj . AddRelation ( Ids . AlarmSubscriptionRef_itsAlarmSubsystem , 0x00000008 ) ;
@@ -122,44 +123,76 @@ public int AlarmSubscriptionCreate()
122123 return res ;
123124 }
124125
125- public int TestWaitForAlarmNotifications ( int waitTimeout , int untilNumberOfAlarms , int alarmTextsLanguageId )
126- {
127- int res = 0 ;
128- short creditLimitStep = 5 ;
126+ // public int TestWaitForAlarmNotifications(int waitTimeout, int untilNumberOfAlarms, int alarmTextsLanguageId, out List<Notification> notifications )
127+ // {
128+ // int res = 0;
129+ // short creditLimitStep = 5;
129130
130- for ( int i = 1 ; i <= untilNumberOfAlarms ; i ++ )
131- {
132- Console . WriteLine ( Environment . NewLine + "WaitForAlarmNotifications(): *** Loop #" + i . ToString ( ) + " ***" ) ;
133- m_LastError = 0 ;
134- WaitForNewS7plusReceived ( waitTimeout ) ;
135- if ( m_LastError != 0 )
136- {
137- return m_LastError ;
138- }
131+ // for (int i = 1; i <= untilNumberOfAlarms; i++)
132+ // {
133+ // Console.WriteLine(Environment.NewLine + "WaitForAlarmNotifications(): *** Loop #" + i.ToString() + " ***");
134+ // m_LastError = 0;
135+ // WaitForNewS7plusReceived(waitTimeout);
136+ // if (m_LastError != 0)
137+ // {
138+ // return m_LastError;
139+ // }
139140
140- var noti = Notification . DeserializeFromPdu ( m_ReceivedPDU ) ;
141- if ( noti == null )
142- {
143- Console . WriteLine ( "Notification == null!" ) ;
144- return S7Consts . errIsoInvalidPDU ;
145- }
146- else
147- {
148- Console . Write ( "Notification: CreditTick=" + noti . NotificationCreditTick + " SequenceNumber=" + noti . NotificationSequenceNumber ) ;
149- Console . WriteLine ( String . Format ( " PLC-Timestamp={0}.{1:D03}" , noti . Add1Timestamp . ToString ( ) , noti . Add1Timestamp . Millisecond ) ) ;
141+ // var noti = Notification.DeserializeFromPdu(m_ReceivedPDU);
142+ // if (noti == null)
143+ // {
144+ // Console.WriteLine("Notification == null!");
145+ // return S7Consts.errIsoInvalidPDU;
146+ // }
147+ // else
148+ // {
149+ // Console.Write("Notification: CreditTick=" + noti.NotificationCreditTick + " SequenceNumber=" + noti.NotificationSequenceNumber);
150+ // Console.WriteLine(String.Format(" PLC-Timestamp={0}.{1:D03}", noti.Add1Timestamp.ToString(), noti.Add1Timestamp.Millisecond));
150151
151- var dai = AlarmsDai . FromNotificationObject ( noti . P2Objects [ 0 ] , alarmTextsLanguageId ) ;
152- Console . WriteLine ( dai . ToString ( ) ) ;
153- if ( noti . NotificationCreditTick >= m_AlarmNextCreditLimit - 1 ) // Set new limit one tick before it expires, to get a constant flow of data
154- {
155- // CreditTick in Notification is only one byte
156- m_AlarmNextCreditLimit = ( short ) ( ( m_AlarmNextCreditLimit + creditLimitStep ) % 255 ) ;
157- Console . WriteLine ( "--> Credit limit of " + noti . NotificationCreditTick + " reached. SetCreditLimit to " + m_AlarmNextCreditLimit . ToString ( ) ) ;
158- SubscriptionSetCreditLimit ( m_AlarmNextCreditLimit ) ;
159- }
160- }
161- }
162- return res ;
152+ // var dai = AlarmsDai.FromNotificationObject(noti.P2Objects[0], alarmTextsLanguageId);
153+ // Console.WriteLine(dai.ToString());
154+ // if (noti.NotificationCreditTick >= m_AlarmNextCreditLimit - 1) // Set new limit one tick before it expires, to get a constant flow of data
155+ // {
156+ // // CreditTick in Notification is only one byte
157+ // m_AlarmNextCreditLimit = (short)((m_AlarmNextCreditLimit + creditLimitStep) % 255);
158+ // Console.WriteLine("--> Credit limit of " + noti.NotificationCreditTick + " reached. SetCreditLimit to " + m_AlarmNextCreditLimit.ToString());
159+ // SubscriptionSetCreditLimit(m_AlarmNextCreditLimit);
160+ // }
161+ // }
162+ // }
163+ // return res;
164+ //}
165+
166+ public int WaitForAlarmNotifications ( int waitTimeout , out List < Notification > notifications )
167+ {
168+ int res = 0 ;
169+ short creditLimitStep = 5 ;
170+ notifications = new List < Notification > ( ) ;
171+
172+ m_LastError = 0 ;
173+ WaitForNewS7plusReceived ( waitTimeout ) ;
174+ if ( m_LastError != 0 )
175+ {
176+ return m_LastError ;
177+ }
178+
179+ var noti = Notification . DeserializeFromPdu ( m_ReceivedPDU ) ;
180+ if ( noti == null )
181+ {
182+ return S7Consts . errIsoInvalidPDU ;
183+ }
184+ else
185+ {
186+ notifications . Add ( noti ) ;
187+
188+ if ( noti . NotificationCreditTick >= m_AlarmNextCreditLimit - 1 ) // Set new limit one tick before it expires, to get a constant flow of data
189+ {
190+ // CreditTick in Notification is only one byte
191+ m_AlarmNextCreditLimit = ( short ) ( ( m_AlarmNextCreditLimit + creditLimitStep ) % 255 ) ;
192+ SubscriptionSetCreditLimit ( m_AlarmNextCreditLimit ) ;
193+ }
194+ }
195+ return res ;
163196 }
164197
165198 public int AlarmSubscriptionDelete ( )
0 commit comments