C# Modbus协议中读取浮点数的操作方法
时间:2021-07-01 10:21:17
帮助过:286人阅读
static float GetFloat(
ushort P1,
ushort P2)
{
int intSign, intSignRest, intExponent, intExponentRest;
float faResult, faDigit;
intSign = P1 /
32768;
intSignRest = P1 %
32768;
intExponent = intSignRest /
128;
intExponentRest = intSignRest %
128;
faDigit = (
float)(intExponentRest *
65536 + P2) /
8388608;
faResult = (
float)Math.Pow(-
1, intSign) * (
float)Math.Pow(
2, intExponent -
127) * (faDigit +
1);
return faResult;
}
C# Modbus协议中读取浮点数的操作方法
标签:输入 nts plc float 浮点 int tsig 浮点数 short