/// <summary> /// 将指定的OperateResult类型转化 /// </summary> /// <param name="result">原始的类型</param> /// <param name="byteTransform">数据转换方法</param> /// <returns>转化后的类型</returns> public static OperateResult <ulong> GetUInt64ResultFromBytes(OperateResult <byte[]> result, IByteTransform byteTransform) { return(GetResultFromBytes(result, m => byteTransform.TransUInt64(m, 0))); }
/// <summary> /// 读取四个寄存器组成的ulong值 /// </summary> /// <param name="address">起始地址</param> /// <exception cref="IndexOutOfRangeException"></exception> /// <returns></returns> public ulong ReadUInt64(ushort address) { return(byteTransform.TransUInt64(ReadRegister(address, 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"); } }
/// <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"); }