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
"Doug (CapeFl)" wrote in message news:<[email protected]>...
> 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
Similar Messages
-
Single precision integer to 8 digit hex string
I need to convert a single precision integer to a MSB-LSB 8 digit hex string to send to a test machine via RS-232. So 15 needs to turn into 41700000. The best I have been able to do is get 15 to turn into 0000000F, which is correct but not in the MSB-LSB format I need. Any ideas?
Just typecast the SGL to U32 and format it with %08x.
Message Edited by altenbach on 05-30-2007 08:49 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
SGL-to-HEXstring.vi 8 KB
SGL-to-HEXstring.png 6 KB -
Single Precision Floating Point Numbers to Bytes
Ok here is some code that i have written w hile back with some help from the support staff. It is designed to take in precision floating point numbers that are stored as 4 bytes and convert then to a decimal value. It works off of a udp input string and then also reformats the string. I have the ability to look at up to 4000 parameters from this one udp string. But now what i want to do is do the opposite of what i have written, and also perhaps get rid of the matlab i used in it as well. What i would like to be able to do is input a decimal value and then have it converted in to the 4 byte groupings that make up this decimal nd then have it inputed back in to a single long string witht hat grouping of bytes in the right order. A better explanation of what was done can be found on this website
http://www.jefflewis.net/XPlaneUDP_8.html
as the original code followed the "Single Precision Floating Point Numbers and Bytes" example on that site but what i want to do is "Going from Single Precision Floating Point Numbers to Bytes". The site also explains the udp string that is being represented. Also attached is the original code that i am trying to simply reverse.
Attachments:
x-plane_udp_master.vi 34 KBPerhaps what you are doing is an exercise in the programming of the math conversion of the bytes.
But if you are just interested in getting the conversion done, why not use the typecast function?
If the bytes happen to be in the wrong order for wherever you need to send the string, then you can use string functions to rearrange them.
Message Edited by Ravens Fan on 10-02-2007 08:50 PM
Attachments:
Example_BD.png 3 KB -
Can someone explain why doing a floating point conversion compromises digit of precision accuracy? For example, if I wire the double precision number "16.0001000" to the "to Single Precision Float" vi input, the output is "16.0000991".
I have an application in which this level of accuracy is critical. I can think of several work arounds, but I still would like a good explanation for why this is the case.
pmacJust use array to spreadsheet string on the DBL and write as text file (and an analogous operation for reading, converting back to DBL). Alternatively, you could make DBL version of "read/write spreadheet file" by editing them slightly and saving them under a new name elsewhere. Make sure to change the icon too, e.g. give it a different color.
If precision is that important, you might want to use binary files. The don't have any formatting loss at all.
Of course if this is just measurement data, don't be fooled by fake precision. even SGL has a 22 bit mantissa, so if your DAQ hardware acqures in 16 bits, SGL is plenty.
LabVIEW Champion . Do more with less code and in less time . -
How to concatenate a string with single quotes
Hi all,
how to concatenate a string with single quotes to a variable.
SathyaHi sathyabama,
1. simple
2. use TILDE character <b>(`)</b>
(just left to the '1' key)
<b> `'mystring'`</b>
3. just copy paste
report abc.
data : m(100) type c.
concatenate `'amit mittal'` 'hello' into m separated by space.
write m.
regards,
amit m. -
Writing to spread sheets with more than single precision
Hi everyone,
Im recording data by using the write to spread sheet VI in Labview 8,
it records single precision which is a problem for me as I require greater
precision.
Are there ways around this issue?
Thanks
Solved!
Go to Solution.What do you mean by this? Is it possible for you to post code which only shows what you are trying to explain?
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies -
Storing analog output data in a datatype other than single-precision
I'm using three PCI-6713 AO cards in a single computer to output 24 channels of data using Labview 6.1. The input terminals of all the analog output VI's are of type single precision (32-bit). The output cards only have 12-bit DAC's, so there is a large amount of information stored that is never used by the cards. Is there a way in Labview to store AO data in another, smaller datatype - such as a 16-bit integer. This would greatly reduce the memory requirements for my application.
I just figured out the answer to my own question. There isn't an option for binary in the AO Write vi, but if you go down to the AO Buffer Write vi (which is called by AO Write), you can select binary array.
Thanks for all your help.
Josh -
Replace multiple whitespaces in a string with single one
Hi,
I'm using Oracle 9.2.0 and I have a query on string manipulation.
Can I replace multiple whitespaces within a string with single one. I tried with regexp_replace function but it is not supporting Oracle 9i.
Can someone help me out?
Regards,
PramodJust playing around:
WITH
Strings
AS
SELECT 'Can I replace multiple whitespaces within a string with single one' Text FROM Dual
SELECT
REPLACE
REPLACE
XMLAGG
XMLElement
"A",
SubStr(Text, Level, 1)
'</A>'
'<A>'
) Text
FROM
Strings
WHERE
NOT
Level > 1
AND SubStr(Text, Level, 1) = ' '
AND SubStr(Text, Level - 1, 1) = ' '
CONNECT BY
Level <= LENGTH(Text); -
How to Splilit The String Into Single Column using Comma As Delimiter ?
How to Splilit The String Into Single Column using Comma As Delimiter ?
using Functionrefer my thread ,code is also available see if that helps you
error while executing the sp ORA-21779: duration not active -
Single precision constant changes value
See attached "vi". If I put a double precison numeric on my block diagram, change it to SINGLE precision, then enter the value .001 into it, it adds values to the far right of the decimal. Why is it doing this? I'm using Labview 2011 SP1.
Solved!
Go to Solution.
Attachments:
precision.vi 5 KBPosting by phone and just taking a guess.
The precision is defined in bits and many fractional values don't have an exact decimal translation.
For example 0.001 cannot be represented exactly in sgl or dbl.
This is inherent to the floating point representation and not language specific. You simply get the closest possible value. Set it back to DBL and change the format to show 20 decimal digits. Same difference.
LabVIEW Champion . Do more with less code and in less time . -
I am using the dynamic signal analyzer.vi but this vi has the output as single precision. How can I change this to DBL precision? If I change the representation from single to double in the AI buffer read.vi labview returns ilegal operation and crash. I have labview 5.1 on windows 95 and one AT-MIO16XE50 DAQ board.
Thanks in advance
Ricardo.Probably by changing the data type that lvdaq.dll expects to write to is causing the crash. I can't test this since I have only 6.1 installed now. In any case, since the daq card is only 16 bits, the single precision is probably adequate for AI Buffer Read. If you do need the greater precision later on, you should be able to change representation in any one of the upper level VIs.
-
Need a single-precision/2-byte conversion tool
Any one have a utility to convert 4-byte single precision numbers to and from a 2-byte representation?
I only need 3 digits, with one fractional digit (-14.3, for example).
Thanks...At one time I thought I wanted to do this, but never got around to it. I did find this information useful, however.
http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf -
Single Precision "3D Cartesian Coordinate Rotation (Direction) (Array)"
Hi there
I am using "3D Cartesian Coordinate Rotation (Direction) (Array).vi" but this VI used Double Precision XYZ numbers.
Is there equivalent in Single Precision?
My reason is to save memory space and time. I am already using 64-bits LabVIEW with 16 GB or RAM.
LabVIEW 2013
Thank you
PeterNo, unfortunately LabVIEW provides very few Single Precision VIs (see my idea here). You might have success by reimplementing it yourself (it's just a matrix multiplication - look in the Help), and using the Multicore Analysis and Sparse Matrix Toolkit which does provide both SGL and DBL paralellized forms of most of the Linear Algebra VIs, among other things.
-
Single precision to hex string
Hello,
I was wondering how to typecast a SGL Or DBL into a hex string? I tried number to hex, and format into string, etc but can't seem to figure it out.
The stirring doesnt need a sgl/dbl and is fine but the heating needs to work at a decimal point. since the device must multiply the heating by 10 (inputting 80 degrees gives out 800 to the device and it sets it to 80 degrees) turning it into a hex string shouldn't be a problem but i can't seem to figure this out.
Any help would be appreciated.
Thanks
Attachments:
single to hex.JPG 33 KBI meant like this which most closely represents what you did for the U16 conversion at the bottom half of your code.
Attachments:
Example_VI.png 15 KB -
Hi,
I'm running 32-bit version of SQL Developer v. 3.2.20.09 build 09.87, and I used the built in context menu (right-clicking from the schema browser) today to copy a table. However, none of the comments copied. When I dug into the PL/SQL that the menu-item is using, I realized that it fails because it doesn't handle single quotes within the comment string.
For example, I have a table named WE_ENROLL_SNAPSHOT that I wanted to copy as WE_ENROLL_SNAPSHOT_V1 (within same schema name)
1. I right-clicked on the object in the schema browser and selected Table > Copy...
2. In the pop-up Copy window, I entered the new table name "WE_ENROLL_SNAPSHOT_V1" and ticked the box for "Include Data" option. -- The PL/SQL that the menu-command is using is in the "SQL" tab of this window. This is what I extracted later for testing the issue after the comments did not copy.
Result: Table and data copied as-expected, but no column or table comments existed.
I examined the PL/SQL block that the pop-up window issued, and saw this:
declare
l_sql varchar2(32767);
c_tab_comment varchar2(32767);
procedure run(p_sql varchar2) as
begin
execute immediate p_sql;
end;
begin
run('create table "BI_ETL".WE_ENROLL_SNAPSHOT_V1 as select * from "BI_ETL"."WE_ENROLL_SNAPSHOT" where '||11||' = 11');
select comments into c_tab_comment from sys.all_TAB_comments where owner = 'BI_ETL' and table_name = 'WE_ENROLL_SNAPSHOT' and comments is not null;
run('comment on table BI_ETL.WE_ENROLL_SNAPSHOT_V1 is '||''''||c_tab_comment||'''');
for tc in (select column_name from sys.all_tab_cols where owner = 'BI_ETL' and table_name = 'WE_ENROLL_SNAPSHOT')
loop
for c in (select comments from sys.all_col_comments where owner = 'BI_ETL' and table_name = 'WE_ENROLL_SNAPSHOT' and column_name=tc.column_name)
loop
run ('comment on column BI_ETL.WE_ENROLL_SNAPSHOT_V1.'||tc.column_name||' is '||''''||c.comments||'''');
end loop;
end loop;
EXCEPTION
WHEN OTHERS THEN NULL;
end;
The string of the table comment on WE_ENROLL_SNAPSHOT is this:
WBIG table of frozen, point-in-time snapshots of Enrolled Students by Category/term/pidm. "Category" is historically, and commonly, our CENSUS snapshot; but, can also describe other frequencies, or categorizations, such as: End-of-Term (EOT), etc. Note: Prior to this table existing, Census-snapshots were stored in SATURN.SNAPREG_ALL. All FALL and SPRING term records prior-to-and-including Spring 2013 ('201230') have been migrated into this table -- EXCEPT a few select prior to Fall 2004 (200410) records where there are duplicates on term/pidm. NO Summer snapshots existed in SNAPREG_ALL, but were queried and stored retroactively (including terms prior to Spring 2013) for the purpose of future on-going year-over-year analysis and comparison.
Note the single quotes in the comment: ... ('201230')
So, in the above PL/SQL line 11 grabs this string into "c_tab_comment", but then line 12 fails because of the single quotes. It doesn't know how to end the string because the single quotes in the string are not "escaped", and this messes up the concatenation on line 12. (So, then no other column comments are created either because the block throws an error, and goes to line 22 for the exception and exits.)
When I modify the above PL/SQL as my own anonymous block like this, it is successful:
declare
c_tab_comment VARCHAR2(32767);
begin
SELECT REPLACE(comments,chr(39),chr(39)||chr(39)) INTO c_tab_comment FROM sys.all_TAB_comments WHERE owner = 'BI_ETL' AND table_name = 'WE_ENROLL_SNAPSHOT' AND comments IS NOT NULL;
EXECUTE IMMEDIATE 'comment on table BI_ETL.WE_ENROLL_SNAPSHOT_V1 is '''||c_tab_comment||'''';
for tc in (select column_name from sys.all_tab_cols where owner = 'BI_ETL' and table_name = 'WE_ENROLL_SNAPSHOT')
loop
for c in (select REPLACE(comments,chr(39),chr(39)||chr(39)) comments from sys.all_col_comments where owner = 'BI_ETL' and table_name = 'WE_ENROLL_SNAPSHOT' and column_name=tc.column_name)
loop
EXECUTE IMMEDIATE 'comment on column BI_ETL.WE_ENROLL_SNAPSHOT_V1.'||tc.column_name||' is '||''''||c.comments||'''';
end loop;
end loop;
EXCEPTION
WHEN OTHERS THEN NULL;
end;
On lines 4 and 8 I wrapped the "comments" from sys.all_tab_comments and sys.all_col_comments with a replace command finding every chr(39) and replacing with chr(39)||chr(39). (On line 8 I also had to alias the wrapped column as "comments" so line 10 would succeed.)
Is this an issue with SQL Developer? Is there any chance that the menu-items can handle single quotes in comment strings? ... And, of course this makes me wonder which other context menu commands in the tool might have a similar issue.
Thoughts?
thanks//jacobPaigeT wrote:
I know about quick drop, but it isn't helpful here. I want to be able to right click on a string or array wire, navigate to the string or array palette, and select the corresponding "Empty?" comparator. In this case, since I do actually know where those functions live, and I'm already using my mouse to right click on the wire, typing ctrl-space to open quick drop and then typing in the function name is actually more work than navigating to it in the palette. It would just be nice to have it on hand in the location I naturally go to look for it the first time.
I don't agree with this work flow. Right hand on mouse, left hand on home keys. Pressing CTRL + Space is done with the left hands, and then you could assign "ea" to "Empty Array" both of which is accessible with the left hand. Darren posted a bunch of great shortcuts for the right handed developer.
https://decibel.ni.com/content/docs/DOC-20453
This is much faster than waiting for any right click menu navigation, even if it is found in the suggested subpalette.
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
Maybe you are looking for
-
Can I connect more than one iPod to iTunes?
I've recently bought a iPod photo for myself but my other half want a iPod mini. The trouble is I've only got 1 PC and my iPod is 60gb which can hold a few songs whilst hers wil only be 4GB. If so, can you have diffrent folders for when I want to upd
-
I have a desktop Power PC running OSX 10.4.6. I upgraded iTunes to version 7.6.1 which will not open now. The warning window says I need OSX 10.4.9 or latter to use it. EXCEPT when I down load the new OSX 10.11 or the combo of that I get a warning sa
-
Safari + Silverlight + Full screen = MBP suddenly shuts off and restarts
In the past few weeks, my MacBook Pro has unexpectedly shut off and then started back up three times. Each time it happened while I was watching full-screen Silverlight video in Safari (4.0.3) - twice on the Netflix website and once on the NBC Sports
-
I seem to have missing some of my notes. This is on MacPro, iPad and iPhone. They were defaulting to goggle mail but are no where now. Checked with the account and not there. Any help where to look and why this happened. Thanks, Sylvia
-
Go to this page: http://thedecoartist.com/ARCHERwebsite/CAT_USinteriorDetails.html In Dreamweaver I cannot select any text in the far right two columns of the table with the text cursor. The only way I can either edit or enter text into those two col