jar file not reading input from serial port
i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown when i execute thru jar file. but when i execute thru netbeans, data is received from comm port. why it is happening? i attached the coding i used.
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
boolean portFound = false;
String defaultPort = "COM2";
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
JOptionPane.showMessageDialog("Found port: "+defaultPort);
portFound = true;
SimpleRead reader = new SimpleRead();
}
}
}
if (!portFound) {
JOptionPane.showMessageDialog("port " + defaultPort + " not found.");
}
}
private int numBytes;
private String s;
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {
System.out.println("port in use");
}
try {
System.out.println("Getting input Stream");
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) {}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException 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.OUTPUTBUFFEREMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[8];
byte[] readBuffer2=null;
try {
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
readBuffer2= new byte[numBytes];
for(int i=0;i
}
s = new String(readBuffer2);
System.out.println("readbuffer......"+ s);
} catch (IOException e) {}
break;
}
}
}
View Answers
Related Tutorials/Questions & Answers:
jar file not reading input from serial portjar file not
reading input from serial port i used a coding for getting data
from serial port. JOptionbox with "
port not found" message is shown when i execute thru
jar file. but when i execute thru netbeans, data is received
jar file not reading input from serial portjar file not
reading input from serial port i used a coding for getting data
from serial port. JOptionbox with "
port not found" message is shown when i execute thru
jar file. but when i execute thru netbeans, data is received
Advertisements
Reading a file from Jar JAVAReading a
file from Jar JAVA I have added one excel sheet into a
jar file.
can anybody tell me how i can read that
file.
actually when i am running code
from eclipse i able to read it but when i am adding that
jar file Reading a file from Jar JAVAReading a
file from Jar JAVA I have added one excel sheet into a
jar file.
can anybody tell me how i can read that
file.
actually when i am running code
from eclipse i able to read it but when i am adding that
jar file Reading string from file timedReading string
from file timed So I want to make a
file reader/ buffered reader that reads a new line of the textfile, lets say every 30 second.
Like it reads the first line, waiting 30 seconds, read the next line and so one
Writing to and reading from a binary file in java.Writing to and
reading from a binary
file in java. I have written... the binary
file from another program as follows:
m_dis = new DataInputStream... work, but the records obtained after
reading the binary
file are much less than
initialise array by reading from file - Java Beginnersinitialise array by
reading from file Hello, I wnat to know how i would initialise an array by
reading a text
file, which contains a simple pattern.
for example the
file may look as shown below, with the star character
reading data from excel file and plotting graphreading data
from excel
file and plotting graph I am doing a project using NetBeans in which i have to take
input an excel
file and then using... at the same time
from one excel
file using different columns..how can i do that?
waiting
Count repetitions of every word from an input fileCount repetitions of every word
from an
input file Hello..i got to know how can i count the repetitions of every word present in a specific
input file?For suppose if i have a url log
file which have time,url's,ip address etc
How to create file from input values in Jframe ?How to create
file from input values in Jframe ? hi i m doing my project using java desktop application in netbeans.i designed a form to get... to take these details and make a
file that can be appended each time.how
Serial COM Port Value in to databaseSerial COM
Port Value in to database How save the
serial COMport value in mysql databse.
Following code is here.
package simpleread;
import...();
if (portId.getPortType() == CommPortIdentifier.PORT_
SERIAL Java error reading from file Java error
reading from file
Java error
reading file...
reading from file. For this we have a class error
reading from file. Inside
Reading XML from a File Reading XML
from a
File
This Example shows you how to Load Properties
from the XML
file via... to
create new DOM parsers. Some of the methods used for
reading XML
from a
Reading a text file in javaReading a text
file in java What is the code for
Reading a text
file... in java.io.* package for
reading and writing to a
file in Java.
To learn more about
reading text
file in Java see the tutorial Read
File in Java.
Thanks
jar filejar file steps to create
jar file with example
jar filejar file
jar file where it s used
jar filejar file how to create a
jar file in java
JAR FILEJAR FILE WHAT IS
JAR FILE,EXPLAIN IN DETAIL?
A
JAR file... and applications.
The Java Archive (
JAR)
file format enables to bundle multiple... link:
Jar File Explanation
jar filejar file how to run a java
file by making it a desktop icon i need complete procedur ..through cmd
Reading file into bytearrayoutputstream input stream and byte output stream. This is and
good example of
reading file...
In this example we have used the class InputStream
for
reading the
file...
import java.io.*;
/**
* Example of
Reading file into byte array
Thread for reading txt fileThread for
reading txt file how to use 3 thread to read 3 txt
file?
To create three threads for
reading the
file and three threads for getting the strings out of the queue and printing them.
thanks
Problem reading word fileProblem
reading word file Deepak you provide me code for extarcting equation
from a word
file and also to write in a word file.But when I again want to read preveously created word
file(created by your code) it gives an error
Reading big file in JavaReading big
file in Java How to read a big text
file in Java program?
Hi,
Read the complete tutorial at How to read big
file line by line in java?
Thanks
Reading Value From consoleReading Value
From console In case of String data Type readLine method of DataInputStream class
read complete line of the given string but the next method of Scanner
class doesn't read the complete line of String. why
Reading Value From consoleReading Value
From console In case of String data Type readLine method of DataInputStream class
read complete line of the given string but the next method of Scanner
class doesn't read the complete line of String. why
reading from pdfreading from pdf how can i read specific words
from pdf
file?
Java Read pdf
file
import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class ReadPDF {
public
Writing and Reading A File and
reading data
from file for our assignment, but just stuck on how to proceed... the user
input from the user through GUI components and store the data...;To extract the data
from text
file and save it to jtable, visit the following links
Reading an excel file into arrayReading an excel
file into array Hi,
I'm trying to read in an excel
file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new to JavaScript. Can anyone
External file reading in jspExternal
file reading in jsp i have written a jsp page(ReadExt.jsp) in my application which reads a text
file content
from a system...
file. It uses BufferedReader class to read that particular
file.
<%@ page
External file reading in jspExternal
file reading in jsp i have written a jsp page(ReadExt.jsp) in my application
which reads a text
file content
from a system...; The given code reads the given
file. It uses BufferedReader class to read
Reading a big file effecientlyReading a big
file effeciently How to read a large text
file quickly without memory error in Java?
What is the best method to read a big
file very efficiently?
Thanks
Hi,
Kindly check the program Java Read
File File path for jar fileFile path for
jar file Hi Experts,
I have created one eclipse...
jar file of that application, unfortunately it is giving the error that resource not found for the template
file.
Also I had tried to get that path
from user
Best way to reading file in javaBest way to
reading file in java Hi,
As a beginner I want to learn about Java programming and make a program for
reading a text
file in java. What is the best way for
reading file in Java?
Thanks