Storing Input buffer from COM1 into Mysql through Java -


so building rfid tracking system, consists of rfid reader , tags. have programmed tags , connected reader through rs-232 port of computer.i open hyper terminal or console serial communication. whenever tag detected id shows in hyper terminal. means fine.

now achieve same in java, i.e serial communication. using javax.comm api serial communication achieved code.

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();      while (portlist.hasmoreelements()) {         portid = (commportidentifier) portlist.nextelement();         if (portid.getporttype() == commportidentifier.port_serial) {              if (portid.getname().equals("com1")) {         //                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;     } }} 

so need achieve whenever tag swapped reader, tagid recieved com port, go database along time stamp.

so created database :

create table track( tagid number(8), timet timestamp ); 

so should whenever card swiped table gets entered tag id (received com port) , time , date of swipe (timestamp of swipe).

any appreciated.

p.s. : using windows , mysql


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -