/// <summary>
        /// 使用指定的类型写入指定的节点数据 -> Writes the specified node data with the specified type
        /// </summary>
        /// <param name="address">节点的名称 -> Name of the node </param>
        /// <param name="typeCode">类型代码,详细参见<see cref="AllenBradleyHelper"/>上的常用字段 ->  Type code, see the commonly used Fields section on the <see cref= "AllenBradleyHelper"/> in detail</param>
        /// <param name="value">实际的数据值 -> The actual data value </param>
        /// <param name="length">如果节点是数组,就是数组长度 -> If the node is an array, it is the array length </param>
        /// <returns>是否写入成功 -> Whether to write successfully</returns>
        public OperateResult WriteTag(string address, ushort typeCode, byte[] value, int length = 1)
        {
            OperateResult <byte[]> command = BuildWriteCommand(address, typeCode, value, length);

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

            OperateResult <byte[]> read = ReadFromCoreServer(command.Content);

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

            OperateResult check = CheckResponse(read.Content);

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

            return(AllenBradleyHelper.ExtractActualData(read.Content, false));
        }
        /// <summary>
        /// 批量读取数据信息,数据长度为读取的数组长度信息 -> Bulk read data information, data length for read array length information
        /// </summary>
        /// <param name="address">节点的名称 -> Name of the node </param>
        /// <param name="length">如果是数组,就为数组长度 -> In the case of arrays, the length of the array </param>
        /// <returns>带有结果对象的结果数据 -> Result data with result object </returns>
        public OperateResult <byte[]> Read(string[] address, int[] length)
        {
            // 指令生成 -> Instruction Generation
            OperateResult <byte[]> command = BuildReadCommand(address, length);

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

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

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

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

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

            // 提取数据 -> Extracting data
            return(AllenBradleyHelper.ExtractActualData(read.Content, true));
        }
        /// <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)
        {
            byte[] cip = AllenBradleyHelper.PackRequestWrite(address, typeCode, data, length);
            byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cip);

            return(OperateResult.CreateSuccessResult(AllenBradleyHelper.PackRequestHeader(0x6F, SessionHandle, commandSpecificData)));
        }
        /// <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"));
            }

            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)));
        }
 /// <summary>
 /// 获取卸载一个已注册的会话的报文 ->
 /// Get a message to uninstall a registered session
 /// </summary>
 /// <returns>字节报文信息 -> BYTE message information </returns>
 public byte[] UnRegisterSessionHandle( )
 {
     return(AllenBradleyHelper.PackRequestHeader(0x66, SessionHandle, new byte[0]));
 }
 /// <summary>
 /// 向PLC注册会话ID的报文 ->
 /// Register a message with the PLC for the session ID
 /// </summary>
 /// <returns>报文信息 -> Message information </returns>
 public byte[] RegisterSessionHandle( )
 {
     byte[] commandSpecificData = new byte[] { 0x01, 0x00, 0x00, 0x00, };
     return(AllenBradleyHelper.PackRequestHeader(0x65, 0, commandSpecificData));
 }