I tried to read data from serial port with GUI in Netbeans. but I can show data in command only.I can't show in text field. I have to use serial port in my project. This is my code for read data from serial port. It show in command only. How to read data from serial and show in text field.I used to append replace setText but It error. Maybe It can't used append in window application with Netbeans..
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[] readBuffer = new byte[20];
try {
// read data
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
// print data
String result = new String(readBuffer);
System.out.print(result); // Here can show data from serial port.
m_shTxt.setText(result); // Here can't show anything.When I use append It error.I cannot show result in text field.
} catch (Exception e) {
}