Esempio n. 1
0
        /// <summary>
        /// 向PLC中位软元件写入bool数组,返回值说明,比如你写入M100,values[0]对应M100
        /// </summary>
        /// <param name="address">要写入的数据地址</param>
        /// <param name="values">要写入的实际数据,可以指定任意的长度</param>
        /// <example>
        /// <code lang="cs" source="Communication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="WriteBool" title="Write示例" />
        /// </example>
        /// <returns>返回写入结果</returns>
        public OperateResult Write(string address, bool[] values)
        {
            OperateResult <byte[]> coreResult = MelsecHelper.BuildWriteBitCoreCommand(address, values, McAnalysisAddress);

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

            // 核心交互
            OperateResult <byte[]> read = ReadFromCoreServer(PackMcCommand(coreResult.Content, NetworkNumber, NetworkStationNumber));

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

            // 错误码校验
            ushort ErrorCode = BitConverter.ToUInt16(read.Content, 9);

            if (ErrorCode != 0)
            {
                return(new OperateResult <byte[]>(ErrorCode, StringResources.Language.MelsecPleaseReferToManulDocument));
            }

            // 成功
            return(OperateResult.CreateSuccessResult( ));
        }