Best way to parse serial communications

I've been programming a long time, but am new to object oriented languages and Java in particular.
I have an application where I read in replies from an instrument over an RS232 port.. Each reply is terminated with a CR. I need to parse each reply and perform some task related to the reply. I've done this many times in C, but I think the 'right' approach in Java would be different. I am looking for ideas on what that 'right' way is.
I have a class that reads in from the serial port (using Javax.comm) and puts the data in a classic circular buffer. Does it make sense when I get a CR to pull that reply and send it to a new thread that parses it and performs the task? That way if multiple replies come in, I can start multiple threads to deal with each reply. In general, each reply can probably be dealt with before the next reply comes, but it's not guaranteed, so having threads to do the work seems like a good idea and helps to modularize the code.
Or is something else better? I'm not looking for a solution, just help in getting me to 'think in Java'.
- SteveS

I've been programming a long time, but am new to object oriented languages and Java in particular.
I have an application where I read in replies from an instrument over an RS232 port.. Each reply is terminated with a CR. I need to parse each reply and perform some task related to the reply. I've done this many times in C, but I think the 'right' approach in Java would be different. I am looking for ideas on what that 'right' way is.
I have a class that reads in from the serial port (using Javax.comm) and puts the data in a classic circular buffer. Does it make sense when I get a CR to pull that reply and send it to a new thread that parses it and performs the task? That way if multiple replies come in, I can start multiple threads to deal with each reply. In general, each reply can probably be dealt with before the next reply comes, but it's not guaranteed, so having threads to do the work seems like a good idea and helps to modularize the code.
Or is something else better? I'm not looking for a solution, just help in getting me to 'think in Java'.
- SteveS

Similar Messages

  • What's the best way to parse a BSTR in TestStand?

    I receive a BSTR from an OLE interface; what is the best way to parse this into something understandable? Has anyone written a routing for this?

    Hi,
    If you are using a OLE interface I think you will be using the Active X Automation adaptor.
    TestStand Active X Automation Adaptor automatically converts BSTR when it store the data in a TestStand variable.
    Then you should be able to use the regular string functions which are available in TestStand to parse the strings.
    Please let me know if you have any more questions.
    Regards
    Anand Jain

  • Which is the best way to parse nested XML

    Hello, I am just getting back into using ColdFusion and I am
    working on a project that needs to parse some XML.
    The XML is generated by a third party document.
    I figured out how to grab individual values and such, but I'm
    not sure what is the best way to grab a value in relation to where
    it is in the XML.
    Following is a rather simplified example of the XML
    I need to grab the value of 'Rich Text' in relation to the
    'ID name' value.
    <project>
    <CT text>
    <Group>
    <id name = text1>
    <Rich Text>some sample text</Rich
    Text>
    </id>
    </Group>
    </CT Text>
    <CT text>
    <Group>
    <Group>
    <id name = text1>
    <Rich Text>some sample text</Rich
    Text>
    </id>
    </Group>
    </Group>
    </CT Text>
    <CT text>
    <id name = text2>
    <Rich Text>some more sample text</Rich
    Text>
    </id>
    </CT Text>
    </project>
    Once parsed, the info I need to output on the page would look
    like
    text 1
    some sample text
    text 2
    some more sample text
    The part that makes this difficult for me is that there may
    be 0 'Group' values or there might be a number of them. As such, I
    can't just grab the value by listing the tree out, since it changes
    depending on the document (there are thousands of these documents
    that I need to parse).
    From what I have seen in some XML examples, there are a
    number of ways to go about doing this, but before I put a lot of
    time into any of them, I was wondering what the 'best' way to do
    this is.
    XSLT? XMLSearch? Structures? Some combination of those or
    other functions?
    P.S. what little I know of using ColdFusion with XML all
    comes from the doc written by Nate Weiss.
    I was a bit let down that after spending well over $1,000 for
    ColdFusion, Adobe left out the only two books that were worth
    printing (the CFML reference guide and the Advanced book). It
    wouldn't have bothered me as much if there was something on the
    product page listing the manuals that said 'we only actually give
    you 2 of the ones listed'.
    Best regards
    Kevin R.

    Hello,
    Could someone do me a huge favor and provide some sample code
    that would parse/output the above xml so that the output would look
    something like the following. . .
    text 1 = some sample text
    text 2 = some more sample text
    The problem I am having is displaying the xmltext for the
    RICH TEXT element in relation to the ID element.
    The code below will return the value of the RICHTEXT
    (incorrectly named in the original XML examples) easily enough, but
    I need to have it show which text number it is.
    Best regards,
    Kevin R.

  • Best way to parse data

    Hi, I'm fairly new to java programming coming from a midrange, COBOL background.
    I need to take data from a legacy program and use it in an online java program. The data is stored in a table that occurs 1-25 times:
    05  DATA-TABLE OCCURS 25 TIMES.
           10  FIELD1                       PIC X(25).
           10  FIELD2                       PIC X(25).
           10  FIELD3                       PIC X(50).  So, I could have between 100 and 2500 bytes of data to deal with in the java program. Can anyone point me in the right direction on the best way to handle this? I thought about creating an intial Array that has 25 elements and then substring-ing the returned data into that. Then, what would be the best way to break that data down to the individual components?
    If you have any solutions or pointers, I would definitely appreciate it.
    Thanks!
    bfrmbama

    I would say to you to start giving meaning to your data and puting it in classes, for example if your data is about pet animals and you have the animal's name, nick and description:
    package example;
    * @author leonardo     12/11/2004
    * @version 1.0
    public class Pet {
        private String name;
        private String nick;
        private String description;
         * Create a pet from the string with the triplet atributes.
         * @param triplet The triplet data.
        public Pet( String triplet ) {
            tokenize( triplet );
         * Method for tokenizing the pet data.
         * @param triplet the data.
        private void tokenize(String triplet) {
             * I am assuming the data is space separated,
             * look at the api to see a complete usage of
             * split and maybe the string tokenizer.
            String[] strings = triplet.split(" ");
            name = strings[1];
            nick = strings[2];
            description = strings[3];
         * Its always a good idea to encapsulate your data
         * and give access to it through accessors and mutators.
        public String getDescription() {
            return description;
        public void setDescription(String description) {
            this.description = description;
        public String getName() {
            return name;
        public void setName(String name) {
            this.name = name;
        public String getNick() {
            return nick;
        public void setNick(String nick) {
            this.nick = nick;
    }then when you tokenize your file you can do:
    // ... Incomplete ...
    // I am assuming you will write a CobolFileReader that implements the file reading and line
    // extratction logic. when there is no more data to be read it returns null
       List list = new ArrayList();
        CobolFileReader cobolFileReader = new CobolFileReader("TheFile.txt");
            for(String triplet = cobolFileReader.getNextTripet(); triplet != null; triplet = cobolFileReader.getNextTripet()) {
                list.add( new Pet( triplet ) );
      This way you will have a lista as big as it needs to be.

  • What is the best way to close a communication session with the FP Server?

    Looking at NI's FieldPoint Demobox.vi example, the session is closed by wiring the FP Refnum out from the FP Create Tag vi for the AI module to the FP Close vi. Is there any difference if the FP Refnum out from any or all of the other FP Create Tags were wired to FP Close vi/vi's? Could the FP Refnum out from the FP Open vi be wired to the FP Close vi? What is the best way to do this?
    Also, as I'm new to FP and I'm conscious that I might swamp this forum with dumb questions, are the any sources of good FP code examples and/or discussions on coding techniques out there beyond the handful of NI's examples?
    Thanks again,
    Niel.

    Niel,
    The FP Open.vi provides a FP Refnum in the form of a data cluster. The cluster contains two elements; a server refnum and a tag refnum. Coming out of the FP Open, only the server refnum has a value, the tag refnum is created when the FP Create Tag.vi is processed. Thus all FP refnums in a process have the same server refnum but different tag refnums. The FP Close.vi uses the server refnum to close the server and ignores the tag refnum so it does not matter which particular refnum was used to close the server. The thing to be careful of is if you close on refnum, you close all refnums. At this point, any reads/writes/advises will result in error 32804 (Invalid IA handle specified).
    Also, please swamp this forum with questions. I am in the process of reviewin
    g the documentation and examples we provide and having a beginner asking questions that do not appear to be covered in our materials gives me an idea of what we are missing. I would ask that you upgrade to FieldPoint Explorer 2.0.4 and use the online help for LabVIEW since that has had some of my modifications added to it (program flow outlines, vi descriptions & use cases).
    Regards, Aaron

  • Best way to parse a subtitle file (.srt) ?

    Hey there!
    I'm a total newbie with Cocoa and I'm currently trying to improve my knowledge in parsing files through a simple TableView. More precisely, I'd like to parse .srt files. Those are subtitle files that can be opened with a basic text-editor. Here's the structure of such a file :
    1
    +00:00:00,324 --> 00:00:02,257+
    +Previously on Greek...+
    2
    +00:00:02,638 --> 00:00:05,022+
    +Come on! That's gonna be+
    +the best party ever!+
    3
    +00:00:05,126 --> 00:00:07,540+
    +Yeah, I know... but she doesn't+
    +want to see me again.+
    As you see, each subtitle is composed of 3 parts : a kind of ID, the output period (xx:xx:xx,xxx) and the content (which is supposed to be composed of 2 lines max. but not everytime so...).
    I'd like to be able to read an SRT file so that I can put its content into my TableView (which has 3 columns : one for the beginning time, one for the end time and one for the content).
    Any help would be appreciated!
    Thanks in advance and sorry for my rusty English
    PS: I'm not asking for a code; just for a solution, a way to do it

    Electrobitch wrote:
    I'm not asking for a code; just for a solution, a way to do it
    Lots of threads go something like, "How would I go about... Does anyone have any ideas?". So I write a little essay about general approach with reference links, only to be asked for sample code. Them I'm asked for ideas about where to put the sample code. Then I find out the OP is sitting in a cubical somewhere, the boss expects to see working screens in 6 hours 23 minutes, and my student was looking for finished code from the start.
    So usually I'm happy to avoid code. However in this case I wouldn't recommend a Cocoa class, a script language or the front end of a compiler. My approach would be to just parse the file in C. I doubt it will take many lines, but it would be way easier for me to post commented code than to explain how to start from scratch, ok?
    Can you tell me if the format you described is a standard? I.e., is your file exactly the same as a SRT format I can find on the web? (E.g., here's one that includes some html: [http://forum.doom9.org/archive/index.php/t-73953.html]). Just so you'll know how obsolete I am, I never heard of SRT before. If one of my kids was around I'm guessing I wouldn't need to Google it, but I'm on my own today.
    I just need to know how much variation there could possibly be from what you posted. Hopefully my code will be clear enough for you to trim it yourself, but I'd like to get it as close as I can the first time.
    \- Ray

  • Best way to parse this xml

    Hi,
    my xml file has this structure:
    <config>
    <settings>
    <engine>ON</engine>
    <monitor>OFF</engine>
    <debug>ON</engine>
    </settings>
    <rules>
    <rule>
    <scope>...</scope>
    <action>...</action>
    </rule>
    <rule>
    <scope>...</scope>
    <action>...</action>
    </rule>
    <rule>
    <scope>...</scope>
    <action>...</action>
    </rule>
    </rules>
    </config>
    What is now the best and most performant way to read in this xml file?
    I don't really know very much of xml yet, so if you can help me, thanks.

    if ur xml is big enough its good to go for sax parser or else use DOM..
    regards
    Shanu

  • Best way to parse XML Message ?

    Hi,
    I have to implement in PL/SQL an interface which receives for example orders in xml format. Something like this:
    <order>
    <order_no>4711</order_no>
    <order_line>
    <skuid>10001</skuid>
    <qty>34</qty>
    </order_line>
    <order_line>
    <skuid>10002</skuid>
    <qty>35</qty>
    </order_line>
    </order>
    I have to parse this xml and store it into an order_mast and order_detl table.
    I'm uncertain which would be the best approach. I read in this document http://www.oracle.com/technology/tech/xml/xdk_sample/xdksample_040602.pdf to do it with an XDK Sax Parser.
    According to this document the performance is better when using SAX then DOM for large xml message.
    But how "large" is large? In my case the xml message can have theoretically several thousand lines, is this already a performance issue for DOM ?
    Are besides the performance any good reason to use DOM instead of SAX ?
    Are there in Oracle 10g any even better possiblities to do this ?
    I read about some DMBS_XML packages, but do know them really.
    I really appreciate any hint or suggestion.
    Many Thanks!
    Peter

    I use the DBMS_XMLDOM package to parse through XML Schemas (about 2Mb in text file terms, thousands of lines (never counted them)) on my desktop, and including all of the processing I do and storing all the information in database tables, the whole lot is processed in about 30 seconds. These are fairly large schemas with lots of included schemas. I imagine it's gonna be a helluva lot faster when we put it on our server, so I don't think DBMS_XMLDOM is a slow way of doing it. Guess the best thing to do is to try different ways and do some performance testing based on your own business requirements i.e. varying size of XML messages and frequency/amount of messages being received.
    ;)

  • Best way to use serials in WM

    Hi All,
    we want to use serials numbers for Wm managed materials.means we are planning to add on feildin TR and TO table also in Quant table .so when we doppicking we want to issue the  right serial number to the customer. so please advice the advangate and constraint of the same
    thansk
    jay

    I concur with T-squared. The Kensington 33185 is simple to use and the sound quality has been excellent. I bought it just last Friday and it has seen me through numerous holiday roadtrips over the past week. It charges and has three presets; I can recommend 89.7 or 106.5 FM when you're in the Philadelphia/Princeton area. :->
    AlumPbk G4 15, 1.5GHz, 1GB RAM   Mac OS X (10.4.3)   iPod 60GB

  • Best way to parse a file.

    Hey!
    I have a txt-file with alot of characters in it. I wonder which is the most effective way to read this file?
    I read this file and put every chars in a long String so i can split this string later with String.split("..");
    The file is about 40kb and will be bigger soon enough. This taking a bit to long.
    What is most efficient?
    Thanks
    /Mike

    Another thing you can do is pre-compile the regex and use Pattern's split() method:  Pattern splitPattern = Pattern.compile(".."); and later:  String[] tokens = splitPattern.split(line);When you use String's split() method, it recompiles the regex each time you call it. The time that takes can really add up when you process thousands of lines.
    BTW, you aren't really splitting on a pair of dots, are you? I assume that's just a placeholder for the real regex.

  • Best way to realize controller communication

    Hi,
    my UI has a search text field and a table. To filter the table content the user can enter something in the text field. If the entered text hits a row, it is displayed, otherwise not. The text field filters the table.
    I have a search.fxml (search text field ) with controller and the table (content.fxml) with controller. When the user typed in the text in the search field and hits the button there, the text will be passed to the search controller. Now my problem begins...I need an instance of the controller of the table to invoke a method which gets the search text and does the filtering. Is there a concept in JavaFX to do this easily. The FXMLLoader.getController() delivers a new instance which does not fit in my case.
    Regards,
    Oliver

    The FXMLLoader.getController() delivers a new instance which does not fit in my case.If you are using JavaFX 2.1, you can use a controller factory to manage how controllers are instantiated. See FXMLLoader#setControllerFactory().
    Probably wrote a lot, in short: how should I share controllers?See this thread for more info:
    How to Navigate 'include' resource in .fxml files

  • Best way to make a Java Messenger?

    I'm currently creating a Messenger service much like ICQ or AIM. I'm trying to find out what is the best way to do network communication and I was hoping some java guru might have some advice.
    Basically I need to know what would be the best and cleanest way for clients to talk to the server and visa versa. Here are the options I know of:
    1. Use pure datagrams and create my own byte by byte protocol.
    2. Use JMS (Java Message Service).
    3. Use some sort of RMI (remote method invocation).
    I want to be able to have a solution that will support massive amounts of users. Oh, and the program won't be a bean or applet, it will be a native application.
    Please give me some advice.
    Gregg

    Why not create your own protocol. I have a similar project. I'm going to be communicating to C on Linux. App will run in Windows. the only option I have is to create my own protocol. I'm not sure if RMI, Soap will help me here. Since the C side knows nothing ot those technologies.
    My quesiton concerns data. I will be creating a binary protocol.
    typedef structur protocol {
    int option
    int code
    unsigned char data[1024]
    } PROTO;
    That is not my protocol just an example. Question I have is that I do not have structures in Java just classes. How can I take data off the socket and type cast it to match the above structure?
    Chris

  • I want to transmit a square pulse through USB port, is it possible?? if not then what is the best way to do that, preferable is with serial then parallel, and its compatibility with vista,XP,and @))7 windows

    hi froends
    i want to transmit a square pulse using lab-view, please help how to do that, the preference  will be USB,SERIAL, Parallel ports, it it must be compatible with all the os versions, like 2007 windows, vista,XP and other.
    please help..................

    sanghi wrote:
    OK I WANT TO DRIVE A RELAY.
    SUGGEST SOMETHING 
    Calm down!
    People can't read your mind.  If you want help, repsect those who contribute their time for free to try to help you.
    Put yourself in our shoes.  If I tell you I want to build a rocket, what information would you give me?  You would need to know if it's for a hobby, something bigger, carries a payload, carries living organism, how far does it go, where does it land (if at all), etc...  
    First of all, we still don't know what you want to do with this relay.  Using a computer to generate is series of pulses is not usually the best way.  What is the frequency of the pulses that you want to transmit?  And why do you want to use a relay?  What are you driving?  Can the relay that you are using fast enough to follow the pulse train that you'll be sending?
    Provide information, ask questions politely and people will help you.

  • Is RMI the best way for Applet to Java communications?

    I have an application that uses a Java program to read values from a PLC (programmable logic controller) via ethernet. I want to display them in Internet Explorer. Currently, I use SQL statements in the application and an applet to pass the values, but this causes the hard drive to be busy all the time. A better way would be to have the applet pass which registers to read for the current page to the application. The application then reads these values once every second (to update the page) and passes them back to the applet. Is RMI the best way to do this? The application and the applet run currently on the same PC, but I can envision going with a client/server architecture at some point in the future. Please respond to: [email protected] or [email protected] Thanks!

    Writing to the DB and reading back is not the best way of achieving IPC. You can use DB directly as long as both applet and application have permissions to do that. This has an advantage that it avoids RMI overhead (though not much). You would not be able to do this if your applet is going to be launched on a web environment (as typically, security policies do not allow you to write/read on local machine's DB or any m/c other than web-server's).
    I feel your current approach has the following
    advantages:
    --> There's no RMI(or any other IPC mech.) overhead involved.
    --> Best way to communicate if applet is permitted to do all the things that the application can do on DB.
    limitations:
    --> When applets are launched through web, this approach would work only if the DB resides on the same m/c as web-server(JDBC).
    --> Lot of DB I/O, table locks etc... affect performance. Application alone can do all that activity(minimized) and communicate it to the applet through RMI/callbacks.
    Alternate/better approach:
    RMI and Servlet combination can be used in order to overcome those limitations. In this scenario, your applet gets downloaded on to the client's m/c, servlets (which make RMI calls to the application running anywhere) reside on the webserver's m/c. applet talks to servlets, which in turn communicate with application(DB). This approach would work in any scenario, but not without the overheads of RMI and/or HTTP. But in my experience, I have noticed that these overheads are not too large.
    To decide upon the strategy to be employed, you should consider all the possible deployment scenarios of your system. For passing any object, you may use RMI for reliable, easy communication. It can serve more purposes than just passing DB data. This will make your system extensible.
    regds,
    CA

  • Hello I have lost my serial number for adobe photoshop elements. Bought from John Lewis last month. I did have it installed but had to uninstall but cannot find the any of the packaging etc plus did not register. What is the best way of getting it install

    Hello I have lost my serial number for adobe photoshop elements 13. Bought from John Lewis last month. I did have it installed but had to uninstall but cannot find the any of the packaging etc plus did not register. What is the best way of getting it installed again/replacement? Thanks

    Do you have the receipt? If you have proof of ownership, you _may_ be able to persuade Customer Support to help you out.  I imagine you would need to scan and email that proof if it works at all.

Maybe you are looking for

  • Cant sync iphone with itunes running XP sp2\-help!

    All photos and music on old lap-top running XP sp2. How can I get on my i-phone 5C??

  • Can PSP be used in Portals?

    Hi Portal Gurus, I understand PL/SQL Cartridges can be used in portal development. But, has Oracle started supporting use of PSP (PL/SQL Server Pages) for portal development? If so, is there any documentation out there for it? Any help will be greatl

  • Validate mandatory field in BPS Excel layout

    Hi Sdner In my BPS Excel layout i want to have some characteristic as mandatory.If i don't put any value for them system will put a # by default which i don't want. system should prompt a error message that particular field is mandatory and enter som

  • I-Pod nano reacts when connected but doesn't do anything when disconnected

    iPod nano reacts and shows music when connected, I can listen also to the music then, but when I disconnect it, it doesn't react at all. I diconnected it right, the battery is charged, I downloaded Itunes succesfully but I can't use my iPod. Maybe it

  • Timeline Editor is not displaying

    I'm learning GoLive from Classroom in a Book. I followed the instruction to open the timeline editor. But nothing's happened. I found that it's been enabled (under window), just doesn't show on the screen. Can anyone please tell me what's wrong? Than