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
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
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? 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