LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

conversion of serial output (IEEE 754) to single

Hi,

I'm trying to read out the actual values of a MKS PR4000B pressure sensor. I managed to get a connection and read/write data to the device (using serial read/write), but I'm having trouble to convert the read output to a single.

The manual tells me the floating number is conform to IEEE 754, the response I get are 8 bytes: @head, actual value.byte3, actual value.byte2, 0x00, @head, actual value.byte1, actual value.byte0, 0x00

I would like to do a cast type to convert it (like in: http://forums.ni.com/ni/board/message?board.id=170&thread.id=195115&view=by_date_ascending&page=1), but never seem to get the right results.

HO\@ps@ should translate to something like 01.903

any ideas?

0 Kudos
Message 1 of 5
(3,609 Views)

What have you done so far?

 

If you're using serial read/write that means you're getting a string. There are 2 solutions:

  1. Assuming you read all 8 bytes: First thing you need to do is to get an array of bytes using the String to Byte Array function. This will allow you to pick off the bytes that are actually the data since for some stupid reason the sensor decides to chop up the number. Use Index Array to pick off the appropriate elements (actual vale.byte3, actual value.byte2,...). Then use Build Array to get an array of bytes that's your number. Then just use TypeCast to cast that array into a SGL number.
  2. Read 4 bytes at a time. This will give you 2 strings, each 4 characters long. You only want the middle 2 characters from each one, so you can use the string functions to get those. Then, concanenate the 2 pieces you extracted, and TypeCast that to an SGL. 
I would give you the code, but I pretty much told you what you need to do, and besides you learn so much more if you try to do it yourself. Smiley Wink
0 Kudos
Message 2 of 5
(3,603 Views)

Perhaps you can post the code you have so far?

 

What is @head?  Some sort of header byte?

 

If so, why are the 4 bytes separated into two groups with a header and a 00 hex byte?

 

Perhaps you aren't stripping the correct bytes out of the string you got before feeding them into the typecast function.

 

Please post some actual byte data that your receive from the sensor (such as a string indicator set for hex display.)  The 8 characters you listed, none of them are 00 hex.  But I don't know that  00 hex would show up at all on a webpage.  That's why a VI with the data saved in a control, indicator or constant would be better.

Message Edited by Ravens Fan on 03-05-2009 10:01 AM
0 Kudos
Message 3 of 5
(3,603 Views)

Here is a VI that converts your string into a Single .

  Convert

Message Edited by VADave on 03-05-2009 11:50 AM
Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
Download All
0 Kudos
Message 4 of 5
(3,573 Views)
So much for the person doing it themselves.... Smiley Very Happy
0 Kudos
Message 5 of 5
(3,565 Views)