0 Replies Latest reply: May 27, 2009 2:15 AM by 843807 RSS

    Serial Event

    843807
      Hello guys,

      this is rohit working on serial port programing in java. here m facing problems,
      i have one function for receiving data from serialport, at the time of receving it is printing right data but after that it should get out of that function although i have put a break stmt still it is not getting out of that function. please take this code and give me solution for this asap.

      *// my function

      **public void serialEvent(SerialPortEvent event) {**

      **System.out.println("start of the event");**
      **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:**
      **// we get here if data has been received**
      **System.out.println("in the event ");**
      **byte[] readBuffer = new byte[20];**
      **try {**
      **// read data**
      **while (inputStream.available() > 0) {**
      **int numBytes = inputStream.read(readBuffer);**
      **}**
      **// print data**
      **String result = new String(readBuffer);**
      **System.out.println("Read: "+result);**
      **} catch (IOException e) {}**

      **break;**
      **}**
      **readThread.getState();**
      **System.out.println("out of main switchcase");**
      **//serialPort.close();**
      **// System.out.println("closed");**
      **// close();**
      **// serialPort.removeEventListener();**
      **//serialPort.notifyOnDataAvailable(false);**
      **// System.exit(0);**

      **}**



      **}**