jar file not reading input from serial port

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 port
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
jar file not reading input from serial port
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
Advertisements
Reading a file from Jar JAVA
Reading 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 JAVA
Reading 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 timed
Reading 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
reading dropdown values from properties file in jsp
reading dropdown values from properties file in jsp  reading dropdown values from properties file in jsp
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
reading a csv file from a particular row
reading a csv file from a particular row  how to read a csv file from a particular row and storing data to sql server by using jsp servlet
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..., but the records obtained after reading the binary file are much less than those
initialise array by reading from file - Java Beginners
initialise 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 graph
reading 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 the data in excel file, i have to plot graphs based on CELL ID selected. please help
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from the properties file and display the data from the database. Now to load the data from
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
Count repetitions of every word from an input file
Count 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 database
Serial 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
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class name√Ę‚?¨¬?com.rational.ft.util.debug√Ę‚?¨¬
Reading duplicate keys from .properties file - Development process
Reading duplicate keys from .properties file  Hi, I am reading a .properties file using a basic java program.Though the .properties file will not allow duplicate keys, but still I want to develope a program to identify
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... file i get an empty text file can you guide me how to do this: /*this program reads multiple files * from a single directory. */ package elite.tech.com
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 the records from a .xlsx file and storing those records in database table
reading the records from a .xlsx file and storing those records in database table  Here is my requirement, I want to read the records from a .xlsx file and store that records in database table. I tried like this public class
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file... a program to read data from a file. Then use the numerical data within... stumped when it comes to reading the file and writing to a new file. My code
jar file built by ant jar task does not have all the dependant jars and throws exception while reading the appplicationContext,xml
jar file built by ant jar task does not have all the dependant jars and throws exception while reading the appplicationContext,xml  I have a spring...;/target> While executing the jar file using java -jar command it is throwing
ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library'
ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library...: ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library...-Serial-Port-Python-Library python with following command: pip install USPP
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
Reading the data from property file from java stand alone application in linux
Reading the data from property file from java stand alone application in linux  Please send me the example of reading the data from a property file from java stand alone application in linux. I don't know how to give path
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file... a program to read data from a file. Then use the numerical data within... it comes to reading the file and writing to a new file. My code is as follows
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
jar file
jar file  steps to create jar file with example
jar file
jar file  jar file where it s used
jar file
jar file  how to create a jar file in java
JAR FILE
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple... link: (adsbygoogle = window.adsbygoogle || []).push({}); Jar File
svg file reading and display
svg file reading and display  i want a sample program for reading and displaying the content of a svg file
jar file
jar 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... the class InputStream for reading the file content into byte array. The read... || []).push({}); import java.io.*; /** * Example of Reading file into byte
Thread for reading txt file
Thread 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 file
Problem 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 a text file in java
Reading a text file in java  What is the code for Reading a text file... 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 (adsbygoogle
Writing and Reading A File
and reading data from file for our assignment, but just stuck on how to proceed... from the user through GUI components and store the data into the text file...); } catch(Exception e) {} } }   To extract the data from text file
Reading big file in Java
Reading 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? (adsbygoogle = window.adsbygoogle || []).push
Reading an excel file into array
Reading 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 jsp
External 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 jsp
External 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 Value From console
Reading 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 console
Reading 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 pdf
reading 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
File path for jar file
File 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
Reading a big file effeciently
Reading 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...({});   Hi, Kindly check the program Java Read File Line by Line
file reading - Swing AWT
file reading  hi everybody, i want to know how to read contents of doc or exe file except for txt file in java.   Hi Friend, Use Jakarta POI library to read the contets of doc file: Here is the code: import

Ads