Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: Java Serial Communication using Javax.comm and saving variables into an array

  1. #26
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Serial Communication using Javax.comm and saving variables into an array

    Hi Everyone;

    Can somebody help how to get the output from the serial port to a variable that i can use in another class.

    I mean to say, in the below method, the code: System.out.print(new String(readBuffer)); gives the output to the output terminal but I want to store this output and use the output in another class.

    Please help.


    public void serialEvent(SerialPortEvent event) {

    // System.out.println("In Serial Event function().. " + event +
    // event.getEventType());
    switch (event.getEventType()) {
    /*
    * case SerialPortEvent.BI: case SerialPortEvent.OE: case
    * SerialPortEvent.FE: case SerialPortEvent.PE: case SerialPortEvent.CD:
    * case SerialPortEvent.CTS: case SerialPortEvent.DSR: case
    * SerialPortEvent.RI: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: break;
    */
    case SerialPortEvent.DATA_AVAILABLE:
    readBuffer = new byte[8];

    try {

    while (inputStream.available()>0) {

    int numBytes = inputStream.read(readBuffer);
    // System.out.println("Number of bytes read " + numBytes);
    }



    System.out.print(new String(readBuffer));

    } catch (IOException e) {
    System.out.println("IO Exception in SerialEvent()");
    }
    break;
    }

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Serial Communication using Javax.comm and saving variables into an array

    I want to store this output and use the output in another class.
    The byte array holds what was read.
    Provide access to that array to the other class.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Getting pixels from an image, and saving them in an array?
    By jtvd78 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 14th, 2011, 08:48 PM
  2. Serial comm reading freeze
    By java_dude in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 10th, 2011, 02:27 PM
  3. Changing Array variables from different classes
    By smellyhole85 in forum Collections and Generics
    Replies: 6
    Last Post: December 9th, 2010, 03:18 PM
  4. Replies: 3
    Last Post: May 15th, 2010, 02:05 PM
  5. theory about serial / parallel port & java
    By wolfgar in forum Java Theory & Questions
    Replies: 5
    Last Post: January 4th, 2010, 10:08 PM