AnsweredAssumed Answered

Converting ViReal64 to double in C

Question asked by DanielRhodin on May 11, 2011
Latest reply on May 12, 2011 by DanielRhodin

Using the 34410A DMM, I'm using the R? command to fetch an array of values from the instrument. When setting the format type to ASCII, conversion to a C# double value is easy of course [double.Parse(string s)], however, setting the instrument to "FORM:DATA REAL,64 gives the values in a ViReal64 format, which is said to be a 8 byte floating number.

When fetching a byte array from the instrument, the returned format will be;
#210xxxxxxxxxxxx[...], where the # tells my parser to expect a definite length block, the first digit gives the length of the header, and the following digits gives the actual count of ViReal64 values.

Then I'm trying to convert the first 8 bytes to a value, using the following code snippet:
List<double> result = new List<double>();

     for(int i = 0;i<b.Length;i+=8)
            result.Add(System.BitConverter.ToDouble(b, i));

The results are not correct after this operation, which I assume is related to a difference in implementation.

I am aware of the IFormattedIO488.ReadIEEEBlock() method, but for implementation-specific reasons I would like to try to avoid using that.

Question is; how do I convert a ViReal64 number, stored as a byte[8] into a C# double value? Any hints on how to solve this issue is welcome, as the transfer time is significantly lower using REAL values compared to ASCII.

Daniel Rhodin