输入参数P1,P2代表PLC中浮点数储存的两个寄存器获取的数据
public 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; }