Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners different output trying to execute same java code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


srinivasan
different output trying to execute same java code
0 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

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
SHOWING ERROR CODE 1064 WHILE TRYING TO EXECUTE PROCEDURE
SHOWING ERROR CODE 1064 WHILE TRYING TO EXECUTE PROCEDURE  I AM TRYING A SP BUT IT IS NOT SAVING AND WORKING.DOES THE STORED PROCEDURE WORK PARTLY... ARE WORKING PROPERLY. BUT WHEN I AM TRYING TO EXECUTE THEM INSIDE
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
Servlet signup same output - JSP-Servlet
Servlet signup same output  Ok i solved the problem of content type by res.setContentType("text/plain"), but the output is same it always prints....   Hi friend, Plz give full details with source code to solve
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
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
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
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
Execute .dll file in java?
Execute .dll file in java?  please anybody give me solution for executing .dll files in java
how to execute this code - JSP-Servlet
how to execute this code  hi guys can any help me in executing this bank application http://www.roseindia.net/jsp/bank.shtml, i need to use any database plz tell me step-to-step procedure for executing this,i need to create
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what?s the problem?  I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what?s
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what?s the problem?  I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what?s
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
Does finally always execute in Java?
Does finally always execute in Java?  Does finally always execute 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
error in program when trying to load image in java - Java Beginners
error in program when trying to load image in java  Hi, I'm trying to add an image to my GUI using java graphics. I have cleaned up all my compiler...) at sun.awt.image.ImageFetcher.run(Unknown Source) this is my code
Java Execute Jar file
operating system or platform. To execute a JAR file, one must have Java... file type java -jar [Jar file Name] in the command prompt. To execute...JAR stands for Java ARchive and is platform independent. By making all
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
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
output java - Java Beginners
; } a. what is the output of the ff. java statement:? i. System.out.println (secret...output java  public static int secret(int one) { int i; int...?  Hello Are you beginner? Ok, The first Output is 125
Advertisements
 

 

 

DMCA.com