raspberry pi serialRead doesn't work
Hello, I have same error, link below
https://www.raspberrypi.org/forums/viewtopic.php?t=223658
I call serailRead(int x) and after thap app is looping forever(serialWrite work fine)
Arduino a = new Arduino("/dev/ttyUSB0",115200);
boolean isOpen = a.openConnection();
Thread.sleep(1500);
if (isOpen) {
System.out.println("Start,led on");
a.serialWrite('1');
System.out.println(a.serialRead());
wait1(1000);
a.serialWrite('0');
wait1(1000);
a.closeConnection();
}else {
System.out.println("No connection");
}
hi @qweasd7924! Thanks for your question. It seems like in your code snippet, you use a.serialRead() not a.serialRead(int x). As warned in the instructions, its possible for a.serialRead() to enter into an infinite loop.
Please use a.serialRead(int x) - it is implemented in a semi_blocking manner that ensures that the thread will wait for AT LEAST ONE character and will read at most x characters in that function call.
Thanks also for linking the discussion thread on Raspberry Pi forums - I understand that a read+timeout function is definitely missing in my library - I'm considering adding such functionality when I have some free time - also happy to accept Pull Requests with the same!
Let me know if you have any other questions!
Thank you. I very often made a two ways communication . So it solves my problem.