/// <summary> /// Called when the Start method is called. /// </summary> /// <param name="context">The context.</param> /// <param name="method">The method.</param> /// <param name="inputArguments">The input arguments.</param> /// <param name="outputArguments">The output arguments.</param> /// <returns></returns> public ServiceResult OnStart( ISystemContext context, MethodState method, IList <object> inputArguments, IList <object> outputArguments) { // all arguments must be provided. if (inputArguments.Count < 2) { return(StatusCodes.BadArgumentsMissing); } // check the data type of the input arguments. uint?initialState = inputArguments[0] as uint?; uint?finalState = inputArguments[1] as uint?; if (initialState == null || finalState == null) { return(StatusCodes.BadTypeMismatch); } Console.WriteLine(" OnStart-Message Requested -"); lock (m_processLock) { // check if the process is running. if (m_processTimer != null) { m_processTimer.Dispose(); m_processTimer = null; } // start the process. m_state = initialState.Value; m_finalState = finalState.Value; // Timer mit OnUpdateProcess - Methode initialisieren m_processTimer = new Timer(OnUpdateProcess, null, 1000, 1000); // the calling function sets default values for all output arguments. // only need to update them here. // System.Windows.Forms.MessageBox.Show(" OnStart-Message Requested -", m_state.ToString()); outputArguments[0] = m_state; outputArguments[1] = m_finalState; } // signal update to state node. lock (Lock) { m_stateNode.Value = m_state; m_stateNode.ClearChangeMasks(SystemContext, true); } // System.Windows.Forms.MessageBox.Show(" OnStart-Message Requested - return ServiceResult: "); return(ServiceResult.Good); }
public void ConstructorTest() { PropertyState <double> _property = new PropertyState <double>(null, "PropertyState"); Assert.IsNotNull(_property.BrowseName); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.Value, _property.ChangeMasks); Assert.AreEqual <NodeClass>(NodeClass.Variable_2, _property.NodeClass); Assert.IsNull(_property.Parent); Assert.AreEqual <double>(default(double), _property.Value); _property.ClearChangeMasks(new SystemContextFixture(), true); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.None, _property.ChangeMasks); }
private ServiceResult UpdateSystemStatus(ISystemContext context, MethodState method, IList <object> inputArguments, IList <object> outputArguments) { if (inputArguments.Count != 1) { return(StatusCodes.BadArgumentsMissing); } _systemStatusPropertyState.Value = inputArguments[0]; // signal update to state node. lock (ApplicationNodeManager.Lock) { _systemStatusPropertyState.ClearChangeMasks(ApplicationNodeManager.SystemContext, true); } return(ServiceResult.Good); }
public void ValueTest() { PropertyState <double> _property = new PropertyState <double>(null, "PropertyState"); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.Value, _property.ChangeMasks); Assert.AreEqual <double>(default(double), _property.Value); _property.ClearChangeMasks(new SystemContextFixture(), true); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.None, _property.ChangeMasks); ISystemContext _returnedContext = null; NodeStateChangeMasks _returnedMask = NodeStateChangeMasks.None; NodeState _returnedNodeState = null; int _handlerCalled = 0; _property.OnStateChanged += (x, y, z) => { _returnedContext = x; _returnedNodeState = y; _returnedMask = z; _handlerCalled++; }; _property.Value = 999.99; Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.Value, _property.ChangeMasks); Assert.AreEqual <double>(999.99, _property.Value); _property.ClearChangeMasks(new SystemContextFixture(), true); Assert.AreEqual <int>(1, _handlerCalled); Assert.IsNotNull(_returnedContext); Assert.AreSame(_property, _returnedNodeState); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.Value, _returnedMask); Assert.AreEqual <NodeStateChangeMasks>(NodeStateChangeMasks.None, _property.ChangeMasks); }
/// <summary> /// Called each time the scan cycle completes. /// </summary> private void DoSimulation(object state) { try { // must acquire the lock. lock (Lock) { // increment counter. m_property.Value++; // this triggers a callback which is implemented in the base class. // the call back pushes the updated values into the monitored items. m_property.ClearChangeMasks(SystemContext, true); } } catch (Exception e) { Utils.Trace(e, "Unexpected error doing simulation."); } }
private ServiceResult OnStart(ISystemContext context, MethodState method, IList <object> inputArguments, IList <object> outputArguments) { // all arguments must be provided. if (inputArguments.Count < 2) { return(StatusCodes.BadArgumentsMissing); } // check the data type of the input arguments. uint?initialState = inputArguments[0] as uint?; uint?finalState = inputArguments[1] as uint?; if (initialState == null || finalState == null) { return(StatusCodes.BadTypeMismatch); } lock (_processLock) { // check if the process is running. if (_processTimer != null) { _processTimer.Dispose(); _processTimer = null; } // start the process. _state = initialState.Value; _finalState = finalState.Value; _processTimer = new Timer(OnUpdateProcess, null, 1000, 1000); // the calling function sets default values for all output arguments. // only need to update them here. outputArguments[0] = _state; outputArguments[1] = _finalState; } // signal update to state node. lock (ApplicationNodeManager.Lock) { _stateNode.Value = _state; _stateNode.ClearChangeMasks(ApplicationNodeManager.SystemContext, true); } TranslationInfo info = new TranslationInfo( "OnStart", "en-US", "The Confirm method was called."); AuditUpdateMethodEventState auditUpdateMethodEventState = new AuditUpdateMethodEventState(method); auditUpdateMethodEventState.Initialize( context, method, EventSeverity.Low, new LocalizedText(info), ServiceResult.IsGood(StatusCodes.Good), DateTime.UtcNow); auditUpdateMethodEventState.SourceName.Value = "Attribute/Call"; auditUpdateMethodEventState.MethodId = new PropertyState <NodeId>(method) { Value = method.NodeId }; auditUpdateMethodEventState.InputArguments = new PropertyState <object[]>(method) { Value = new object[] { inputArguments } }; auditUpdateMethodEventState.SetChildValue(context, BrowseNames.InputArguments, inputArguments.ToArray(), true); bool valid = auditUpdateMethodEventState.Validate(context); if (valid) { ApplicationNodeManager.Server.ReportEvent(auditUpdateMethodEventState); } return(ServiceResult.Good); }
private void ConnectPLC(object item) { try { List <string[]> informations = excelInfors.FindAll(x => x[1] != "" && x[2] != "" && x[3] != ""); float Temperature = 0; float Humidity = 0; foreach (string[] infor in informations) { float value = 0; var tagName = infor[0]; var ip = (string)infor[1]; var port = Int32.Parse(infor[2]); EasyModbus.ModbusClient modbusClient = new EasyModbus.ModbusClient(ip, port); try { ////Increase the Connection Timeout to 5 seconds modbusClient.ConnectionTimeout = 5000; modbusClient.Connect(); var address = Int32.Parse(infor[3]); var length = Int32.Parse(infor[4]); int[] holdingRegister = modbusClient.ReadHoldingRegisters(address - 1, length); var rawValue = holdingRegister[0]; value = Convert.ToSingle(Decimal.Divide(rawValue, 10)); } catch (Exception ex) { } try { using (SqlConnection connection = new SqlConnection(conString)) using (SqlCommand command = new SqlCommand("Insert into [ADVANTECH WISE-4220] (Time, TagName, Value, MachineIRAI, SensorIRAI) values(@date,@tagName,@value,@irai,@sensorIrai)", connection)) { command.Parameters.AddWithValue("date", System.DateTime.Now); command.Parameters.AddWithValue("tagName", tagName); command.Parameters.AddWithValue("value", value); command.Parameters.AddWithValue("irai", infor[5]); command.Parameters.AddWithValue("sensorIrai", infor[6]); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } catch (Exception ex) { } if (tagName == "Temperature") { Temperature = value; } if (tagName == "Humidity") { Humidity = value; } PropertyState matrix = (PropertyState)FindPredefinedNode(new NodeId(infor[0], NamespaceIndex), typeof(PropertyState)); matrix.Value = value; matrix.ClearChangeMasks(SystemContext, true); modbusClient.Disconnect(); } var data = new Record(); data.Temperature = Temperature; data.Humidity = Humidity; MongoHelper.Asset.UpdatePrimaryValue("0990-MY.0027101.0000000001-#TS-00058200.0000000005.0002", data); } catch (Exception e) { Utils.Trace(e, "Unexpected error during simulation."); } }