Ejemplo n.º 1
0
        /// <summary>
        /// 往指定的地址里写入bool数组对象
        /// </summary>
        /// <param name="address">三菱的地址信息</param>
        /// <param name="value">值</param>
        /// <returns>是否成功的结果</returns>
        public OperateResult Write(string address, bool[] value)
        {
            OperateResult <MelsecMcDataType, int> analysis = MelsecHelper.McAnalysisAddress(address);

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

            if (analysis.Content1.DataType == 0)
            {
                return(new OperateResult <bool[]>(StringResources.Language.MelsecCurrentTypeNotSupportedWordOperate));
            }

            if (analysis.Content1.DataCode == MelsecMcDataType.M.DataCode)
            {
                mBuffer.SetBytes(value.Select(m => m ? (byte)1 : (byte)0).ToArray( ), analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.X.DataCode)
            {
                xBuffer.SetBytes(value.Select(m => m ? (byte)1 : (byte)0).ToArray( ), analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.Y.DataCode)
            {
                yBuffer.SetBytes(value.Select(m => m ? (byte)1 : (byte)0).ToArray( ), analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else
            {
                return(new OperateResult <bool[]>(StringResources.Language.NotSupportedDataType));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取指定地址的bool数据对象
        /// </summary>
        /// <param name="address">三菱的地址信息</param>
        /// <param name="length">数组的长度</param>
        /// <returns>带有成功标志的结果对象</returns>
        public OperateResult <bool[]> ReadBool(string address, ushort length)
        {
            OperateResult <MelsecMcDataType, int> analysis = MelsecHelper.McAnalysisAddress(address);

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

            if (analysis.Content1.DataType == 0)
            {
                return(new OperateResult <bool[]>(StringResources.Language.MelsecCurrentTypeNotSupportedWordOperate));
            }

            if (analysis.Content1.DataCode == MelsecMcDataType.M.DataCode)
            {
                return(OperateResult.CreateSuccessResult(mBuffer.GetBytes(analysis.Content2, length).Select(m => m != 0x00).ToArray( )));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.X.DataCode)
            {
                return(OperateResult.CreateSuccessResult(xBuffer.GetBytes(analysis.Content2, length).Select(m => m != 0x00).ToArray( )));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.Y.DataCode)
            {
                return(OperateResult.CreateSuccessResult(yBuffer.GetBytes(analysis.Content2, length).Select(m => m != 0x00).ToArray( )));
            }
            else
            {
                return(new OperateResult <bool[]>(StringResources.Language.NotSupportedDataType));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 写入自定义的数据到数据内存中去
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="value">数据值</param>
        /// <returns>是否写入成功的结果对象</returns>
        public override OperateResult Write(string address, byte[] value)
        {
            OperateResult <MelsecMcDataType, int> analysis = MelsecHelper.McAnalysisAddress(address);

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

            if (analysis.Content1.DataCode == MelsecMcDataType.M.DataCode)
            {
                byte[] buffer = SoftBasic.ByteToBoolArray(value).Select(m => m ? (byte)1 : (byte)0).ToArray( );
                mBuffer.SetBytes(buffer, analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.X.DataCode)
            {
                byte[] buffer = SoftBasic.ByteToBoolArray(value).Select(m => m ? (byte)1 : (byte)0).ToArray( );
                xBuffer.SetBytes(buffer, analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.Y.DataCode)
            {
                byte[] buffer = SoftBasic.ByteToBoolArray(value).Select(m => m ? (byte)1 : (byte)0).ToArray( );
                yBuffer.SetBytes(buffer, analysis.Content2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.D.DataCode)
            {
                dBuffer.SetBytes(value, analysis.Content2 * 2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.W.DataCode)
            {
                wBuffer.SetBytes(value, analysis.Content2 * 2);
                return(OperateResult.CreateSuccessResult( ));
            }
            else
            {
                return(new OperateResult <byte[]>(StringResources.Language.NotSupportedDataType));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 读取自定义的寄存器的值。按照字为单位
        /// </summary>
        /// <param name="address">起始地址,示例:"D100","M100"</param>
        /// <param name="length">数据长度</param>
        /// <exception cref="IndexOutOfRangeException"></exception>
        /// <returns>byte数组值</returns>
        public override OperateResult <byte[]> Read(string address, ushort length)
        {
            OperateResult <MelsecMcDataType, int> analysis = MelsecHelper.McAnalysisAddress(address);

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

            if (analysis.Content1.DataCode == MelsecMcDataType.M.DataCode)
            {
                bool[] buffer = mBuffer.GetBytes(analysis.Content2, length * 16).Select(m => m != 0x00).ToArray( );
                return(OperateResult.CreateSuccessResult(SoftBasic.BoolArrayToByte(buffer)));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.X.DataCode)
            {
                bool[] buffer = xBuffer.GetBytes(analysis.Content2, length * 16).Select(m => m != 0x00).ToArray( );
                return(OperateResult.CreateSuccessResult(SoftBasic.BoolArrayToByte(buffer)));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.Y.DataCode)
            {
                bool[] buffer = yBuffer.GetBytes(analysis.Content2, length * 16).Select(m => m != 0x00).ToArray( );
                return(OperateResult.CreateSuccessResult(SoftBasic.BoolArrayToByte(buffer)));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.D.DataCode)
            {
                return(OperateResult.CreateSuccessResult(dBuffer.GetBytes(analysis.Content2 * 2, length * 2)));
            }
            else if (analysis.Content1.DataCode == MelsecMcDataType.W.DataCode)
            {
                return(OperateResult.CreateSuccessResult(wBuffer.GetBytes(analysis.Content2 * 2, length * 2)));
            }
            else
            {
                return(new OperateResult <byte[]>(StringResources.Language.NotSupportedDataType));
            }
        }
 /// <summary>
 /// 分析地址的方法,允许派生类里进行重写操作
 /// </summary>
 /// <param name="address">地址信息</param>
 /// <returns>解析后的数据信息</returns>
 protected virtual OperateResult <MelsecMcDataType, int> McAnalysisAddress(string address)
 {
     return(MelsecHelper.McAnalysisAddress(address));
 }