Пример #1
0
        /// <summary>
        /// Sets the variable value.
        /// </summary>
        private void SetVariable(VarItem varItem, CnlData[] cnlData, int dataIndex, DateTime timestamp)
        {
            try
            {
                DeviceTag deviceTag  = varItem.DeviceTag;
                int       dataLength = deviceTag.DataLength;
                object    value      = 0.0;

                switch (deviceTag.DataType)
                {
                case TagDataType.Double:
                    value = deviceTag.IsArray ?
                            (object)CnlDataConverter.GetDoubleArray(cnlData, dataIndex, dataLength) :
                            CnlDataConverter.GetDouble(cnlData, dataIndex);
                    break;

                case TagDataType.Int64:
                    value = deviceTag.IsArray ?
                            (object)CnlDataConverter.GetInt64Array(cnlData, dataIndex, dataLength) :
                            CnlDataConverter.GetInt64(cnlData, dataIndex);
                    break;

                case TagDataType.ASCII:
                    value = CnlDataConverter.GetAscii(cnlData, dataIndex, dataLength);
                    break;

                case TagDataType.Unicode:
                    value = CnlDataConverter.GetUnicode(cnlData, dataIndex, dataLength);
                    break;
                }

                BaseDataVariableState variable = varItem.Variable;
                variable.Value      = value;
                variable.StatusCode = CnlDataConverter.GetStatus(cnlData, dataIndex, dataLength) > CnlStatusID.Undefined ?
                                      StatusCodes.Good : StatusCodes.Bad;
                variable.Timestamp = timestamp;
                variable.ClearChangeMasks(SystemContext, false);
            }
            catch (Exception ex)
            {
                log.WriteException(ex, Locale.IsRussian ?
                                   "Ошибка при установке значения переменной {0}" :
                                   "Error setting the variable {0}", varItem.Variable.NodeId);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates OPC server nodes that correspond to device tags.
        /// </summary>
        private void CreateDeviceTagNodes(FolderState folder, DeviceLogic deviceLogic, TagGroup tagGroup,
                                          DeviceVars deviceVars)
        {
            string pathPrefix = CommUtils.GetDeviceLogFileName(deviceLogic.DeviceNum, ".");

            foreach (DeviceTag deviceTag in tagGroup.DeviceTags)
            {
                if (!string.IsNullOrEmpty(deviceTag.Code))
                {
                    BaseDataVariableState variable = CreateVariable(folder, pathPrefix, deviceTag);
                    variable.OnSimpleWriteValue = OnSimpleWriteValue;

                    VarItem varItem = new VarItem
                    {
                        Variable  = variable,
                        DeviceTag = deviceTag,
                        DeviceNum = deviceLogic.DeviceNum
                    };

                    deviceVars[deviceTag.Code]            = varItem;
                    varByPath[variable.NodeId.ToString()] = varItem;
                }
            }
        }