Exemplo n.º 1
0
        /// <summary>
        /// 批量写入PLC的数据,以字为单位,也就是说最少2个字节信息,支持X,Y,M,S,D,T,C,具体的地址范围需要根据PLC型号来确认
        /// </summary>
        /// <param name="address">地址信息</param>
        /// <param name="value">数据值</param>
        /// <returns>是否写入成功</returns>
        public override OperateResult Write(string address, byte[] value)
        {
            // 获取指令
            var command = OmronFinsNetHelper.BuildWriteWordCommand(address, value, false);;

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

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

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

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

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

            // 成功
            return(OperateResult.CreateSuccessResult( ));
        }
Exemplo n.º 2
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 = OmronFinsNetHelper.BuildWriteWordCommand(address, values.Select(m => m ? (byte)0x01 : (byte)0x00).ToArray( ), true);;

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

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

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

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

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

            // 成功
            return(OperateResult.CreateSuccessResult( ));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据类型地址以及需要写入的数据来生成指令头
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="value">真实的数据值信息</param>
        /// <param name="isBit">是否是位操作</param>
        /// <returns>带有成功标志的报文数据</returns>
        public OperateResult <byte[]> BuildWriteCommand(string address, byte[] value, bool isBit)
        {
            var command = OmronFinsNetHelper.BuildWriteWordCommand(address, value, isBit);

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

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