We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm still in trouble with the receiving data via serial interface.
After have solved some issues addressed in previous post, I'm now in troble with the this problem :
Using microPython I send a string like this :
'$$$','z1','N','22','30','23','45','N','N','N','N','N','N','N','1144'
Using Processing2 I receive the data ,split by ',' and fill in a string array. If I print all single array elements , I see exactly the same data that send, and the same if with a data scope I trace the received data.
Now the question is :
Why if I try to check if the first element in the array is "SSS" or if the second is "z1" the code is not working while if I display the data are right ?? :-?
Here part of code :
void serialEvent(Serial myPort)
{ String inBuffer_str = myPort.readStringUntil('\n');
println(inBuffer_str); // < --- here It's all right
String[] inBuffer = split(inBuffer_str.trim(), ",");
println(inBuffer[0].length()); // < ---this show 3
println(inBuffer[0].trim()); // < ---this show $$$
if (inBuffer[0]=="$$$")
{ println("ok");} // < ---never arrive at this point
}
I've also tryied to test the string instead that as $$$ like 363636 but nothing to do ?
And btw , it happens if I try to test in the same way any other element of the inBuffer array.
What is wrong in my code ? In which way can I test the string ? :(
Answers
http://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
http://Processing.org/reference/String_equals_.html
Thanks a lot ! I didn't think that there was a specific instruction for this, specially if apparently the data received were the right expected. I never end to learn something new ... :-S
@contax63, we need to use equals() in Java b/c even though 2 String objects got the same content,
they're very likely located at different memory addresses. That is, they're distinct objects! >-)
What
==
&!=
operators do is compare whether or not both objects have the same reference / pointer / memory address.Other programming languages overload those equality operators as to use equals() behind the scenes. :ar!
Ah, It's very clear now !. Thanks again.