Results 1 to 1 of 1
- 07-23-2009, 12:53 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Serial port - send command respond
I made an app, that send command + checksum to the GPS tracker and should return response. But i dont get it... i get only gps data every second - speed, position an so on.
I don't know if something is wrong with my code or GPS has some trick or something...
Code:
Java Code:// in main class i open port, insert command and calculate checksum // writer class: public void run () { serialPort.notifyOnDataAvailable(true); try { serialPort.notifyOnOutputEmpty(true); } catch (Exception e) { System.out.println("Error setting event notification: "+ e.toString()); } System.out.println("Writing \""+messageString+"\" to "+serialPort.getName()); try { //write to serial port out.write(messageString.getBytes()); out.flush(); } catch (IOException e) { System.out.println("Write error: "+ e); } } // LISTENING TO SERIALPORT EVENTS 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: // we get here if data has been received byte[] buffer = new byte[1024]; int len = -1; try { while ( ( len = this.in.read(buffer)) > -1 ) { System.out.print(new String(buffer,0,len)); } } catch ( IOException e ) { e.printStackTrace(); } break; } }
Similar Threads
-
Reading from Serial port!
By Dogge in forum New To JavaReplies: 2Last Post: 12-01-2010, 03:21 AM -
Serial Port
By radhika in forum New To JavaReplies: 5Last Post: 11-06-2009, 10:40 AM -
Serial Port Ethernet
By nipunreddevil in forum NetworkingReplies: 2Last Post: 03-01-2009, 05:22 PM -
throw java to connect to serial port and Send AT Commands to dial up modem
By jfouadazem in forum Advanced JavaReplies: 4Last Post: 02-28-2009, 08:39 PM -
serial port
By musiigedeo in forum Advanced JavaReplies: 0Last Post: 07-23-2007, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks