예제 #1
0
 /// <summary>
 /// Extract actual data form plc response
 /// </summary>
 /// <param name="response">response data</param>
 /// <param name="isRead">read</param>
 /// <returns>result</returns>
 public static OperateResult <byte[]> ExtractActualData(byte[] response, bool isRead)
 {
     try
     {
         if (isRead)
         {
             if (response[0] == 0x06)
             {
                 byte[] buffer = new byte[response.Length - 13];
                 Array.Copy(response, 10, buffer, 0, buffer.Length);
                 return(OperateResult.CreateSuccessResult(SoftBasic.AsciiBytesToBytes(buffer)));
             }
             else
             {
                 byte[] buffer = new byte[response.Length - 9];
                 Array.Copy(response, 6, buffer, 0, buffer.Length);
                 return(new OperateResult <byte[]>(BitConverter.ToUInt16(SoftBasic.AsciiBytesToBytes(buffer), 0), "Data:" + SoftBasic.ByteToHexString(response)));
             }
         }
         else
         {
             if (response[0] == 0x06)
             {
                 return(OperateResult.CreateSuccessResult(new byte[0]));
             }
             else
             {
                 byte[] buffer = new byte[response.Length - 9];
                 Array.Copy(response, 6, buffer, 0, buffer.Length);
                 return(new OperateResult <byte[]>(BitConverter.ToUInt16(SoftBasic.AsciiBytesToBytes(buffer), 0), "Data:" + SoftBasic.ByteToHexString(response)));
             }
         }
     }
     catch (Exception ex)
     {
         return(new OperateResult <byte[]>(ex.Message));
     }
 }