輸入參數P1,P2代表PLC中浮點數儲存的兩個寄存器獲取的數據 ...
輸入參數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; }