Exemplo n.º 1
0
        /// <summary>
        /// 向PLC中位软元件写入bool数组,返回值说明,比如你写入D100,values[0]对应D100.0
        /// </summary>
        /// <param name="address">要写入的数据地址</param>
        /// <param name="values">要写入的实际数据,可以指定任意的长度</param>
        /// <returns>返回写入结果</returns>
        /// <example>
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteBool" title="WriteBool示例" />
        /// </example>
        public OperateResult Write(string address, bool[] values)
        {
            // 获取指令
            var command = BuildWriteCommand(address, values.Select(m => m ? (byte)0x01 : (byte)0x00).ToArray( ), true);

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

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

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

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

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

            // 写入成功
            return(OperateResult.CreateSuccessResult( ));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从欧姆龙PLC中批量读取位软元件,返回读取结果
        /// </summary>
        /// <param name="address">读取地址,格式为"D100","C100","W100","H100","A100"</param>
        /// <param name="length">读取的长度</param>
        /// <returns>带成功标志的结果数据对象</returns>
        /// <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 = BuildReadCommand(address, length, true);

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

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

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

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

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

            // 返回正确的数据信息
            return(OperateResult.CreateSuccessResult(valid.Content.Select(m => m != 0x00 ? true : false).ToArray( )));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 向PLC写入数据,数据格式为原始的字节类型
        /// </summary>
        /// <param name="address">初始地址</param>
        /// <param name="value">原始的字节数据</param>
        /// <returns>结果</returns>
        /// <example>
        /// 假设起始地址为D100,D100存储了温度,100.6℃值为1006,D101存储了压力,1.23Mpa值为123,D102,D103存储了产量计数,读取如下:
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteExample2" title="Write示例" />
        /// 以下是写入不同类型数据的示例
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="WriteExample1" title="Write示例" />
        /// </example>
        public override OperateResult Write(string address, byte[] value)
        {
            // 获取指令
            var command = BuildWriteCommand(address, value, false);

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

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

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

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

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

            // 成功
            return(OperateResult.CreateSuccessResult( ));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 从欧姆龙PLC中读取想要的数据,返回读取结果,读取单位为字
        /// </summary>
        /// <param name="address">读取地址,格式为"D100","C100","W100","H100","A100"</param>
        /// <param name="length">读取的数据长度</param>
        /// <returns>带成功标志的结果数据对象</returns>
        /// <example>
        /// 假设起始地址为D100,D100存储了温度,100.6℃值为1006,D101存储了压力,1.23Mpa值为123,D102,D103存储了产量计数,读取如下:
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadExample2" title="Read示例" />
        /// 以下是读取不同类型数据的示例
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\OmronFinsNet.cs" region="ReadExample1" title="Read示例" />
        /// </example>
        public override OperateResult <byte[]> Read(string address, ushort length)
        {
            // 获取指令
            var command = BuildReadCommand(address, length, false);

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

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

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

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

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

            // 读取到了正确的数据
            return(OperateResult.CreateSuccessResult(valid.Content));
        }