汇川ModbusTCPAPI使用H5u_Read_Soft_Elem_Float读取浮点数值不对的解决方法
读取Float的方式如下:
byte[] pValue2 = new byte[4];
int nRet3 = H5u_Read_Soft_Elem(SoftElemType.REGI_H5U_D, 270, 4, pValue2, 0);
float nValue2 = BitConverter.ToSingle(pValue2, 0);
Debug.WriteLine(String.Format("H5u_Read_Soft_Elem【4】:{0}", nValue2));
读取Double的方式与Float相似,如下:
byte[] pValue = new byte[8];
int nRet2 = H5u_Read_Soft_Elem(SoftElemType.REGI_H5U_D, 270, 8, pValue, 0);
double nValue = BitConverter.ToDouble(pValue, 0);
Debug.WriteLine(String.Format("H5u_Read_Soft_Elem【8】:{0}", nValue));
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/18283992