/// <summary>
        /// 创建一个写入的报文指令
        /// </summary>
        /// <param name="address">起始地址</param>
        /// <param name="typeCode">类型数据</param>
        /// <param name="data">数据</param>
        /// <param name="length">如果是数组,就为数组长度</param>
        /// <returns>包含结果对象的报文信息</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)));
        }
예제 #2
0
 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[]> list = new List <byte[]>();
         for (int i = 0; i < address.Length; i++)
         {
             list.Add(AllenBradleyHelper.PackRequsetRead(address[i], length[i]));
         }
         byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, list.ToArray());
         return(OperateResult.CreateSuccessResult <byte[]>(AllenBradleyHelper.PackRequestHeader(0x6f, SessionHandle, commandSpecificData)));
     }
     catch (Exception exception)
     {
         return(new OperateResult <byte[]>("Address Wrong:" + exception.Message));
     }
 }
예제 #3
0
 public OperateResult <byte[]> BuildWriteCommand(string address, ushort typeCode, byte[] data, int length = 1)
 {
     try
     {
         byte[]   buffer = AllenBradleyHelper.PackRequestWrite(address, typeCode, data, length);
         byte[][] cips   = new byte[][] { buffer };
         byte[]   commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cips);
         return(OperateResult.CreateSuccessResult <byte[]>(AllenBradleyHelper.PackRequestHeader(0x6f, SessionHandle, commandSpecificData)));
     }
     catch (Exception exception)
     {
         return(new OperateResult <byte[]>("Address Wrong:" + exception.Message));
     }
 }
예제 #4
0
        public OperateResult <byte[]> ReadCipFromServer(params byte[][] cips)
        {
            byte[] commandSpecificData = AllenBradleyHelper.PackCommandSpecificData(Slot, cips);
            byte[] send = AllenBradleyHelper.PackRequestHeader(0x6f, SessionHandle, commandSpecificData);
            OperateResult <byte[]> result = base.ReadFromCoreServer(send);

            if (!result.IsSuccess)
            {
                return(result);
            }
            OperateResult result2 = CheckResponse(result.Content);

            if (!result2.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(result2));
            }
            return(OperateResult.CreateSuccessResult <byte[]>(result.Content));
        }
        /// <summary>
        /// 创建一个读取的报文指令
        /// </summary>
        /// <param name="address">tag名的地址</param>
        /// <param name="length">数组信息,如果不是数组,就都为1</param>
        /// <returns>包含结果对象的报文信息</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)));
        }