Hello.
Recently I've started a minor project using Arduino and I've hit a wall.
I'm trying for about 3 days to read a simple "Hello" from my board.
On the serial monitor everything works, but wanted to mannipulate my arduino with a java program.
Was working with this code I've found somewhere but I keep getting this error :
"Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
COM1
Exception : Unknown Application"
package serial;
import gnu.io.*;
import java.io.*;
public class Main {
public static void main(String[] s)
{
try
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("COM1");
if (portIdentifier.isCurrentlyOwned())
{
System.out.println("Port in use!");
}
else {
System.out.println(portIdentifier.getName());
SerialPort serialPort = (SerialPort) portIdentifier.open("ListPortClass", 300);
int b = serialPort.getBaudRate();
System.out.println(Integer.toString(b));
serialPort.setSerialPortParams(300, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
OutputStream mOutputToPort = serialPort.getOutputStream();
InputStream mInputFromPort = serialPort.getInputStream();
String mValue = "AT\r";
System.out.println("beginning to Write . \r\n");
mOutputToPort.write(mValue.getBytes());
System.out.println("AT Command Written to Port. \r\n");
mOutputToPort.flush();
System.out.println("Waiting for Reply \r\n");
Thread.sleep(500);
byte mBytesIn [] = new byte[20];
mInputFromPort.read(mBytesIn);
mInputFromPort.read(mBytesIn);
String value = new String(mBytesIn);
System.out.println("Response from Serial Device: "+value);
mOutputToPort.close();
mInputFromPort.close();
serialPort.close();
}}
catch (Exception ex)
{
System.out.println("Exception : " + ex.getMessage());
}
}
}
Any help is welcome.
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
COM1
Exception : Unknown Application