public int others        = 0;  // 自定义的其他信息



            public void ParseSource(byte[] Content)
            {
                temperature = byteTransform.TransInt16(Content, 0);
                press       = byteTransform.TransSingle(Content, 2);
                others      = byteTransform.TransInt32(Content, 6);
            }
 /// <summary>
 /// 将指定的OperateResult类型转化
 /// </summary>
 /// <param name="result">原始的类型</param>
 /// <param name="byteTransform">数据转换方法</param>
 /// <returns>转化后的类型</returns>
 public static OperateResult <int> GetInt32ResultFromBytes(OperateResult <byte[]> result, IByteTransform byteTransform)
 {
     return(GetResultFromBytes(result, m => byteTransform.TransInt32(m, 0)));
 }
 /// <summary>
 /// 读取两个寄存器组成的int值
 /// </summary>
 /// <param name="address">起始地址</param>
 /// <exception cref="IndexOutOfRangeException"></exception>
 /// <returns>int值</returns>
 public int ReadInt32(ushort address)
 {
     return(byteTransform.TransInt32(ReadRegister(address, 2), 0));
 }
Esempio n. 4
0
 public dynamic GetValue(byte[] data, IByteTransform byteTransform)
 {
     if (RegularCode == RegularNodeTypeItem.Int16.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransInt16(data, Index));
         }
         else
         {
             return(byteTransform.TransInt16(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.UInt16.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransUInt16(data, Index));
         }
         else
         {
             return(byteTransform.TransUInt16(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.Int32.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransInt32(data, Index));
         }
         else
         {
             return(byteTransform.TransInt32(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.UInt32.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransUInt32(data, Index));
         }
         else
         {
             return(byteTransform.TransUInt32(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.Int64.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransInt64(data, Index));
         }
         else
         {
             return(byteTransform.TransInt64(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.UInt64.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransUInt64(data, Index));
         }
         else
         {
             return(byteTransform.TransUInt64(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.Float.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransSingle(data, Index));
         }
         else
         {
             return(byteTransform.TransSingle(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.Double.Code)
     {
         if (TypeLength == 1)
         {
             return(byteTransform.TransDouble(data, Index));
         }
         else
         {
             return(byteTransform.TransDouble(data, Index, TypeLength));
         }
     }
     else if (RegularCode == RegularNodeTypeItem.StringAscii.Code)
     {
         return(Encoding.ASCII.GetString(data, Index, TypeLength));
     }
     else
     {
         throw new Exception("Not Supported Data Type");
     }
 }
Esempio n. 5
0
        /// <summary>
        ///     获取当前的数据信息实际值
        /// </summary>
        /// <param name="data"></param>
        /// <param name="byteTransform"></param>
        /// <returns></returns>
        public dynamic GetValue(byte[] data, IByteTransform byteTransform)
        {
            if (RegularCode == RegularNodeTypeItem.Bool.Code)
            {
                if (TypeLength == 1)
                {
                    var tmp = SoftBasic.ByteToBoolArray(data, data.Length * 8);
                    return(tmp[Index]);
                }
                else
                {
                    var tmp   = SoftBasic.ByteToBoolArray(data, data.Length * 8);
                    var array = new bool[TypeLength];
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = tmp[Index + i];
                    }
                    return(array);
                }
            }

            if (RegularCode == RegularNodeTypeItem.Int16.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransInt16(data, Index));
                }
                return(byteTransform.TransInt16(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.UInt16.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransUInt16(data, Index));
                }
                return(byteTransform.TransUInt16(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.Int32.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransInt32(data, Index));
                }
                return(byteTransform.TransInt32(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.UInt32.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransUInt32(data, Index));
                }
                return(byteTransform.TransUInt32(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.Int64.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransInt64(data, Index));
                }
                return(byteTransform.TransInt64(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.UInt64.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransUInt64(data, Index));
                }
                return(byteTransform.TransUInt64(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.Float.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransSingle(data, Index));
                }
                return(byteTransform.TransSingle(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.Double.Code)
            {
                if (TypeLength == 1)
                {
                    return(byteTransform.TransDouble(data, Index));
                }
                return(byteTransform.TransDouble(data, Index, TypeLength));
            }

            if (RegularCode == RegularNodeTypeItem.StringAscii.Code)
            {
                return(Encoding.ASCII.GetString(data, Index, TypeLength));
            }
            throw new Exception("Not Supported Data Type");
        }