private void ToggleRampCond() { var cs = new AeConditionState[1]; var devfailattrs = new object[1]; cs[0] = new AeConditionState(ConditionIdWaterLevel, 0, true, DaQuality.Good, 1, devfailattrs) { ActiveState = true }; switch (levelValue_) { case 10: levelValue_ = 20; cs[0].SubConditionId = SubCondDDefIdLoRamp; break; case 20: levelValue_ = 50; cs[0].ActiveState = false; break; case 50: levelValue_ = 80; cs[0].SubConditionId = SubCondDefIdHiRamp; cs[0].AckRequired = true; break; case 80: levelValue_ = 90; cs[0].SubConditionId = SubCondDefIdHiHiRamp; break; case 90: levelValue_ = 10; cs[0].SubConditionId = SubCondDefIdLoLoRamp; break; } devfailattrs[0] = levelValue_; // Set required attribute ProcessConditionStateChanges(1, cs); }
private void GetConditionStateButtonOnClick(object sender, System.EventArgs e) { if (conditionlistView.SelectedItems.Count != 0) { AeCondition condition = ((AeCondition)conditionlistView.SelectedItems[0].Tag); AeConditionState conditionState = null; this.conditionStateRichTextBox.Text = null; int res = m_session.GetAeConditionState(condition.SourcePath, condition.ConditionName, null, out conditionState, m_executionOptions); if (ResultCode.SUCCEEDED(res) && (m_executionOptions.ExecutionType == EnumExecutionType.SYNCHRONOUS)) { this.conditionStateRichTextBox.Text += " Source Path: " + condition.SourcePath + "\n"; this.conditionStateRichTextBox.Text += " Condition Name: " + condition.ConditionName + "\n"; this.conditionStateRichTextBox.Text += " State: " + GetState(conditionState.State) + "\n"; this.conditionStateRichTextBox.Text += " Quality: " + conditionState.Quality + "\n"; this.conditionStateRichTextBox.Text += " Active Time: " + conditionState.ConditionActiveTime + "\n"; this.conditionStateRichTextBox.Text += " Inactive Time: " + conditionState.ConditionInactiveTime + "\n"; this.conditionStateRichTextBox.Text += " AcknowledgeTime: " + conditionState.ConditionAckTime + "\n"; this.conditionStateRichTextBox.Text += " AcknowledgerComment: " + conditionState.AcknowledgerComment + "\n"; this.conditionStateRichTextBox.Text += " AcknowledgerID: " + conditionState.AcknowledgerId + "\n"; this.conditionStateRichTextBox.Text += " Active subcondition time: " + conditionState.SubConditionActiveTime + "\n"; this.conditionStateRichTextBox.Text += " Active subcondition name: " + conditionState.ActiveSubConditionName + "\n"; this.conditionStateRichTextBox.Text += " Active subcondition definition: " + conditionState.ActiveSubConditionDefinition + "\n"; this.conditionStateRichTextBox.Text += " Active subcondition description: " + conditionState.ActiveSubConditionDescription + "\n"; this.conditionStateRichTextBox.Text += " Active subcondition severity: " + conditionState.ActiveSubConditionSeverity + "\n"; this.conditionStateRichTextBox.Text += " Number of subconditions: " + conditionState.SubConditionsNames.Length + "\n"; for (int i = 0; i < conditionState.SubConditionsNames.Length; i++) { this.conditionStateRichTextBox.Text += " Subcondition name: "+ conditionState.SubConditionsNames[i] + "\n"; this.conditionStateRichTextBox.Text += " Subcondition definition: "+ conditionState.SubConditionsDefinitions[i] + "\n"; this.conditionStateRichTextBox.Text += " Subcondition description: "+ conditionState.SubConditionsDescriptions[i] + "\n"; this.conditionStateRichTextBox.Text += " Subcondition severity: "+ conditionState.SubConditionsSeverities[i] + "\n"; } //end for } //end if } else { MessageBox.Show(" Select a condition in the condition list ! ", "Select condition"); } //ens if ... else }
//========================================================================= // ToggleTank1Cond // --------------- // Each call of this function changes the active state of the // condition specified by ID ConditionIdTank1Overflow. // This function also sets the required attribute valus and uses // an own message which is used instead of the default message. //========================================================================= private void ToggleTank1Cond() { var cs = new AeConditionState[1]; var devfailattrs = new object[1]; cs[0] = new AeConditionState(ConditionIdTank1Overflow, 0, false, DaQuality.Good, 1, devfailattrs); if (tank1Active_) { tank1Active_ = false; cs[0].Message = "Normal State"; // Own message devfailattrs[0] = 80; // Current Value } else { tank1Active_ = true; cs[0].Message = "Overflow"; // Own message devfailattrs[0] = 123; // Current Value } cs[0].ActiveState = tank1Active_; // Set current active state // Process the new state ProcessConditionStateChanges(1, cs); }
} // end Terminate public string GetConditionState() { if (m_aeSession == null) { return(""); } // end if string message = String.Empty; try { string conditionStateToString = String.Empty; AeConditionState conditionState = null; int result = m_aeSession.GetAeConditionState( "computer.clock.time slot 1", "between", null, out conditionState, null); if (ResultCode.SUCCEEDED(result)) { message = "The condition state is: \n"; message += " Source Path: computer.clock.time slot 1 \n"; message += " Condition Name: between \n"; message += " State: " + GetStateToString(conditionState.State) + "\n"; message += " Quality: " + conditionState.Quality + "\n"; message += " Active Time: " + conditionState.ConditionActiveTime + "\n"; message += " Inactive Time: " + conditionState.ConditionInactiveTime + "\n"; message += " AcknowledgeTime: " + conditionState.ConditionAckTime + "\n"; message += " AcknowledgerComment: " + conditionState.AcknowledgerComment + "\n"; message += " AcknowledgerID: " + conditionState.AcknowledgerId + "\n"; message += " Active subcondition time: " + conditionState.SubConditionActiveTime + "\n"; message += " Active subcondition name: " + conditionState.ActiveSubConditionName + "\n"; message += " Active subcondition definition: " + conditionState.ActiveSubConditionDefinition + "\n"; message += " Active subcondition description: " + conditionState.ActiveSubConditionDescription + "\n"; message += " Active subcondition severity: " + conditionState.ActiveSubConditionSeverity + "\n"; message += " Number of subconditions: " + conditionState.SubConditionsNames.Length + "\n"; for (int i = 0; i < conditionState.SubConditionsNames.Length; i++) { message += " Subcondition name: "+ conditionState.SubConditionsNames[i] + "\n"; message += " Subcondition definition: "+ conditionState.SubConditionsDefinitions[i] + "\n"; message += " Subcondition description: "+ conditionState.SubConditionsDescriptions[i] + "\n"; message += " Subcondition severity: "+ conditionState.SubConditionsSeverities[i] + "\n"; }//end for } else { message = "Get condition state failed!\n"; } // end if...else } catch (Exception exc) { GetApplication().Trace( EnumTraceLevel.ERR, EnumTraceGroup.USER, "OpcClient::GetConditionState", exc.ToString()); } // end try...catch return(message); }//end GetConditionState
// This method simulates item value changes. void RefreshThread() { double count = 0; int ramp = 0; var rand = new Random(); var devfailattrs = new object[2]; var condHeating1 = new Heating1Condition(); devfailattrs[0] = (long)5555; // Error Code devfailattrs[1] = "3Com EtherLink XL NIC (3C900B-COMBO)"; // Device Name var cs = new AeConditionState[1]; cs[0] = new AeConditionState(ConditionIdTank1Overflow, 0, false, DaQuality.Good, 1, devfailattrs) { ActiveState = true }; // Update all used items once foreach (MyItem item in items_.Values) { SetItemValue(item.DeviceItemHandle, item.Value, DaQuality.Good.Code, DateTime.Now); } for (; ;) // forever thread loop { //int numclientHandles; //IntPtr[] clientHandles; //String[] clientNames; //GetClients(out numclientHandles, out clientHandles, out clientNames); //if (numclientHandles > 0) //{ // foreach (var client in clientHandles) // { // int numGroupHandles; // IntPtr[] groupHandles; // String[] groupNames; // GetGroups(client, out numGroupHandles, out groupHandles, out groupNames); // if (numGroupHandles > 0) // { // foreach (var group in groupHandles) // { // DaGroupState groupInfo; // GetGroupState(group, out groupInfo); // int numItemStates; // DaItemState[] itemStates; // GetItemStates(group, out numItemStates, out itemStates); // } // } // } //} DateTime dateTimeStartRefresh = DateTime.UtcNow; if ((count % 2) == 0) { ToggleTank1Cond(); // every 2s } if ((count % 3) == 0) { ToggleRampCond(); // every 3s } if ((count % 5) == 0) { // every 5s condHeating1.ToggleCondition(); } if ((count % 120) == 0) { // every 2 min. devfailattrs[0] = (long)1234; // Error Code devfailattrs[1] = "3Com EtherLink XL NIC (3C900B-COMBO)"; // Device Name ProcessSimpleEvent(CategoryIdDeviceFailure, SourceIdNetworkAdapter, "No response", 800, 2, devfailattrs, DateTime.Now); } // Sample how to get a list of active items (used at least by one client) int numHandles; IntPtr[] itemHandles; GetActiveItems(out numHandles, out itemHandles); count++; ramp++; myDynamicRampItem_.Value = ramp; // update server cache for this item SetItemValue(myDynamicRampItem_.DeviceItemHandle, myDynamicRampItem_.Value, DaQuality.Good.Code, DateTime.Now); myDynamicRandomItem_.Value = rand.Next(); SetItemValue(myDynamicRandomItem_.DeviceItemHandle, myDynamicRandomItem_.Value, DaQuality.Good.Code, DateTime.Now); myDynamicSineItem_.Value = Math.Sin((count % 40) * 0.1570796327); SetItemValue(myDynamicSineItem_.DeviceItemHandle, myDynamicSineItem_.Value, DaQuality.Good.Code, DateTime.Now); DateTime dateTimeStart = DateTime.UtcNow; // Update all used items once foreach (MyItem item in dynamicItems_.Values) { item.Value = ramp; SetItemValue(item.DeviceItemHandle, item.Value, DaQuality.Good.Code, DateTime.Now); } TimeSpan duration = (DateTime.UtcNow - dateTimeStart); double callsPerSecond = 1 / (duration.TotalSeconds / NumberMassItems); myDynamicSetItemValueCallsPerSecondItem_.Value = Math.Round(callsPerSecond); SetItemValue(myDynamicSetItemValueCallsPerSecondItem_.DeviceItemHandle, myDynamicSetItemValueCallsPerSecondItem_.Value, DaQuality.Good.Code, DateTime.Now); TimeSpan durationRefresh = (DateTime.UtcNow - dateTimeStartRefresh); int waitTime = 1000 - (int)durationRefresh.TotalMilliseconds; if (waitTime > 0) { Thread.Sleep(waitTime); // ms } if (stopThread_ != null) { stopThread_.Set(); return; // terminate the thread } } }
public Heating1Condition() { cs_[0] = new AeConditionState(ConditionIdHeating1ExtTemp, 0, false, DaQuality.Good, 1, devfailattrs_); }