Ejemplo n.º 1
0
        /// <summary>
        /// 向PLC写入数据,数据格式为原始的字节类型
        /// </summary>
        /// <param name="address">初始地址</param>
        /// <param name="value">原始的字节数据</param>
        /// <example>
        /// 假设起始地址为D100,D100存储了温度,100.6℃值为1006,D101存储了压力,1.23Mpa值为123,D102,D103存储了产量计数,写入如下:
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\MelsecAscii.cs" region="WriteExample2" title="Write示例" />
        /// 以下是读取不同类型数据的示例
        /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\MelsecAscii.cs" region="WriteExample1" title="Write示例" />
        /// </example>
        /// <returns>是否写入成功的结果对象</returns>
        public override OperateResult Write(string address, byte[] value)
        {
            // 获取写入
            OperateResult <byte[]> command = MelsecHelper.BuildWriteWordCommand(address, value);

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

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

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

            // 结果验证
            OperateResult checkResult = CheckPlcWriteResponse(read.Content);

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

            return(OperateResult.CreateSuccessResult( ));
        }