汇川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));
posted @ 2024-07-04 15:44  ꧁执笔小白꧂  阅读(307)  评论(0)    收藏  举报