@Paul Clapham: The first part is correct...send commands to arduino, receive responses back. That part is correct. When it comes to simple turn on and off a string of LEDS. That is fine. It's when I issue the blink led command is what is fouling things up: 1.) Press button, changes color to yellow, 2.) led blinks 10 times, 3.) when led is done blinking string from arduino is sent to java program to turn the button back to a non-yellow color and so on.
So maybe I need to split the if statements up. How and where to place it is the question?
I don't see why you need any if-statements at all. You're sending a request and expecting two responses, separated by a significant period of time. So to receive the two responses it seems to me that you need to call serialRead to get the first response (and then process it) followed by calling serialRead to get the second response (and then process it). Two calls to serialRead because you're expecting two responses. Does that sound right?
You shouldn't need polling if the serialRead method blocks as the API doc says. The method's doc says it won't return until it has read at least one character.
However the print outs you posted showed that the variable: line2 was empty after data was supposed to have been read into it.
@Norm Radder: The data never gets to line2 as both if statements have been occurring at the same time...they need to be separated by a timer or something....one is invoked at the beginning and the other gets invoked when it receives ABO...which gets sent at the end of the blinking leds
They should NOT need a delay between calls if the serialRead method blocks until it has data.
If the serialRead method blocked, then the code could have just 4 statements: read/print what was returned/read/print what was returned
If the serialRead does not block then the code needs to delay some how between reads so that the reads are done AFTER the device has written some data to be read.
Add the current time to the print statements so that you can see how much delay there is between when the data is read and printed.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop