Beispiel #1
0
        private void OkBTN_Click(object sender, EventArgs e)
        {
            try
            {
                NodeId nodeId = NodeIdCTRL.Identifier;
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter a valid node id.", this.Text);
            }

            try
            {
                if (!String.IsNullOrEmpty(IndexRangeTB.Text))
                {
                    NumericRange indexRange = NumericRange.Parse(IndexRangeTB.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter a valid index range.", this.Text);
            }

            DialogResult = DialogResult.OK;
        }
Beispiel #2
0
        private void OkBTN_Click(object sender, EventArgs e)
        {
            try {
                if (IndexRangeTB.Visible)
                {
                    NumericRange.Parse(IndexRangeTB.Text);
                }

                DialogResult = DialogResult.OK;
            } catch (Exception exception) {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
        public static NumericRange ResolveIndexRange(this string indexRange)
        {
            NumericRange resolvedIndexRange = new NumericRange(0, 0);

            if (!string.IsNullOrEmpty(indexRange))
            {
                try
                {
                    resolvedIndexRange = NumericRange.Parse(indexRange);
                }
                catch (Exception e)
                {
                    string errorMessage = $"The given IndexRange '{indexRange}' in a select clause has not a valid syntax.";
                    Logger.Error(e, errorMessage);
                    throw new Exception(errorMessage);
                }
            }
            return(resolvedIndexRange);
        }
        private void OkBTN_Click(object sender, EventArgs e)
        {
            try
            {
                IndexRangeTB.Text = IndexRangeTB.Text.Trim();

                if (String.IsNullOrEmpty(IndexRangeTB.Text))
                {
                    NumericRange.Parse(IndexRangeTB.Text);
                }

                StatusCodeTB.Text = StatusCodeTB.Text.Trim();

                if (StatusCodeCK.Checked)
                {
                    TypeInfo.Cast(StatusCodeTB.Text, BuiltInType.StatusCode);
                }

                SourceTimestampTB.Text = SourceTimestampTB.Text.Trim();

                if (SourceTimestampCK.Checked)
                {
                    TypeInfo.Cast(SourceTimestampTB.Text, BuiltInType.DateTime);
                }

                ServerTimestampTB.Text = ServerTimestampTB.Text.Trim();

                if (ServerTimestampCK.Checked)
                {
                    TypeInfo.Cast(ServerTimestampTB.Text, BuiltInType.DateTime);
                }

                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
        /// <summary>
        /// Prompts the user to edit the read request parameters for the set of nodes provided.
        /// </summary>
        public ReadValueId[] ShowDialog(Session session, params ReadValueId[] nodesToRead)
        {
            NodeBTN.Session           = session;
            NodeBTN.SelectedReference = null;

            bool editNode         = true;
            bool editAttribute    = true;
            bool editIndexRange   = true;
            bool editDataEncoding = true;

            // populate the controls.
            if (nodesToRead != null && nodesToRead.Length > 0)
            {
                bool nonValueAttribute = false;

                for (int ii = 0; ii < nodesToRead.Length; ii++)
                {
                    if (nodesToRead[ii] == null)
                    {
                        continue;
                    }

                    // only show the node if all have the same node id.
                    if (editNode)
                    {
                        if (NodeBTN.SelectedNode != null && nodesToRead[ii].NodeId != NodeBTN.SelectedNode)
                        {
                            NodeTB.Visible  = false;
                            NodeLB.Visible  = false;
                            NodeBTN.Visible = false;
                            editNode        = false;
                        }
                        else
                        {
                            NodeBTN.SelectedNode = nodesToRead[ii].NodeId;
                        }
                    }

                    // only show the attribute if all have the same attribute id.
                    if (editAttribute)
                    {
                        // check if any non-value attributes are present.
                        if (nodesToRead[ii].AttributeId != Attributes.Value)
                        {
                            nonValueAttribute = true;
                        }

                        int index = (int)nodesToRead[ii].AttributeId - 1;

                        if (AttributeCB.SelectedIndex != -1 && index != AttributeCB.SelectedIndex)
                        {
                            AttributeCB.Visible = false;
                            AttributeLB.Visible = false;
                            editAttribute       = false;
                        }
                        else
                        {
                            AttributeCB.SelectedIndex = index;
                        }
                    }
                }

                DataEncodingCB.Items.Clear();
                editIndexRange = !nonValueAttribute;

                IndexRangeLB.Visible = editIndexRange;
                IndexRangeTB.Visible = editIndexRange;

                if (!nonValueAttribute)
                {
                    // use the index range for the first node as template.
                    IndexRangeTB.Text = nodesToRead[0].IndexRange;

                    // fetch the available encodings for the first node in the list from the server.
                    IVariableBase variable = session.NodeCache.Find(nodesToRead[0].NodeId) as IVariableBase;

                    if (variable != null)
                    {
                        if (session.NodeCache.IsTypeOf(variable.DataType, Opc.Ua.DataTypeIds.Structure))
                        {
                            DataEncodingCB.Items.Add(new EncodingInfo());
                            DataEncodingCB.SelectedIndex = 0;

                            foreach (INode encoding in session.NodeCache.Find(variable.DataType, Opc.Ua.ReferenceTypeIds.HasEncoding, false, true))
                            {
                                DataEncodingCB.Items.Add(new EncodingInfo()
                                {
                                    EncodingName = encoding.BrowseName
                                });

                                if (nodesToRead[0].DataEncoding == encoding.BrowseName)
                                {
                                    DataEncodingCB.SelectedIndex = DataEncodingCB.Items.Count - 1;
                                }
                            }
                        }
                    }
                }

                // hide the data encodings if none to select.
                if (DataEncodingCB.Items.Count == 0)
                {
                    DataEncodingCB.Visible = false;
                    DataEncodingLB.Visible = false;
                    editDataEncoding       = false;
                }
            }

            if (!editNode && !editAttribute && !editIndexRange && !editDataEncoding)
            {
                throw new ArgumentException("nodesToRead", "It is not possible to edit the current selection as a group.");
            }

            if (base.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create the list of results.
            ReadValueId[] results = null;

            if (nodesToRead == null || nodesToRead.Length == 0)
            {
                results = new ReadValueId[1];
            }
            else
            {
                results = new ReadValueId[nodesToRead.Length];
            }

            // copy the controls into the results.
            for (int ii = 0; ii < results.Length; ii++)
            {
                // preserve the existing settings if they are not being changed.
                if (nodesToRead != null && nodesToRead.Length > 0)
                {
                    results[ii] = (ReadValueId)nodesToRead[ii].Clone();
                }
                else
                {
                    results[ii] = new ReadValueId();
                }

                // only copy results that were actually being edited.
                if (editNode)
                {
                    results[ii].NodeId = NodeBTN.SelectedNode;
                }

                if (editAttribute)
                {
                    results[ii].AttributeId = (uint)(AttributeCB.SelectedIndex + 1);
                }

                if (editIndexRange)
                {
                    results[ii].ParsedIndexRange = NumericRange.Parse(IndexRangeTB.Text);

                    if (NumericRange.Empty != results[ii].ParsedIndexRange)
                    {
                        results[ii].IndexRange = results[ii].ParsedIndexRange.ToString();
                    }
                    else
                    {
                        results[ii].IndexRange = String.Empty;
                    }
                }

                if (editDataEncoding)
                {
                    results[ii].DataEncoding = null;

                    EncodingInfo encoding = DataEncodingCB.SelectedItem as EncodingInfo;

                    if (encoding != null)
                    {
                        results[ii].DataEncoding = encoding.EncodingName;
                    }
                }
            }

            return(results);
        }
Beispiel #6
0
        private void Load()
        {
            foreach (string resourceName in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (resourceName.EndsWith(".SystemConfiguration.xml"))
                {
                    using (Stream istrm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
                        m_configuration = (Configuration)serializer.Deserialize(istrm);
                    }
                }
            }

            if (m_configuration.Controllers != null)
            {
                for (int ii = 0; ii < m_configuration.Controllers.Length; ii++)
                {
                    ControllerConfiguration controller = m_configuration.Controllers[ii];

                    int blockAddress = m_position;
                    int offset       = m_position - blockAddress;

                    BlockConfiguration data = new BlockConfiguration()
                    {
                        Address    = blockAddress,
                        Name       = controller.Name,
                        Type       = controller.Type,
                        Properties = new List <BlockProperty>()
                    };

                    if (controller.Properties != null)
                    {
                        for (int jj = 0; jj < controller.Properties.Length; jj++)
                        {
                            ControllerProperty property   = controller.Properties[jj];
                            NodeId             dataTypeId = NodeId.Parse(property.DataType);
                            string             value      = property.Value;
                            Range range = null;

                            if (!String.IsNullOrEmpty(property.Range))
                            {
                                try
                                {
                                    NumericRange nr = NumericRange.Parse(property.Range);
                                    range = new Range()
                                    {
                                        High = nr.End, Low = nr.Begin
                                    };
                                }
                                catch (Exception)
                                {
                                    range = null;
                                }
                            }

                            data.Properties.Add(new BlockProperty()
                            {
                                Offset    = offset,
                                Name      = controller.Properties[jj].Name,
                                DataType  = dataTypeId,
                                Writeable = controller.Properties[jj].Writeable,
                                Range     = range
                            });

                            switch ((uint)dataTypeId.Identifier)
                            {
                            case DataTypes.Int32:
                            {
                                //Write(blockAddress, offset, (int)TypeUtils.Cast(value, BuiltInType.Int32));
                                offset += 4;
                                break;
                            }

                            case DataTypes.Double:
                            {
                                // Write(blockAddress, offset, (double)TypeUtils.Cast(value, BuiltInType.Double));
                                offset += 4;
                                break;
                            }
                            }
                        }
                    }

                    m_position            += offset;
                    m_blocks[blockAddress] = data;
                }
            }
        }
        /// <summary>
        /// Prompts the user to edit the write request parameters for the set of nodes provided.
        /// </summary>
        public WriteValue ShowDialog(Session session, WriteValue nodeToWrite)
        {
            NodeBTN.Session           = session;
            NodeBTN.SelectedReference = null;

            // fill in the control.
            NodeBTN.SelectedNode      = nodeToWrite.NodeId;
            AttributeCB.SelectedIndex = (int)nodeToWrite.AttributeId - 1;
            IndexRangeTB.Text         = nodeToWrite.IndexRange;
            ValueBTN.Value            = nodeToWrite.Value.WrappedValue;

            if (nodeToWrite.Value.StatusCode != StatusCodes.Good)
            {
                StatusCodeTB.Text    = (string)TypeInfo.Cast(nodeToWrite.Value.StatusCode, BuiltInType.String);
                StatusCodeCK.Checked = true;
            }

            if (nodeToWrite.Value.SourceTimestamp != DateTime.MinValue)
            {
                SourceTimestampTB.Text    = (string)TypeInfo.Cast(nodeToWrite.Value.SourceTimestamp, BuiltInType.String);
                SourceTimestampCK.Checked = true;
            }

            if (nodeToWrite.Value.ServerTimestamp != DateTime.MinValue)
            {
                ServerTimestampTB.Text    = (string)TypeInfo.Cast(nodeToWrite.Value.ServerTimestamp, BuiltInType.String);
                ServerTimestampCK.Checked = true;
            }

            if (base.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create the result.
            WriteValue result = new WriteValue();

            result.NodeId             = NodeBTN.SelectedNode;
            result.AttributeId        = (uint)(AttributeCB.SelectedIndex + 1);
            result.ParsedIndexRange   = NumericRange.Parse(IndexRangeTB.Text);
            result.Value.WrappedValue = ValueBTN.Value;

            if (StatusCodeCK.Checked)
            {
                result.Value.StatusCode = (StatusCode)TypeInfo.Cast(StatusCodeTB.Text, BuiltInType.StatusCode);
            }

            if (SourceTimestampCK.Checked)
            {
                result.Value.SourceTimestamp = (DateTime)TypeInfo.Cast(SourceTimestampTB.Text, BuiltInType.DateTime);
            }

            if (ServerTimestampCK.Checked)
            {
                result.Value.ServerTimestamp = (DateTime)TypeInfo.Cast(ServerTimestampTB.Text, BuiltInType.DateTime);
            }

            if (NumericRange.Empty != result.ParsedIndexRange)
            {
                result.IndexRange = result.ParsedIndexRange.ToString();
            }
            else
            {
                result.IndexRange = String.Empty;
            }

            return(result);
        }