LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

converting 4 bytes to float

Solved!
Go to solution
Highlighted

Dear all,

I have working RS485 network with PIC microcontrollers (master + 6 slaves). I intend to replace master with some hardware where LabVIEW would be installed. I already managed to put together test vi on PC with USB-FTDI-RS485 WE adapter, which is capable to communicate with one slave. Slave is responsible for meassuring of the consumption of electric energy and watter in my house.

The problem is in converting of recived data in byte array form to float form, it is not accurate enough. Attached picture shows which bytes aro for each varible and also shows what is correct values for kWh as also for m3. Please check also part of the vi, where converting take place. Jus have in mind that Microchip has diferent IEEE754 standard, where sign bit is shifted with exponent for one place.

Any suggestion or advice would be very appreciated.

 

Regards, Vlado

0 Kudos
Message 1 of 18
(3,229 Views)

Can you make a small example that contains the 2D array as default data (e.g. as a diagram constant) and the desired result. Looking at your big code gives me a hadeache (a severs case of sequenceitis and localitis Smiley Very Happy) and since we don't have you device, we cannot run it.

 

Conversion code seems a bit circuitous. Are you sure it is sound?

It seems you are using all bits, so how much more accurate are you expecting to get?


LabVIEW Champion Do more with less code and in less time
Message 2 of 18
(3,202 Views)

Hi Vlado,

 

when you use a tool which outputs non-standard numbers you should provide a manual with a good (!) description of that numeric format!

 

The standard way of typecasting 4 bytes to a SGL does not work with your example data:

check.png

(Using Reverse1DArray to swap byte order doesn't yield in an expected result, too.)

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 3 of 18
(3,192 Views)

USB adapter link: http://www.ftdichip.com/Products/Cables/USBRS485.htm

Their code sample was modified step by step to version 5 with help of some discusions from this forum.

Would you be so kind to change attached vi (your idea) and post it back so I can test it.

 

Refards, Vlado

0 Kudos
Message 4 of 18
(3,176 Views)

That link is just the USB to RS-485 converter.  It has nothing to do with the actual data you are transmitting.  How your floating point data is being encoded as 4 bytes on the PIC device you are communicating with is what matters.

Message 5 of 18
(3,164 Views)

Previous post was reply to Altenbach.

This one is reply to GerdW.

 

Sorry, you are right. Not enough informations from my side.

So, this is not standard IEEE754 conversion, where from MSB side first bit is sign bit, then eight bits for exponent and the rest of 23 bits for mantissa. Instead of this it is used Microchip conversion where from MSB side eight bits are used for exponent, then one bit for sign and rest of 23 bits same as before for mantissa. That's mostly all about my problem.

By the way, I am not a specialist in LabView.

 

Regards, Vlado

 

0 Kudos
Message 6 of 18
(3,153 Views)

Reply to RavensFan.

On PIC (slave) side variable is converted to byte array of 4 bytes.

RS485 transfer protocol: Master send to slave message of 8 bytes with slave addres and command for slave for respond. Slave compare addres and respond to master with it's status (first line of 8 bytes on the picture). Then master send new commnd for each byte of the variable. Becouse we have two variables (each contain 4 bytes) we have to repeat this proces 8 times.

File with precised description of this communication is attached, which is made by software "Serial Port Monitor" .

 

Regards, Vlado

0 Kudos
Message 7 of 18
(3,147 Views)
Solution
Accepted by topic author California_J
02-23-2016 12:37 PM

California_J wrote: Instead of this it is used Microchip conversion where from MSB side eight bits are used for exponent, then one bit for sign and rest of 23 bits same as before for mantissa.

Then this should work for you once you get the 4 bytes.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 8 of 18
(3,133 Views)

Hello crossrulz, would you be so kind to attach your vi here, becouse I have no idea how to build it.

 

Regards, Vlado

0 Kudos
Message 9 of 18
(3,123 Views)

@California_J wrote:

Hello crossrulz, would you be so kind to attach your vi here, becouse I have no idea how to build it.

 

Regards, Vlado


That is a Snippet! Drag it to your LabVIEW block diagram to import the code directly.

Cheers

CLASolidWorks CP Icon.png
--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'

Message 10 of 18
(3,115 Views)