ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

cast string to single precision

Hi,

I try to write a communication between a PC and a DSP which is
programmed to
understand some kind of ModBus. I tried to use MBmaster.vi, a freeware
of AIRtech in the netherlands.
I was successfull to 90% after a very short time - I get back a string
from the DSP which makes sense.
The only problem is to *convert* the 4Byte=8Hex=32Bits(=IEEE754 single
precision format) into the LabView single precision number it does
represent .

In other programming languages like C I think I could do this easily
on a very low level procedure or with one of these dangerous casts.
As a newbie to LabView I could not found neither one VI to do this or
find out which simple combination of VIs could solve the problems.

Are there any cracks
here who know *the* easy solution??

Thanx & Regards
Urs Bögli
0 Kudos
Message 1 of 7
(3,844 Views)
Did you check the VI functions under Functions>String>Additional String to Number Functions?
There are quite a few for converting to/from Hex, etc. I've used them for concatenating 4-bit strings into an 8-bit string (to get an 8-bit byte/word), also converting to/from Hex using some of the VIs I mentioned.
Good Luck, Doug
0 Kudos
Message 2 of 7
(3,844 Views)
"Doug (CapeFl)" wrote in message news:<5065000000050000001C310000-991728092000@quiq.com>...
> Did you check the VI functions under Functions>String>Additional
> String to Number Functions?
> There are quite a few for converting to/from Hex, etc. I've used them
> for concatenating 4-bit strings into an 8-bit string (to get an 8-bit
> byte/word), also converting to/from Hex using some of the VIs I
> mentioned.
> Good Luck, Doug

Dough,
as a programmer for twenty years I have some problems to understand the way
labview does work with types and casts - other languages are much clearer about it
- or have I not found the ultimative help area yet ???

May I ask you to send me the VI off list?

thanks
Urs
0 Kudos
Message 3 of 7
(3,844 Views)
The Type Cast function is located in the palette Functions/Advanced/Data
Manipulation.

Wire the 4 bytes string to the "x" input and a SGL number to the type input.
It will output the string type casted to a SGL number.

Jean-Pierre Drolet


LabVIEW, C'est LabVIEW

Message 4 of 7
(3,844 Views)
Urs,

I think the best approach would be to use the type casting vi. This is found on the function palette under advanced -> data manipulation. You simply wire in the string into the "x" input, an SGL integer into the "type" input, and the resulting "*(type*)&x" output should be in the format you want. Additionally, the string/number conversion vi's can be very helpful as well.

Best Regards,

Eric Enger
0 Kudos
Message 5 of 7
(3,844 Views)
Eric,
thanks a lot for this hint. After I ve brought the information into
the correcr order(lsb was at the start first...) I only had to add the
cast VI - thats simple and stupid, but not too much 😉
Best Regards
Urs



> Urs,
>
> I think the best approach would be to use the type casting vi. This
> is found on the function palette under advanced -> data manipulation.
> You simply wire in the string into the "x" input, an SGL integer into
> the "type" input, and the resulting "*(type*)&x" output should be in
> the format you want. Additionally, the string/number conversion vi's
> can be very helpful as well.
>
> Best Regards,
>
> Eric Enger
0 Kudos
Message 7 of 7
(3,844 Views)
Urs, based on all the other helpful inputs, there is a solution, in fact, more than 1.
I've attached a vi that should fit various needs, or at least give some clues...
Doug
0 Kudos
Message 6 of 7
(3,844 Views)