different output trying to execute same java code

different output trying to execute same java code

i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding to read value from serial port :

import java.io.*;
import java.util.*;
import javax.comm.*;

public class SimpleRead implements Runnable, SerialPortEventListener {

  static CommPortIdentifier portId;
  static Enumeration portList;

  InputStream inputStream;
  SerialPort serialPort;
  Thread readThread;

  public static void main(String[] args) {


    portList = CommPortIdentifier.getPortIdentifiers();
    JOptionPane.showMessageDialog(null, "portList :"+portList.hasMoreElements()); 
    while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
       if (portId.getName().equals("COM3")) {
      //                if (portId.getName().equals("/dev/term/a")) {
        SimpleRead reader = new SimpleRead();
      }
    }
  }
}

public SimpleRead() {
  try {
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
  } catch (PortInUseException e) {System.out.println(e);}
  try {
    inputStream = serialPort.getInputStream();
  } catch (IOException e) {System.out.println(e);}
  try {
    serialPort.addEventListener(this);
  } catch (TooManyListenersException e) {System.out.println(e);}
  serialPort.notifyOnDataAvailable(true);
  try {
    serialPort.setSerialPortParams(9600,
      SerialPort.DATABITS_8,
      SerialPort.STOPBITS_1,
      SerialPort.PARITY_NONE);
  } catch (UnsupportedCommOperationException e) {System.out.println(e);}
  readThread = new Thread(this);
  readThread.start();
}

public void run() {
  try {
    Thread.sleep(20000);
  } catch (InterruptedException e) {System.out.println(e);}
}

public void serialEvent(SerialPortEvent 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:
    byte[] readBuffer = new byte[20];

    try {
      while (inputStream.available() > 0) {
        int numBytes = inputStream.read(readBuffer);
      }
      System.out.print(new String(readBuffer));
    } catch (IOException e) {System.out.println(e);}
    break;
  }
}
}

When i execute from netbeans, JOptionPane showing "portList : true" but when i double click on the jar file and tried to run, JOptionPane showing " portList : false"

Why there is different output trying to execute same java code

View Answers

Ads









Related Tutorials/Questions & Answers:
different output trying to execute same java code
there is different output trying to execute same java code...different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding... " portList : false" Why there is different output trying to execute same java
Advertisements
different output trying to execute same java code
different output trying to execute same java code  i am using net beans 7 ide and java 6 to develop my java projects. i used the following coding... " portList : false" Why there is different output trying to execute same java
How to ensure the same output by java code on 32 bit m/c and 64 bit m/c
How to ensure the same output by java code on 32 bit m/c and 64 bit m/c  How to ensure the same output by java code on 32 bit m/c and 64 bit m/c
How to print different Messge for the same NumberFormatException on different cause objects in JAVA?
How to print different Messge for the same NumberFormatException on different cause objects in JAVA?  How to print different Messge for the same NumberFormatException on different cause objects in JAVA? try { int
Java error cannot find symbol
("value of a"+a); } } Output : When you compile and execute...Java error cannot find symbol In this section you will learn about "cannot find symbol" in java. Java cannot find symbol is a type of error occurs
login for different user in the same page
login for different user in the same page  how can i do the login for different user in the same page throug jsp
Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same
Java code for Saving Marathi (Indian local language ) in Mysql and retrieving... going to save the marathi data into mysql and trying to retrieving the same from...; And my output is : Same o/p I gets in eclipse console. Can you tell me the solution
java code to validate column content of 2 different tables in 2 different databases.
java code to validate column content of 2 different tables in 2 different... at different server and display output( in excel format) using JAVA. if matched... that the migrated data is correct by creatng a script to run written in java
Updating rows who has same id with different values for each row from java program
Updating rows who has same id with different values for each row from java...) with "lalitha" as a value for sname column from java program. Same for records with sid... rows with same id. student table: sid sname age 2 aruna 25 2
how to write code for this output?
how to write code for this output?   1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
Java Read Lines from Text File and Output in Reverse order to a Different Text File
Java Read Lines from Text File and Output in Reverse order to a Different Text... to another text file. When that is done the output values of that file need to display in a JTextArea field. I have a good share of the code done and an area
ModuleNotFoundError: No module named 'sphinx_execute_code'
ModuleNotFoundError: No module named 'sphinx_execute_code'  Hi, My... named 'sphinx_execute_code' How to remove the ModuleNotFoundError: No module named 'sphinx_execute_code' error? Thanks   Hi
How send different files to browser at same time ..example(pdf&html) want display in same request using servlet
How send different files to browser at same time ..example(pdf&html) want display in same request using servlet  package com.readfiles; import... ServletException, IOException { String pdfFileName = "Java Tips.pdf
Execute .dll file in java?
Execute .dll file in java?  please anybody give me solution for executing .dll files in java
How can I output text typed in textarea by user on the same page?
How can I output text typed in textarea by user on the same page?  I... would like to take the comments and append them to the same page for all to see. Is this posibble and if so could you give me the code and instructions to do
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
updating rows which contains same id, different value for each row
updating rows which contains same id, different value for each row  ... rows with sid 5. Like this table may contains multiple records with same sid. Here my requirement is "I have to update those records which contains same sid
What is the equivalent method in Java which is equivalent to clrscr() in c/c++ . The code should help to clear the output screen ?
What is the equivalent method in Java which is equivalent to clrscr() in c/c++ . The code should help to clear the output screen ?  Hello to all, I have searched the net to know that is there any equivalent method for clrscr
java program of different shapes
java program of different shapes  pls help me to get the code of a java program of different shapes using menu
Does finally always execute in Java?
Does finally always execute in Java?  Does finally always execute in Java
can i Execute PHP code inside python script?
can i Execute PHP code inside python script?    can i Execute PHP code inside python script
Does finally always execute in Java?
Does finally always execute in Java?  Hi, I am learning exception handling in Java. I want to know if finally{} block is always executed or not in Java? Does finally always execute in Java? Thanks

Ads