From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting 4 bytes to float

Solved!
Go to solution

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

Download All
0 Kudos
Message 1 of 18
(9,552 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 :D) 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?

Message 2 of 18
(9,525 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


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 18
(9,515 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
(9,499 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
(9,487 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
(9,476 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
(9,470 Views)
Solution
Accepted by topic author California_J

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 18
(9,456 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
(9,446 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


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

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


Message 10 of 18
(9,438 Views)