• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Multiple Lines

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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?
 
Sheriff
Posts: 26961
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Master Rancher
Posts: 4599
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Scott Eric Catalano
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
 
Norm Radder
Master Rancher
Posts: 4599
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

need to be separated by a timer  


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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic