Exemple #1
0
        /// <summary>
        /// 使用指定的类型写入指定的节点数据 -> Writes the specified node data with the specified type
        /// </summary>
        /// <param name="address">节点的名称 -> Name of the node </param>
        /// <param name="typeCode">类型代码,详细参见<see cref="AllenBradleyHelper"/>上的常用字段 ->  Type code, see the commonly used Fields section on the <see cref= "AllenBradleyHelper"/> in detail</param>
        /// <param name="value">实际的数据值 -> The actual data value </param>
        /// <param name="length">如果节点是数组,就是数组长度 -> If the node is an array, it is the array length </param>
        /// <returns>是否写入成功 -> Whether to write successfully</returns>
        public OperateResult WriteTag(string address, ushort typeCode, byte[] value, int length = 1)
        {
            OperateResult <byte[]> command = BuildWriteCommand(address, typeCode, value, length);

            if (!command.IsSuccess)
            {
                return(command);
            }

            OperateResult <byte[]> read = ReadFromCoreServer(command.Content);

            if (!read.IsSuccess)
            {
                return(read);
            }

            OperateResult check = CheckResponse(read.Content);

            if (!check.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(check));
            }

            return(AllenBradleyHelper.ExtractActualData(read.Content, false));
        }
Exemple #2
0
        /// <summary>
        /// 批量读取数据信息,数据长度为读取的数组长度信息 -> Bulk read data information, data length for read array length information
        /// </summary>
        /// <param name="address">节点的名称 -> Name of the node </param>
        /// <param name="length">如果是数组,就为数组长度 -> In the case of arrays, the length of the array </param>
        /// <returns>带有结果对象的结果数据 -> Result data with result object </returns>
        public OperateResult <byte[]> Read(string[] address, int[] length)
        {
            // 指令生成 -> Instruction Generation
            OperateResult <byte[]> command = BuildReadCommand(address, length);

            if (!command.IsSuccess)
            {
                return(command);
            }

            // 核心交互 -> Core Interactions
            OperateResult <byte[]> read = ReadFromCoreServer(command.Content);

            if (!read.IsSuccess)
            {
                return(read);
            }

            // 检查反馈 -> Check Feedback
            OperateResult check = CheckResponse(read.Content);

            if (!check.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(check));
            }

            // 提取数据 -> Extracting data
            return(AllenBradleyHelper.ExtractActualData(read.Content, true));
        }
        /// <summary>
        /// 批量读取数据信息,数据长度无效
        /// </summary>
        /// <param name="address">节点的地址格式</param>
        /// <returns>带有结果对象的结果数据</returns>
        public OperateResult <byte[]> Read(string[] address)
        {
            // 指令生成
            OperateResult <byte[]> command = BuildReadCommand(address);

            if (!command.IsSuccess)
            {
                return(command);
            }

            // 核心交互
            OperateResult <byte[]> read = ReadFromCoreServer(command.Content);

            if (!read.IsSuccess)
            {
                return(read);
            }

            // 检查反馈
            OperateResult check = CheckResponse(read.Content);

            if (!check.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(check));
            }

            // 提取数据
            return(AllenBradleyHelper.ExtractActualData(read.Content, true));
        }
Exemple #4
0
        private OperateResult <byte[]> ReadByCips(params byte[][] cips)
        {
            OperateResult <byte[]> read = ReadCipFromServer(cips);

            if (!read.IsSuccess)
            {
                return(read);
            }

            // 提取数据 -> Extracting data
            return(AllenBradleyHelper.ExtractActualData(read.Content, true));
        }