How to parse 16 bit signed integer

Currently, I am attempting to collect meaningful data from a flow meter
connected through serial communication (RS-232 port).  The
received data is a 16 bit signed integer in two's complement
representation i.e. the 16 bit signed integer is in binary format with
2 bytes synchronization  preceding. 
For each value from the flow meter the byte sequence recevied is as
follows:  0x7F (sync) , 0x7F (sync) , MSB , LSB.  When
parsing, I would like to ignore the buffers and store/convert the
correct values from the flow meter into decimals, but I do not know how
to do that.  I attempted to use Instrument I/O Assistant and the
programming similar to it, but I don't know how to identify the buffers
as seperators. 
Do any of you know how to do this?  Let me know if you need more information. Your help will be most appreciated. 

Well, cast the entire string as an array of U32, use "split numbers" to get the last 16 bits each, cast to I16.
(look ma, no loops! )
Message Edited by altenbach on 10-12-2005 09:57 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
cast.png ‏3 KB

Similar Messages

  • How to scale 32-bit signed integer data to floating-p​oint voltage when acquring data in DAQmx by PXI4472?

    I acquired data in DAQmx by PXI4472. For the high speed data logger, I used "DAQmx Read" to read unscaled 32-bit signed integer data.
    Now, my question is how to scale 32-bit signed integer data to floating-point voltage?
    I think that it's (20/(2**24))*I32 because the voltage range of PXI4472 is -10 to +10 and its resolution is 24 bits. But I cann't get correct voltage by that formula.

    While you could hard code the scaling factor, it will be more flexible if you retrieve the scaling coefficients from the driver. To do this, you need to use the Analog Input>>General Properties>>Advanced>>Device Scaling Coefficients>>Device Scaling Coefficients properties under the DAQmx Channel Property Node. Look at the documentation for this property to see how it can be used to create a polynomial equation for scaling to volts.
    Since you are creating a data logging solution, you may want to consider using a compressed data stream from the driver instead of the I32 data type. This will allow you to read the data back as a stream of u8's instead. Since the PXI-4472 is 24 bits, you will only have to write 3 bytes to disk for each sample instead of 4. You can check out the following examples for how to create an application using this compressed data stream. It also shows how to use the scaling coefficients to transform the unscaled data back to voltage values.

  • How to read 16-bit signed integer in binary format with 2 byte sync. preceding??

    A flowmeter provides data as 16-bit signed integer in binary format with 2 byte sync. preceding
    I got i small problem by understanding the synchronasation.
    I read the data provided by the flowmeter, and then write it to a binaryfile.dat. i need to convert the data to decimal format. is it better to convert the data before or after writing it to the binary file. Coz i need to read the data out again for calculations and save it again in a new file.
    I understand that the synchronization  help one to see where to begin reading the usable data. is it right?
    Need any suggestions
    Thank you !
    Zamzam
    HFZ
    Attachments:
    DataOut.JPG ‏37 KB

    HI Rolf.k.
    Thank you for the small program it was helpfull.
    You got right about that proberly there  will be conflict with some spurios data, I can already detect that when writing the data to a spreadsheet file.
    I writes the data in such a way, that in each line there will be a date, a timestamp, a tab and a timestamp at the end. That means two columns.
    When i set given samplerate up, that controls the rate of the data outflow from the device, (1,56 Hz - 200 Hz),   the data file that i write to , looks unorderet.
     i get more than one timestamp and severel datavalues in every line and so on down the spreadsheet file.
    Now the question is: Could it be that the function that writes the data to the file,  can't handle the speed of the dataflow in such a way that the time stamp cant follow with the data flowspeed. so i'm trying to set the timestamp to be  with fractions of the seconds by adding the unit (<digit>) in the timestamp icon but its not working. Meaby when i take the fractions off a second within the timestamp i can get every timestamp with its right data value. Am i in deeb water or what do You mean!??
    AAttached Pics part of program and a logfile over data written to file
    regards
    Zamzam
    HFZ
    Attachments:
    DataFlowWR.JPG ‏159 KB
    Datalogfile.JPG ‏386 KB

  • How to parse Double to Integer Type?

    Dear all,
    I have a question in Java programming. How to change the variable of Double type into Integer Type? Is there any class that I should import in the Program?
    thanks.

    Double d = new Double(2.0);
    Integer i = new Integer(d.intValue()));

  • Format into string 16 bit signed integer

    Is there any format specifier string for "Format into string", whereas the result is an I16 string?
    My problem is when I use "%d" and the input string is 65535, the result string should be "-1".
    Solved!
    Go to Solution.

    Are you trying to get an integer out of an ASCII string (Scan from String) or turn an integer into a string (Format into String).  You title and question seem to contradict each other.
    Assuming you are trying to scan from string, it looks like you need to scan into a U16 and then use a conversion bullet to turn it into an I16.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Scan I16.png ‏11 KB

  • Help converting two 16 bit hex words to signed integer

    I am currently attempting to use labVIEW 2010 to read temperature and mass flow information off of a modbus instrument. However the instrument returns all values in 2 16 bit hex words in "Intel Bytes" ordering. I am having trouble converting this information to a usable signed decimal. For example:
    Word 1   Word 2             Signed Integer
    527E      41C0                 +24.0402793884277340
    I have attempted to merge the words and cast to decimal but to no avail. Any help or tips are appreciated as I am new to labVIEW and working with raw data in general.
    My current code is attached.
    Solved!
    Go to Solution.
    Attachments:
    Modbus_Read_6_7_2011.vi ‏14 KB

    On a side note, there is also an idea that would make code images less ambiguous in terms of numeric representations.
    (Personally, I always insist of attaching code or code snippets instead of images to make things unique. A flat image can never fully show all important aspects of a program.) 
    LabVIEW Champion . Do more with less code and in less time .

  • How to parse XML file with namesapce?

    Hi,
       I am trying to parse an xml file having namespace. But no data is returned.
    Sample Code:
    public class XMLFileLoader
    var xml:XML = new XML();
    var myXML:XML = new XML();
    var XML_URL:String = "file:///C:/Documents and Settings/Administrator/Desktop/MyData.xml";
    var myLoader:URLLoader = null;
    public function XMLFileLoader()
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    myLoader= new URLLoader(myXMLURL);
    myLoader.addEventListener(Event.COMPLETE,download);
    public function download(event:Event):void
    myXML = XML(myLoader.data);
    var ns:Namespace=myXML.namespace("xsi");
    for(var prop:String in myXML)
         trace(prop);
    //Alert.show(myXML..Parameters);
    //trace("Data loadedww."+myXML.toString());
    //Alert.show(myXML.DocumentInfo.attributes()+"test","Message");
    The XML Contains the following format.
    <Network xmlns="http://www.test.com/2005/test/omc/conf"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.test.com/2005/test/omc/conf/TestConfigurationEdition3proposal4.xsd">
        <TestDomain>
          <WAC>
            <!--Release Parameter  -->
            <Parameters ParameterName="ne_release" OutageType="None"
                        accessRight="CreateOnly" isMandatory="true"
                        Planned="false"
                        Reference="true" Working="true">
              <DataType>
                <StringType/>
              </DataType>
              <GUIInfo graphicalName="Release"
                       tabName="All"
                       description="Describes the release version of the managed object"/>
            </Parameters>
    </TestDomain>
    </Network>
    Any sample code how to parse this kind of xml file with namespaces...
    Regards,
    Purushotham

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • How to use DOMParser from an Applet / Or, how to parse XML from an Applet?

    Hey,
    As stating in the subject line, I wonder how to do it without getting an �Access Denied� error.
    I would like to parse a XML file that has external DTD pointing to a SYSTEM location. Yes, I can change it to a public location. However, in either way, I have problems to use DOMBuilder to parse the xml file. The application always throws the security exception.
    I tried to use the DOMParser from org.apache.xerces.parsers to parse the xml file. I set the DOMParser to ignore parsing the external DTD, and use the DOMParser.parse(InputSource) to parse the xml file from a giving URL. However, I get null of the result document.
    Does anyone know how to parse the XML from an Applet? Or, does anyone know how to use the DOMParser from an Applet?
    Thank you very much,

    If the document resides on the local filesystem, you will need to sign a CAB or JAR for the applet to circumvent the sandbox's security restrictions. There are dozens of posts on how to do this. Basically, that will turn the applet into an application, from a Java security perspective.
    - Saish
    "My karma ran over your dogma." - Anon

  • How to parse xml file in midlet

    Hi Guys,
    i wish to parse xml file and display it in my midlet. i found api's supporting xml parsing in j2se ie., in java.net or j2se 5.0. Can u please help me what package to use in midlet?
    how to parse xml info and display in midlet? Plz reply soon......Thanks in advance....

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • How to convert Date to Integer

    Hi all,
    please send the code How to convert the Date to Integer
    I want like this
    example: Date= 04.11.2002 after conversion the integer is: 4112002
    like this I want if anyone knows this please send it as soon as possible
    byee
    thanks

    Assuming ... String ASimpleDateFormat;
    // do this first
    ASimpleDateFormat = ASimpleDateFormat.replace(".","");
    // then parse
    int DateAsInt = Integer.parseInt(ASimpleDateFormat);

  • How to parse string to date in j2me?

    How to parse string to date in j2me?
    Please help me.

    Hi..
    String dyStr = "20";
    String mtStr = "1";
    String yrStr = "1999";
    Calendar cal = Calendar.getIntstance();
    int dy = Integer.parseInt(dyStr);
    int mt = Integer.parseInt(mtStr);
    int yr = Integer.parseInt(yrStr);
    cal.set(Calendar.DATE, dy);
    cal.set(Calendar.MONTH, mt);
    cal.set(Calendar.YEAR, yr);
    OK?

  • How do I stay signed in to Facetime?

    Recently Facetime has been asking me for my Apple password the first time incoming calls are received after starting the computer.  Until a couple of days ago, FT would always be automatically signed in, but now before answering a call I must input my password.
    How do I stay signed in?

    @Linc, the answer gets a bit involved.  Sorry in advance.
    Last week I spent an hour on the phone with Apple tech support because my computer suddenly and inexplicably cut off my access to iCloud.  As an aside, I could still sign into iCloud via the web site and all my peripheral devices (iPhone, iPad).  After much trouble shooting it came down to rebuilding a new keychain.  Until that point I had always disabled iCloud keychain, preferring my 1Password instead. 
    After your question above, I noticed that iCloud keychain is checked under the System Preferences.  Selecting the Options tab reveals a window with a check mark beside the "Allow approving with security code," and another tab to change that code.  I don't remember ever making such a code.
    I'm a bit wary of deselecting the iCloud keychain for fear of reproducing the previous problem.
    Suggestions? 

  • How to parse this textfile

    I have a plan textfiel that i'm able to read but i can't parse the date and numbers in the text file.
    text content: [ 2007.10.19 11:53:42 ] (test) <color=0xffbbbb00>Your item, costs 598.0 euro.
    i suppose i can use substring/tokenizer but my knowledge in the tokenizer is limited.
    Does anyone know how to parse the date and costs so i can show the total costs for an item?

    mkoryak wrote:
    import java.util.regex.*;
    holy regex, batman! I definitely have to devote more time to regex. My mere mortal solution to some of the extractions went along these lines:
        private Color getColor(String text)
            Color c = null;
            String[] strArr = text.split("[<>]"); 
            // the forum mangles this  :( 
            // it should have angle brackets inside of square brackets. 
            String colorStr = strArr[1];
            colorStr = colorStr.substring(colorStr.indexOf("=") + 3);
            int[] colorInts = new int[4];
            for (int i = 0; i < colorInts.length; i++)
                String colorSubStr = colorStr.substring(2 * i, 2 * i + 2);
                colorInts[i] = Integer.parseInt(colorSubStr, 16);
            c = new Color(colorInts[0], colorInts[1], colorInts[2], colorInts[3]);
            return c;
        private Date getDate(String text)
            Date d = null;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
            String[] dateStrArr = text.split("[\\[\\]]");
            String dateStr = dateStrArr[1].trim();
            try
                    d = sdf.parse(dateStr);
            catch (ParseException e)
                e.printStackTrace();
            return d;
        }I will definitely study your code mkoryak, thanks.
    Edited by: petes1234 on Oct 24, 2007 10:09 AM

  • How to parse the xml file using servlet

    My scenario is like this:
    <b>FILE-->XI-->J2EE Application</b>
    XI sends the xml file to j2ee application. My servlet receives the file in HTTPRequest string. 
    How to parse that file using servlets.I should get the xml file as it is and should be displayed in the browser.
    Can anyone please help me with code, its urgent.
    Please help me!

    Download this java code
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
    in your servlet code you can write
    public void doPost(req,resp){
    DefaultHandler handler = new Echo02();
    handler.parse(req.getInputStream());
    Offcourse you will need to modify the code of Echo02 class a bit to suit your requirement which would finally retrun you a string and you can then write it using
    respose.getWriter().write(responseString);

  • Reading 16 & 22 bit signed integers using Scan From String

    Last week it was suggested to use Scan from String which is a new tool for me and worked well to be able to read in ans parse strings.
    After parsing the string, I'm having trouble converting the numbers into signed integers. The magnitude of some of the the outputs are unreasonably high then flip to near 0 then back up again.
    Sample String (With spaces added)
    $ 00 FCCE 00F6 3FFA93 0BFE 0C89 0DDB
    Message Format:
    Bytes 3-6 FCCE Heave acceleration bits 15-0 15-bit data, sign extended to 16 bits LSB : 0.001261g Sign “+” when accelerating upward
    Bytes 11-16 3FFA93 FOG Gyro 1 bits 21-0 Bits 22-23 are always zero 22-bit signed data LSB = 97.275 µ˚/s Sign corresponds to MEMS axis
    Sample Data File:
    $00FCCE00F13FFD78100910A811FA
    $00FCDF00F13FFCD3141614C71619
    $00FCD600F33FFD20182118E61A39
    $00FCDA00F73FFB3E1C2D1D051E58
    $00FCDD00F73FFC32203921242278
    $00FCDD00EF3FFDDC244525442697
    The vi and a longer sample data file are uploaded to the ni ftp site. The zip file is named: IMU (9-15-08).zip. (Can't attach files to this message for some reason)
    Any help appreciated.
    Thanks,
    Chris

    Files uploaded to the "incoming" directory cannot be downloaded. That folder is intended to be used for submitting code to NI to investigate bugs and such things, not for forum posts.
    What are you expecting FCCE to be? If the string is made of the characters "F", followed by the character "C", etc. (as opposed to the hex value of F, followed by the hex value of C, etc), then you can simply use Hexadecimal String to Number. Otherwise you need to use Type Cast.
    Attachments:
    Example_VI.png ‏5 KB

Maybe you are looking for

  • Relation between movement type and Schedule Line Item Cat

    I have a situation for Return Sales Order, there's two lines items with *Item Cat                      Schedule Line Item Cat         Stock REN(Normal)                 YN (Returns 657)                 Blocked RENN (Free Goods)      DN (Returns)      

  • Looping Restart in Early Intel iMac after recent 10.5 update

    My friend's iMac is stuck in a restart loop after downloading the latest update for her 10.5 system. She hadn't installed an update for about 4 months so I am not sure what update would have caused the loop. Her computer was working fine before the u

  • How do you get songs not in your library?

    I have some songs that are not in my library so I can't download them into my iPod. HELP PLEASE!!!!!!!!!!!

  • Making new folders in Mail

    I would like to know how to make new folders in my yahoo mail account. Thank You.

  • Re:java regular expression for website

      Hi All, I am using jdeveloper 11.1.2.3.0 My requirement is that I have a website  attribute I need the regular expression for the website attribute to display the format www.google.com  www.oracle.com. Thanks, Sandeep