/// <summary>
        /// 创建一个写入的报文指令
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="typeCode">类型数据</param>
        /// <param name="data">数据</param>
        /// <returns>包含结果对象的报文信息</returns>
        public OperateResult <byte[]> BuildWriteCommand(string address, ushort typeCode, byte[] data)
        {
            byte[] cip = AllenBradleyHelper.PackRequestWrite(address, typeCode, data);
            byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(cip);

            return(OperateResult.CreateSuccessResult(AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build a read command bytes
        /// </summary>
        /// <param name="address">the address of the tag name</param>
        /// <param name="length">Array information, if not arrays, is 1 </param>
        /// <returns>Message information that contains the result object </returns>
        public OperateResult <byte[]> BuildReadCommand(string[] address, int[] length)
        {
            if (address == null || length == null)
            {
                return(new OperateResult <byte[]>("address or length is null"));
            }
            if (address.Length != length.Length)
            {
                return(new OperateResult <byte[]>("address and length is not same array"));
            }

            try
            {
                List <byte[]> cips = new List <byte[]>( );
                for (int i = 0; i < address.Length; i++)
                {
                    cips.Add(AllenBradleyHelper.PackRequsetRead(address[i], length[i]));
                }
                byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cips.ToArray( ));

                return(OperateResult.CreateSuccessResult(AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData)));
            }
            catch (Exception ex)
            {
                return(new OperateResult <byte[]>("Address Wrong:" + ex.Message));
            }
        }
        /// <summary>
        /// 创建一个读取的报文指令
        /// </summary>
        /// <param name="address">tag名的地址</param>
        /// <returns>包含结果对象的报文信息</returns>
        public OperateResult <byte[]> BuildReadCommand(string[] address)
        {
            List <byte[]> cips = new List <byte[]>( );

            foreach (var add in address)
            {
                cips.Add(AllenBradleyHelper.PackRequsetRead(add));
            }
            byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(cips.ToArray( ));

            return(OperateResult.CreateSuccessResult(AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a written message instruction
        /// </summary>
        /// <param name="address">The address of the tag name </param>
        /// <param name="typeCode">Data type</param>
        /// <param name="data">Source Data </param>
        /// <param name="length">In the case of arrays, the length of the array </param>
        /// <returns>Message information that contains the result object</returns>
        public OperateResult <byte[]> BuildWriteCommand(string address, ushort typeCode, byte[] data, int length = 1)
        {
            try
            {
                byte[] cip = AllenBradleyHelper.PackRequestWrite(address, typeCode, data, length);
                byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cip);

                return(OperateResult.CreateSuccessResult(AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData)));
            }
            catch (Exception ex)
            {
                return(new OperateResult <byte[]>("Address Wrong:" + ex.Message));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 使用CIP报文和服务器进行核心的数据交换
        /// </summary>
        /// <param name="cips">Cip commands</param>
        /// <returns>Results Bytes</returns>
        public OperateResult <byte[]> ReadCipFromServer(params byte[][] cips)
        {
            byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cips);
            byte[] command             = AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData);

            // 核心交互 -> Core Interactions
            OperateResult <byte[]> read = ReadFromCoreServer(command);

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

            // 检查反馈 -> Check Feedback
            OperateResult check = CheckResponse(read.Content);

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

            return(OperateResult.CreateSuccessResult(read.Content));
        }