Пример #1
0
        /// <summary>
        /// 从欧姆龙PLC中批量读取位软元件,返回读取结果
        /// </summary>
        /// <param name="address">读取地址,格式为"D100","C100","W100","H100","A100"</param>
        /// <param name="length">读取的长度</param>
        /// <returns>带成功标志的结果数据对象</returns>
        /// <remarks>
        /// 地址支持的列表如下:
        /// <list type="table">
        ///   <listheader>
        ///     <term>地址名称</term>
        ///     <term>示例</term>
        ///     <term>地址进制</term>
        ///   </listheader>
        ///   <item>
        ///     <term>DM Area</term>
        ///     <term>D100.0,D200.10</term>
        ///     <term>10</term>
        ///   </item>
        ///   <item>
        ///     <term>CIO Area</term>
        ///     <term>C100.0,C200.10</term>
        ///     <term>10</term>
        ///   </item>
        ///   <item>
        ///     <term>Work Area</term>
        ///     <term>W100.0,W200.10</term>
        ///     <term>10</term>
        ///   </item>
        ///   <item>
        ///     <term>Holding Bit Area</term>
        ///     <term>H100.0,H200.10</term>
        ///     <term>10</term>
        ///   </item>
        ///   <item>
        ///     <term>Auxiliary Bit Area</term>
        ///     <term>A100.0,A200.1</term>
        ///     <term>10</term>
        ///   </item>
        /// </list>
        /// </remarks>
        /// <example>
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadBool" title="ReadBool示例" />
        /// </example>
        public OperateResult <bool[]> ReadBool(string address, ushort length)
        {
            // 获取指令
            var command = OmronFinsNetHelper.BuildReadCommand(address, length, true);

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

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

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

            // 数据有效性分析
            OperateResult <byte[]> valid = ResponseValidAnalysis(read.Content, true);

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

            // 返回正确的数据信息
            return(OperateResult.CreateSuccessResult(valid.Content.Select(m => m != 0x00 ? true : false).ToArray( )));
        }
Пример #2
0
        /// <summary>
        /// 批量读取PLC的数据,以字为单位,支持读取X,Y,M,S,D,T,C,具体的地址范围需要根据PLC型号来确认
        /// </summary>
        /// <param name="address">地址信息</param>
        /// <param name="length">数据长度</param>
        /// <returns>读取结果信息</returns>
        public override OperateResult <byte[]> Read(string address, ushort length)
        {
            // 解析地址
            var command = OmronFinsNetHelper.BuildReadCommand(address, length, false);

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

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

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

            // 数据有效性分析
            OperateResult <byte[]> valid = ResponseValidAnalysis(read.Content, true);

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

            // 读取到了正确的数据
            return(OperateResult.CreateSuccessResult(valid.Content));
        }
Пример #3
0
        /// <summary>
        /// 根据类型地址长度确认需要读取的指令头
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="length">长度</param>
        /// <param name="isBit">是否是位读取</param>
        /// <returns>带有成功标志的报文数据</returns>
        public OperateResult <byte[]> BuildReadCommand(string address, ushort length, bool isBit)
        {
            var command = OmronFinsNetHelper.BuildReadCommand(address, length, isBit);

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

            return(OperateResult.CreateSuccessResult(PackCommand(command.Content)));
        }