/// <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 byte[] RegisterSessionHandle()
 {
     byte[] buffer1 = new byte[4];
     buffer1[0] = 1;
     byte[] commandSpecificData = buffer1;
     return(AllenBradleyHelper.PackRequestHeader(0x65, 0, commandSpecificData));
 }
예제 #4
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));
     }
 }
예제 #5
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)));
        }
 /// <summary>
 /// 获取卸载一个已注册的会话的报文
 /// </summary>
 /// <returns>字节报文信息</returns>
 public byte[] UnRegisterSessionHandle( )
 {
     return(AllenBradleyHelper.PackRequestHeader(0x66, SessionHandle, new byte[0]));
 }
 /// <summary>
 /// 向PLC注册会话ID的报文
 /// </summary>
 /// <returns>报文信息</returns>
 public byte[] RegisterSessionHandle( )
 {
     byte[] commandSpecificData = new byte[] { 0x01, 0x00, 0x00, 0x00, };
     return(AllenBradleyHelper.PackRequestHeader(0x65, 0, commandSpecificData));
 }