Search serial input

Hi, ive only just started programming in java. My FYP involves getting gps info over serial port and searching the data rxed for time etc. I've managed to get SImpleRead working for the GPS im using so it reads everything in fine. I have to search through the sentences (input) received now for the word $GPRMC and im having great difficulty. i cant see exactly what is my input in the code, is it inputStream or buffer??? can anyone help heres my code so far
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SerialRead implements Runnable, SerialPortEventListener {
     static CommPortIdentifier portId;
     static Enumeration portList;
     InputStream inputStream;
     SerialPort serialPort;
     Thread readThread;
     boolean portOpen;
     BufferedInputStream in;
     public static void main(String[] args) {
          System.out.println("Starting....");
          portList = CommPortIdentifier.getPortIdentifiers();
          while (portList.hasMoreElements()) {
               portId = (CommPortIdentifier) portList.nextElement();
               if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                    if (portId.getName().equals("COM1")) {
                         System.out.println("Found Serial Port!!!");
                         SerialRead reader = new SerialRead();
     public SerialRead() {
          System.out.println("Opening Serial......");
          try {
               serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
               portOpen = true;
          } catch (PortInUseException e) {}
          try {
               System.out.println("Getting input stream....");
               inputStream = serialPort.getInputStream();
               in = new BufferedInputStream(inputStream, 1024);
          } catch (IOException e) {
               serialPort.close();
          System.out.println("Error opening i/o streams");}
     try {
               serialPort.addEventListener(this);
     } catch (TooManyListenersException e) {}
          serialPort.notifyOnDataAvailable(true);
          try {
               serialPort.setSerialPortParams(4800,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
          } catch (UnsupportedCommOperationException e) {}
          System.out.println("Parameters set");
          readThread = new Thread(this);
          readThread.start();
     public void run() {
          try {
               Thread.sleep(10000);
          } catch (InterruptedException e) {}
     public void serialEvent(SerialPortEvent event) {
//          Create a StringBuffer and int to receive input data.
          StringBuffer inputBuffer = new StringBuffer();
          int newData = 0;      
          //Determine type of event
          switch(event.getEventType()) {
          case SerialPortEvent.BI:
               System.out.println("\n--- BREAK RECEIVED ---\n");
          case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
          break;
          case SerialPortEvent.DATA_AVAILABLE:
               while (newData != -1) {
                    try {
                         newData = inputStream.read();
                    if (newData == -1){
                    break;
                    if('\r' == (char)newData) {
                    inputBuffer.append('\n');
                    } else{
                         inputBuffer.append((char)newData);
                         //GetGPRMC();
                         System.out.print(new String(inputBuffer));
                    } catch (IOException ex) {
                         System.err.println(ex);
                         return;
//     //Method to find GPRMC in buffer
//     public void GetGPRMC()
//     int counter = 0;
//     do{
//          //search the i/p buffer to find GPRMC word
//          if(inputBuffer.regionMatches(counter, GPRMC, 0, 5)){
//          //store 127 characters starting at GPRMC
//          String temp = inputBuffer.substring(counter, counter + 127);
//          counter = 0;
//          //Tokenize string with respect to commas
//          StringTokenizer tokens = new StringTokenizer(temp, ",");
//          while(tokens.hasMoreTokens() && (counter < 11))
//                    gpsData[counter] = tokens.nextToken();
     //Close connection method
     public void CloseConnection()
          if (!portOpen)
               return;                          // if the port is already closed, do nothing
          try {
               inputStream.close();          //close inputstream
          catch (IOException e) {
               CloseConnection();
               System.err.println(e);
          serialPort.close();                // close port
i know its not an incredibly difficult thing to do but ive been puzzling over it for a while now and still cant see how to go about it. i know i could use regionMatches method but i dont know which string to use to call it.....
confused laela

Hi!
My project is basically the same thing, only I get data from the GPS on one computer (using C) and send it through a GSM modem.
On the reciever PC, I have to extract the data from the modem (the GPS string)
I will try to use your code, if that's ok.
I have very little time and the reciever PC part is giving me lots of problems
Thanks

Similar Messages

  • VL02N-How search serial numbers quickly in IQ09 screen???

    In our company,when doing VL02N for Outbound Delivery,sometimes for the finished product with serial numbers management, we will go to Menu "Extras" -> "Serial Numbers" to choose the serial numbers,then will go to the screen "Display Material Serial Number:Serial Number Selection" ,the same with IQ09.And there we will enter some elelments to quick search serial numbers for the finished product,just like "Material","Stock" and so on.
    My question is in VL02N we have already input "Material ","Plant","Storage Location" values,then on the screen "Display Material Serial Number:Serial Number Selection",we hoped this values could be copied to the screen,not enter by ourselves again.By now,"Material" values could be copied to the IQ09 screen,but "Plant","Storage Location" values can not be copied to the IQ09 screen.
    That means in IQ09 screen some data can be copied from VL02N directly?
    Is it possible in SAP?How to do it?
    Thanks for any reply!
    Edited by: Fei Liu on Mar 24, 2009 3:42 PM
    Edited by: Fei Liu on Mar 24, 2009 3:42 PM

    I mean in Outbound Delivery with VL02N, we have already input  "Material ","Plant","Storage Location" these values,and when go to menu "Extras" -> "Serial Numbers" to choose the serial numbers, on the IQ09
    screen,we hope these   "Material ","Plant","Storage Location"  values will auto copied to the IQ09 screen to quickly search the serial numbers.
    It is possible auto copied "Material ","Plant","Storage Location"   values to serial numbers search screen IQ09?

  • How does the search functon/input box work?

    How does the search functon/input box work?
    Hi
    my level is beginner
    there is a search box on the upper right hand on this page
    frames in gey ?
    how does this work.
    does this search in the database?
    if i would want to create this in an application
    what can i do ?
    are there CF examples??

    Thanks
    search against a database : Are there a function of Cf ta
    tags/code to do this? is this CFquery / and Cfoutput?
    or
    do a Verity search of a collection. How is this dont by? CF
    submit a search to an external search engine like Google.
    oh, is this when a page has a search and when the user types in
    there text in the input box it automatically goes to the google
    search. any articles on how to do this in CF
    Thanks

  • Mac and serial input

    Hi,
    I have a device that generates serial signals. I've connected it to the mac via a serial-usb adapter. Is there a way or an application that allows the mac to recognize serial inputs (ascii or hexadecimal) and use them as commands, or example to launch an application or a script?
    Thanks
    mino

    Zterm may be the software you are looking for:
    http://homepage.mac.com/dalverson/zterm/

  • Search help - input screen

    Hi,
    i want to build a search help. it should be like when we click F4 on the field, it should give the screen with input field (field1) and if we enter the value in the field, it should display the corresponding values (field2) for the input field. when user clicks the field, it should retrieve the field2.
    and we should also  be able to default the input field and also set the no of entries to be displayed
    Can anyone let me know how to create this kind of search help
    Thanks
    Shekhar

    Hi shekar..
    just see this sample code..
      SELECT carrid carrname
                    FROM scarr
                    INTO CORRESPONDING FIELDS OF TABLE itab_carrid.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
           EXPORTING
                retfield        = 'CARRID'
                      dynpprog    = gv_repid
                      dynpnr      = gv_dynnr
                      dynprofield = 'S_field-LOW'
                value_org       = 'S'
           TABLES
                value_tab       = itab_carrid
           EXCEPTIONS
                parameter_error = 1
                no_values_found = 2
                OTHERS          = 3.
      IF sy-subrc <> 0.
    ENDIF.
    wirte one more select query with where condition = s_field-low. into table itab2 to provide search help for 'S_field11-LOW' on same screen..
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
           EXPORTING
                retfield        = 'CARRID11'
                      dynpprog    = gv_repid
                      dynpnr      = gv_dynnr
                      dynprofield = 'S_field11-LOW'
                value_org       = 'S'
           TABLES
                value_tab       = itab2
           EXCEPTIONS
                parameter_error = 1
                no_values_found = 2
                OTHERS          = 3.
      IF sy-subrc <> 0.
    ENDIF.
    just follow this code.. all the best..
    Thanks
    GSANA

  • "Structure search" and "free search" in input help

    I need to have an input help for my PERNR field, right now i am using search help PREMN and calling FM F4IF_FIELD_VALUE_REQUEST inorder to display the input help. But, in addition to this, i wnat the tabs "Structure search " , "Free search" to be displayed in teh input help pop up screen.
    How can i achieve this?
    Thanks,
    Vasuki

    Hi Vasuki,
    Just write it this way
    parameters:p_pernr type pa0001-pernr matchcode object PREM.
    Now once you hit f4 help. The search help will be displayed with all tabs, once you choose the free search tab the respective screen will be displayed.Now if you want to return to other tabs you must choose the button in bottom of the free search screen which is in between "Green tick mark" and "Close button".

  • Loss serial input with re install of Labview

    I have an existing VI that is trying to connect through Com 1 to an Emveco testing machine. The hard drive crashed and I am trying to re install LabView on a new hard drive. When I run the VI in the new installation, it does not seem to communicate to the testing machine. I have opened hyperterminal and can see the data coming in the serial port. I am not sure if I loaded the correct driver for serial communications and also I not not sure how to check to see if the serial comm. settings are right in LabView

    Hello -
    It appears that your hardware is working, as verified by hyperterminal. Therefore, the problem most likely is with the software.
    Are you receiving any error messages? Or does the serial port just appear to not communicate when the VI is run?
    What version of LabView are you using? Did you install the same version on the new hard drive?
    Does your program use VISA? You may not have VISA installed on the new machine and this may be causing the problem. You can verify that VISA is installed by opening Measurement and Automation Explorer and expanding the software list in the left column by clicking on the "+".
    Have you tried to verify serial communication in LabView by running one of
    the example VIs? Try to run the LabVIEW <-> Serial.vi found in the Example Finder >> Hardware Input and Output >> Serial folder.
    Additional Resources:
    The current serial driver for your Operating System is located here.
    This KnowledgeBase discusses some common problems with serial communication and possible solutions.
    Let me know if any of these suggestions solve your problem. If not, please provide more information and I will continue to research the issue. Have a great day!
    Becky B.
    Applications Engineer
    National Instruments
    Becky Linton
    National Instruments
    Field Engineer
    Office: 734-464-2463
    Cell: 248-709-2822
    Email: [email protected]

  • Serial # input everytime I open PS CS6?!

    PS CS6 is registered to my Adobe ID. For the last week, everytime I open the program, it makes me "License the Product" and input the serial number...AGAIN! This is really starting to get annoying. Can anyone help out with some advice?

    With Windows the easiest way is to start PS with a right click to icon.  Then choose "run as administrator".  Enter data and should be OK next time.
    Hope this helps.

  • I just bought mac and does mac have mongolian keyboard language? i searched the input resource in language

    Does mac have mongolian keyboard language? i have searched on the input resource in language & text, but i could not find it. Help me, please

    Hi Bart_mgl,
    You can try following link.
    http://mongoliankeyboardformac.blogspot.com/

  • Asynchronous serial input with an sbRIO FPGA

    Background:
    As part of my capstone project, I'm trying to read data transmitted serially from an IMU. The host is an sbRIO 9602.
    As far as I'm aware, the protocol is not exactly standard: data is sent asynchronously in packets. Each packet consists of 12+ bytes in immediate sequence, each having a start and stop bit, and then the line goes idle [high] until the next packet. Each data byte is preceded by a frame bit, and only contains 7 bits of actual data, so the packet has to be further processed to get actual useful data.
    I've seen the FPGA serial I/O example program floating around. The code I inherited was actually based on it, but it's overly complex for this application, and I'm not convinced it would actually work for this protocol at all. I couldn't get it to work, at any rate. I rewrote the sampling code in its entirety twice trying to get it to work, but haven't made a lot of progress. -On the bright side, the current VI is much simpler and more straight forward than my first attempt...
    The problem:
    I can read the first 70 or so bits of a packet fine, then the program skips a bit. That throws off the start/stop bits, and basically renders everything after meaningless. In this screenshot the data is as read in, in order from top to bottom:
    I'm fairly certain this means my sampling interval isn't perfect [this suggests about 1.4% too long], but I'm totally stumped on how to avoid it. What's worse, this is actually on the lowest possible output setting from the IMU, 2400 baud. Realistically, we're hoping to have it working at either 230.4k or 460.8k baud.
    The prior version of my code had the packet being read in 10-bit [1 byte] chunks, processing, then reading the next chunk. I encountered exactly the same error. I assumed that having too much code in the sampling process was causing the timing to be thrown off, so I changed it to read off the entire packet into a bit array and then process it afterward [while no data is coming in]. I've attached this version of the code for reference. It's cleaner, but no change as far as the error is concerned.
    Am I correct in my evaluation, or is there something else going on? More to the point, is there a way of fixing or working around the problem so that I can get reliable samples [even at 100-200x the bit rate]?
    As an aside, I've only been working with LabVIEW for a couple weeks; please tell me if I'm using poor habits or doing anything incorrectly.
    Any help will be immensely appreciated. Thank you.
    Attachments:
    IMU_serial_in.vi ‏61 KB

    Hi Ryan,
    I have a suggested methodology, but I don't currently have any example code to share that would get you started.
    The challenge you have is even if you sample at the exact right baud rate of your incoming signal, the phase of the FPGA clock will not be exactly the same as the source signal.  Now complicate that with your sample frequency and baud rate will always be slightly different, and you will get the sampling drift effect you described where data eventually is clocked in wrong.  On short transmissions, this may not be a problem because the sampling can be re-aligned with a start bit, but for long, continuous streaming, it eventually fails as the sampling and source signals drift out of phase.
    I would suggest over-sampling the DIO line, using a debounce filter if necessary, and use a measured time between edge detections to constantly adjust your sampling period and phase to keep your sampling aligned with the incoming data.
    The proposed LabVIEW code I imagine would be a single-cycle timed loop based state-machine.  Essentially the state machine could detect edges that occur near the baud rate you expect to receive, and then would adjust the sampling period to ensure you are sampling the data inbetween transitions while the incoming waveform is stable.
    With this method running at 40MHz, you would essentially have ~43 clock ticks/samples of each clock cycle at 921.6kbps, and you should be able to pull out the right samples at the right time in the waveform.
    Hope this helps, and if I find a good example of this, I'll send it your way.
    Cheers,
    Spex
    National Instruments
    To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be...

  • Custom Search Help / Input Help

    Hi All,
    I have a custom BSP application, I need to provide a Search Help for a custom field there, can someone brief me the steps to follow?.
    Thanks, Sudeep..

    Hi,
    Check this one http://****************/Tutorials/BSP/F4Help/Tutorial.htm
    blogs ShowHelp Functionality with pop-up
             ShowHelp Functionality with pop-up - part2
    Regards,
    Sri

  • Searching user-inputted text

    I'm designing a word processor in Interface Builder, and am trying to integrate a search field. Basically, I've got the NSTextView and the NSSearchField, and I need to know how to connect the two so that I can use the NSSearchField to search the NSTextView. I started off in Xcode with an AppleScript Application, and have not made any modifications to anything besides MainMenu.nib, which is where I have the main window. Please help!
    -Jake Simonds-Malamud

    Hi,
    I don't know, if it really fits your need, but take a look at the Core Date Videotutorial: http://developer.apple.com/cocoa/coredatatutorial/index.html
    and especially to the "Adding the Search Field" chapter: http://developer.apple.com/cocoa/coredatatutorial/coredata_mov14.html
    This might gives you an idea, what to do.
    ~ Markus

  • Serial input + Applescript crashing

    Hello, I am having a really annoying problem with my script. When I connect my device for serial communication through USB port and run the script, everything goes smooth. Once I stop the script and try to run it again, Applescript suddenly exits with an error. Basically I can not start script after stopping it without restarting Applescript. Any ideas on how to solve this issue?
    I use SerialPort X.
    Thanks in advance.

    Hm, looks like to are using Serial Port X Extension....
    Hint 1 from it's readme:
    *+Note: If you are using applescripts from an earlier version of Mac OS X (especially ppc) in Snow Leopard and they are not working correctly, try opening them in the Script Editor and re-saving.+*
    Hint 2:
    Let us or the developer of Serial Port X know which error message you get. To get the exact error msg you can use this code to copy it to you clipboard....
    try
    set onMode to false
    set use_port to "/dev/cu.usbmodem411"
    repeat until (get serialport list) contains use_port
    delay 3
    end repeat
    if (get serialport list) contains use_port then
    set onMode to true
    set myPort to serialport open use_port bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0
    delay 0.5
    serialport close use_port
    repeat while onMode is true
    set x to serialport read myPort
    if x is not equal to "" then
    beep
    if x is equal to "3" then
    display dialog "Success"
    end if
    end if
    end repeat
    end if
    on error msg
    set the clipboard to msg
    end try

  • Safari 4: Search Forum input messed up

    Just installed Safari 4. The Search Forum field in these forums looks weird. There seem to be two fields, on superimposed on the other. Is anybody else experiencing this problem?

    Hi Richard
    This has been a GUI bug in Safari since S4 Beta came out. Strange that Apple wouldn't have fixed it yet. Old adage about the shoemaker and his shoes.

  • Serial input read gives 10 samples but I only want 1

    I have my sensor connected to com1. Here is my code:
    Private Sub CWButton1_ValueChanged(ByVal Value As Boolean)
    Do While CWButton1.Value = True
    Data = CWSerial1.Read
    AllData = AllData + Data
    TextIn.Text = AllData
    CWGraph1.ChartY Val(Data)
    DoEvents
    Loop
    End Sub
    My problem is I just want one sample per loop, but I'm getting like 10. I don't know if I can change the output of the sensor. Is there a way to just get one sample at a time?
    BTW I'm new with measurement studio, but it is very cool!
    thanks,
    Brian

    Have you tried using the optional bufferSize parameter to CWSerial.Read? For more info, see the documentation for CWSerial.Read in the Measurement Studio reference.
    - Elton

Maybe you are looking for

  • Bank accounts query

    Dear All , this is regarding maintaining different bank accounts for EoU and Domestic division: How do we ensure that we pick the right bank a/c if we  have a common vendor between domestic and eou? Have we need to  split the vendors in domestic and

  • Loadmovie in AS#

    Dear my friends I have one .as file named Hanif.as with the following codes : package { import flash.net.URLRequest; import flash.display.*; import flash.events.*; public class Hanif { function Hanif():void { var i:Loader =new Loader(); //var mc:Movi

  • Direct Store Delivery concept in SAP

    Hi, What is DSD (Direct Store Delivery) in SAP and how is it different than normal delivery process? I mean we sell products (division) to the customers/warehouses through the distribution channel in both the cases.So, what is the difference between

  • Increasing release strategy levels/steps

    Dear gurus, We recently added a release code (FC) on our release strategies for our purchase requisitions. The condition is that all Pru2019s have to be released and/or checked by the Financial Controller prior to being released by the process leader

  • DW won't launch

    Just installed DW. Reboots haven't helped. Suggestions? Thanks in advance!