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

 
 


srinivasan
different output trying to execute same java code
0 Answer(s)      11 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

View Answers









Related Pages:
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
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
output
output  Sir,I am experiencing some problems with the output of this program.I got some useful help this website,but the output of the program isn't producing what it should.let me explain the output below is what happen when
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
PDO Execute
PDO Execute Code: In the current tutorial we will study how to execute a simple SQL code using PDO. In the previous tutorials we knew that how to connect... are different but rest of the coding will remain same, for example select
unable to see the output of applet. - Applet
. u just copy that java source code and compile that using javac then you copy that html part in the same directory and execute your first applet...unable to see the output of applet.  Sir, I was going through
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
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
JDBC Execute Statement
a database. In this Tutorial, the code illustrates an example from JDBC Execute... to create a new table on the name of existing table. The output of code show... JDBC Execute Statement      
JDBC Execute Query
JDBC Execute Query       The  Execute Query in JDBC retrieve the elements from a database. In this Tutorial we want to describe you a code that helps you to understand JDBC Execute Query
JDBC Execute Update Example
to describe you a code that helps you in understanding JDBC Execute update Example...;} } Output Table updated. Download code... JDBC Execute Update Example       JDBC
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
how to execute a unix shell script from a java program
the script name from a java code .once you execute this java program...how to execute a unix shell script from a java program  well , i am... solution . could anyone please give a sample code as of how to do this... what i am
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
Execute SQL Queries with Java Application
Execute SQL Queries with Java Application  ... values and retrieve values from the table. Before running this java code you...;} } Output of the program : Download Source code
input output
Input And Output       Introduction The Java I/O means Java Input/Output and is a part... DataInputStream with an appropriate BufferedReader. Here is the code of java program
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
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
different Font
different Font      ... and it's font name with size. Code Description: The following method... Font.TIMES_ROMAN Font.SYMBOL  The code of the program is given
How to communicate with different web applications ? ? ? ? - JSP-Servlet
with different web applications which are under same or different servers? ex... that first and second are different contexts. if i am trying... this if possible send me some code thanks in advance to all java experts. Deepak ji plz
Command Line Standard Output In Java
Command Line Standard Output In Java In this section we will discuss about the Command Line Java IO Standard Output. Standard streams, feature of various O/S, are written through standard output in Java. Standard streams can
* How to communicate with different web applications ? ? ? ? - JSP-Servlet
with different web applications which are under same or different servers? ex...* How to communicate with different web applications ? ? ? ?  Deepak.../jsp/show.jsp => so i meant to say that first and second are different
*** How to communicate with different web applications ? ? ? ? - JSP-Servlet
to communicate with different web applications which are under same or different servers? ex... to say that first and second are different contexts. if i am trying... this if possible send me some code thanks in advance to all java experts. Deepak ji
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
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
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
input output in java
input output in java  java program using filereader and filewriter   Hi Friend, Try the following code: import java.io.*; class... Friend, Try the following code: import java.io.*; class
Swing UI alignment Issue on different Platform - Swing AWT
Swing UI alignment Issue on different Platform  Hi, We are developing UI using Java Swing on windows. The problem is when we Test the same Ui... I execute the posted source code in Linux the LAF is getting changed (i.e. some
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
Spring supports remoting for six different RPC models:
Window and run the client code by giving the argument f:\springdemo>java... for six different RPC models: 1. Remote Method Invocation (RMI) 2. Hessian... two proxy factory beans to access the Enterprise Java Beans
Separating custom code in different file
Separating custom code  in different file We can separate custom code in the separate custom java script file. In this example ,we put the jQuery.../javascript" src="custom.js"></script> OUTPUT : Download
Input and Output package
Input and Output package  Hi guys, My professor used input and output statements in a different way.. She didnt used System.out.println(); instead she used in.readint() out.writeln() commands to read input and print output. she
Execute PHP in HTML
Execute PHP in HTML In this tutorial you will learn about the different ways of executing PHP code into HTML pages. In general, we have seen that a page... programming is required and your page is yet static just execute the php code
Input And Output
Input And Output       Introduction The Java I/O means Java Input/Output and is a part of java.io... with an appropriate BufferedReader. Here is the code of java program to Read text File
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
Open Source Excel
Writer gives you the same output with 1/4 of the lines of code that it takes to make the same output with POI. Office Writer is the only reporting solution that delivers real Excel and Word output, with all of the features and functions
Input / Output in Easiest Method in Java
Input / Output in Easiest Method in Java  How to input from keyboard, both strings and characters and display the result on the screen with the easiest method in Java?   Hi Friend, Try the following code: import
Output of this one - Java Interview Questions
errors. The following code displays "Executed" as an output. public class...Output of this one   public class Test { int i=-277; { try{ if(Byte i<<1) { System.out.println("Executed"); } else
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
different type input in java
different type input in java  hiiiii... get input different different type like as DataInputStream,Scanner i want to get source code of these all type of input method. thank   Java Read through DataInputStream: import
Redirecting the console output into a file in Java
Redirecting the console output into a file in Java  Hi, i coded... to redirect the output of the console to a text file. i used your tutorial, but it's not working for me. Could you please help for this code. [CODE] import
Hash value is not same - Java Beginners
Hash value is not same  Hi, I've two Excel files with same data... 2003 files is not same as the hash value of Excel 2007 file. What might... post your code. Thanks
Execute database query by using sql tag of JSTL SQL library
Execute database query by using sql tag of JSTL SQL library... to create application that execute sql query given by user using JSTL SQL Library. To execute query first create a data source and then execute sql query
Java Redirect output to file
Java Redirect output to file This section illustrates you how to redirect the output to the file. It may be comfortable to a programmer if they are able... to the file. In the given example, we have set the output stream of System
Execute .dll file in java?
Execute .dll file in java?  please anybody give me solution for executing .dll files in java
how to communicate with different web applications - JSP-Servlet
how to communicate with different web applications  how to communicate with different web applications which are under same or different servers? ex... to achive this if possible send me some code thanks in advance to all java experts
Error in a code. - Java Beginners
Error in a code.  This is the question I posted yesterday: "I'm trying to write a program that has a text field for input, two buttons and the output text area. A user is asked to type in a number. The first button when pressed

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.