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

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

            int startIndex = CheckAddress(analysis.Content.Substring(3));

            switch (analysis.Content[1])
            {
            case 'P': pBuffer.SetBytes(value, startIndex); return(OperateResult.CreateSuccessResult());

            case 'Q': qBuffer.SetBytes(value, startIndex); return(OperateResult.CreateSuccessResult());

            case 'M': mBuffer.SetBool(value[0] == 1 ? true:false, startIndex); return(OperateResult.CreateSuccessResult());

            case 'D': dBuffer.SetBytes(value, startIndex == 0 ? startIndex : startIndex *= 2); return(OperateResult.CreateSuccessResult());

            default: return(new OperateResult <byte[]>(StringResources.Language.NotSupportedDataType));
            }
        }
Example #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 <string> analysis = XGBFastEnet.AnalysisAddress(address, true);

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

            int startIndex = CheckAddress(analysis.Content.Substring(3));

            switch (analysis.Content[1])
            {
            case 'P': return(OperateResult.CreateSuccessResult(pBuffer.GetBytes(startIndex, length)));

            case 'Q': return(OperateResult.CreateSuccessResult(qBuffer.GetBytes(startIndex, length)));

            case 'M': return(OperateResult.CreateSuccessResult(SoftBasic.BoolArrayToByte(mBuffer.GetBool(startIndex, length *= 8))));

            case 'D': return(OperateResult.CreateSuccessResult(dBuffer.GetBytes(startIndex == 0 ? startIndex : startIndex *= 2, length)));

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