• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RFID Problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys i have a problem in my RFID kit program actually i can able to read
the device while after opening & closing the software originally given by the vendor.
can anybody help me to do my program as stand aone:

here my code is :


import java.io.*;
import java.util.*;
import javax.comm.*;

class opensesay implements Runnable,SerialPortEventListener {

static CommPortIdentifier portId;
static Enumeration portList;
static SerialPortEvent event;

InputStream inputStream;

SerialPort serialPort;
Thread readThread;

public static void main(String[] args) {

portList = CommPortIdentifier.getPortIdentifiers();

try
{

portId = CommPortIdentifier.getPortIdentifier("COM1");

opensesay reader = new opensesay();

}
catch (NoSuchPortException nspe)
{
System.out.println("No port named COM1 found");
}
catch (UnsupportedCommOperationException ucoe)
{
System.out.println("Could not enable receive threshold.");
}

}

public opensesay() throws UnsupportedCommOperationException {

try {

serialPort = (SerialPort) portId.open("opensesayApp", 2000);

} catch (PortInUseException e) {}
try {



serialPort.enableReceiveThreshold(16);

/*
System.out.println("Port '" + serialPort.getName() + "' settings:");
System.out.println("\tInput Buffer Size: " + serialPort.getInputBufferSize());
System.out.println("\tReceive Framing Enabled? " + serialPort.isReceiveFramingEnabled());
System.out.println("\tReceive Framing Byte: " + serialPort.getReceiveFramingByte());
System.out.println("\tReceive Threshold Enabled? " + serialPort.isReceiveThresholdEnabled());
System.out.println("\tReceive Threshold: " + serialPort.getReceiveThreshold());
System.out.println("\tReceive Timeout Enabled? " + serialPort.isReceiveTimeoutEnabled());
System.out.println("\tReceive Timeout: " + serialPort.getReceiveTimeout());
*/
inputStream = serialPort.getInputStream();



} catch (IOException e) {
}

try {

serialPort.addEventListener(this);



} catch (TooManyListenersException e) { }

serialPort.notifyOnDataAvailable(true);



try {

serialPort.setSerialPortParams(9600,SerialPort.DATABITS_7,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);



} catch (UnsupportedCommOperationException e) {}

readThread = new Thread(this);

readThread.start();

}



public void run() {

try {

Thread.sleep(10000);

} 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.OUTPUT_BUFFER_EMPTY:

break;

case SerialPortEvent.DATA_AVAILABLE:

byte [] readBuffer = new byte[4096];
//int [] s = new int [4096];


try {
while (inputStream.available() > 0) {
//System.out.println("Available bytes: " + inputStream.available());
int numBytes = inputStream.read(readBuffer);
//for(int i = 0;i<4096;i++) s[i] = readBuffer[i];
{
}
//System.out.println("Number of bytes read: " + numBytes);
}
System.out.println("\"" + new String(readBuffer).trim() + "\"");
//for(int i = 0;i<4096;i++)System.out.print("\"" + s[i]+ "\"");
} catch (IOException e) {}
break;

}

}
}

help me to trap this problem out.

thanks in advance
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Green Java:

Welcome to JavaRanch! While we at JavaRanch are glad to help you out, there's a few things that you could to do to help us help you. First, please read the Java Ranch Naming Policy and then change your display name to comply. (We are looking for a real-sounding first and last name.)

Second, What exactly is the problem you are having? A cursory glance doesn't show any specific problems, and many of us here do not have time for more than a cursory glance. If you can be as specific in you question as possible, that would help. (See How To Ask Questions The Smart Way

Third, please use [CODE] and [/CODE] tags along with formatting when posting code. It makes it easier to read.

Thanks
[ April 12, 2005: Message edited by: Joel McNary ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic