public System.Single GetFloatValue(int index, bool byteSwap, bool wordSwap) { var data = new byte[] { Data[index], Data[index + 1], Data[index + 2], Data[index + 3] }; var highWord = ushort.MinValue; var lowWord = ushort.MinValue; if (!byteSwap) { var words = MODBUSConverter.NetworkBytesToHostUInt16(data); highWord = words[1]; lowWord = words[0]; } else { highWord = BitConverter.ToUInt16(data, 2); lowWord = BitConverter.ToUInt16(data, 0); } var highWordBytes = BitConverter.GetBytes(highWord); var lowWordBytes = BitConverter.GetBytes(lowWord); if (!wordSwap) { return(BitConverter.ToSingle(new byte[] { highWordBytes[0], highWordBytes[1], lowWordBytes[0], lowWordBytes[1] }, 0)); } else { return(BitConverter.ToSingle(new byte[] { lowWordBytes[0], lowWordBytes[1], highWordBytes[0], highWordBytes[1] }, 0)); } }
public System.Int16 GetShortValue(int index, bool byteSwap) { var data = new byte[] { Data[index], Data[index + 1] }; var word = ushort.MinValue; if (!byteSwap) { var words = MODBUSConverter.NetworkBytesToHostUInt16(data); word = words[0]; } else { word = BitConverter.ToUInt16(data, 0); } return((Int16)word); }