示例#1
0
        /// <summary>
        /// 写入自定义的数据到数据内存中去
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="value">数据值</param>
        /// <returns>是否写入成功的结果对象</returns>
        public override OperateResult Write(string address, byte[] value)
        {
            OperateResult <byte, int, ushort> analysis = SiemensS7Net.AnalysisAddress(address);

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

            switch (analysis.Content1)
            {
            case 0x81: inputBuffer.SetBytes(value, analysis.Content2 / 8); return(OperateResult.CreateSuccessResult( ));

            case 0x82: outputBuffer.SetBytes(value, analysis.Content2 / 8); return(OperateResult.CreateSuccessResult( ));

            case 0x83: memeryBuffer.SetBytes(value, analysis.Content2 / 8); return(OperateResult.CreateSuccessResult( ));

            case 0x84: dbBlockBuffer.SetBytes(value, analysis.Content2 / 8); return(OperateResult.CreateSuccessResult( ));

            default: return(new OperateResult <byte[]>(StringResources.Language.NotSupportedDataType));
            }
        }
示例#2
0
        /// <summary>
        /// 读取自定义的寄存器的值
        /// </summary>
        /// <param name="address">起始地址,示例:"I100","M100"</param>
        /// <param name="length">数据长度</param>
        /// <exception cref="IndexOutOfRangeException"></exception>
        /// <returns>byte数组值</returns>
        public override OperateResult <byte[]> Read(string address, ushort length)
        {
            OperateResult <byte, int, ushort> analysis = SiemensS7Net.AnalysisAddress(address);

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

            switch (analysis.Content1)
            {
            case 0x81: return(OperateResult.CreateSuccessResult(inputBuffer.GetBytes(analysis.Content2 / 8, length)));

            case 0x82: return(OperateResult.CreateSuccessResult(outputBuffer.GetBytes(analysis.Content2 / 8, length)));

            case 0x83: return(OperateResult.CreateSuccessResult(memeryBuffer.GetBytes(analysis.Content2 / 8, length)));

            case 0x84: return(OperateResult.CreateSuccessResult(dbBlockBuffer.GetBytes(analysis.Content2 / 8, length)));

            default: return(new OperateResult <byte[]>(StringResources.Language.NotSupportedDataType));
            }
        }