Hello everyone,
after getting started with some easier projects for my Arduino I decided to move on to something a bit more difficult.
As I have already done some programming in Java I tried interfacing my Arduino with a simple java script using the jSerial library (GitHub - Fazecast/jSerialComm: Platform-independent serial port access for Java). Sending data from the Arduino and parsing it in java works just fine, but if I try sending data to the Arduino, the Arduino always crashes, my Java script works just fine. The crash seems to occur completely independent of the sketch running on the Arduino. Even the blink example sketch crashes as soon as I send a byte from my java script, judging from the LEDs the arduino restarts immediately after receiving the first byte. I´ve also tried out another Arduino, but I´m facing the same problem on my Arduino Uno, as well as on a cheap nano clone. If I had to guess, I´d say that the bootloader is somehow responding to the serial data, but I´m way to inexperienced to actually figure out whats going on.
I´m using the following code in my Java script:
import java.io.IOException;
import com.fazecast.jSerialComm.*;
public class MainClass {
public static void main(String[] args) throws IOException, SerialPortInvalidPortException{
SerialPort myPort = null;
byte i = 123;
try {
myPort = SerialPort.getCommPort("COM6");
System.out.println(myPort.getSystemPortName());
myPort.setComPortParameters(9600, 8, 1, 0);
myPort.setComPortTimeouts(SerialPort.TIMEOUT_WRITE_BLOCKING, 0, 0);
while (!myPort.isOpen()) {
if (myPort.openPort()) {
System.out.println("Opend Port");
}
else {
System.out.println("Failed to open port");
}
}
myPort.getOutputStream().write(i);
myPort.getOutputStream().flush();
System.out.println("Wrote tesbyte");
}
finally {
myPort.closePort();
}
}
}
I hope I´m in the right forum for this issue as the problem seems to lie more on the java sight of the programming.
I´m looking forward to your support because to be honest I´ve become quite frustrated. The tutorials I´ve been following and the documentation of the library have offered no help for this kind of problem, there also aren´t a lot of projects using java for interfacing.
Thanks for all your efforts in helping me!