Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RFID problem  RSS feed

 
Sathiskumar.S
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!