« first day (1688 days earlier)      last day (1165 days later) » 

12:12 AM
@BlockofDiamond Just for the sake of readability, you should probably not use it. Even if it was well defined in your context, the next person to read the code may have the same question as you. It can make the code harder to understand without any real benefit.
 
jrh
12:40 AM
Is there a risk of strict aliasing violations when using ref structured bindings? Does the standard well define x in auto& [x, y] = p1; x = 25.5; to be a strict alias of a field of p1, or could a compiler fail to recognize x modifying the state of p1?
 
 
9 hours later…
user12761381
10:02 AM
Greetings everyone
 
user12761381
Anyone able to help me sorting a string comparison with C++ (Arduino)?
I'm driving crazy not being able to do simple string comparison...
 
user12761381
My arduino receives a command from PC (using Serial Port).
The command translated and converted as string is received correctly.
After the string is built; i pass the string to another method (as a string parameter).
in this method (that makes the comparisons / filters the command received) there are a few if statements containing:
 
user12761381
the command string to be compared.
However; even tho the strings match; Arduino acts otherwise
 
user12761381
void SetMode(String &cmd)
{
if (strcmp(((cmd).c_str()),((GetBoardInfo).c_str()))==1)
{
Serial.println("Reached");
}

if (cmd == "GetBoardInfo") { Print_BoardInfo(); } // Print Micro Controller Board Info.
if (cmd == "SetTerminate") { Shutdown(); } // Shutdown Peripherals.
}
 
user12761381
The received "cmd" is correct... But if statement comparison fails... Am I doing this wrong? I mean.. C# won't betray my logic like this...
 
user12761381
10:13 AM
Also:
- String length seems to be correct.
- if (cmd == "GetBoardInfo") { ... }
 
user12761381
if (cmd.equals("GetBoardInfo")) { ... }
if (strcmp(((cmd).c_str()), ((GetBoardInfo).c_str()) == 1)

All Fail
 
user12761381
I'm not posting another question in forum because I feel it is going to end up duplicate. However none of the answers got me to understand why or fix my issue.
 
nwp
@JohnConnor Use cmd == GetBoardInfo. Though by the name it looks like GetBoardInfo is a function you meant to call.
And yes, the logic is wrong. strcmp returns 0 when the strings are equal.
 
user12761381
Thumbs up.
Regarding the name:
I was initially performing a comparison with a const String variable (defined in a separate header class); thus the name (Above with Quotes in a desperate way to understand why it fails).

Regarding strcmp: nicely pointed. will give it a try
 
nwp
You probably should not use strcmp in C++ at all.
It's not exactly bad, the function works just fine, but mixing the C and C++ standard library like that is frowned upon and you will probably run into some issues and miss out on ease of use.
 
user12761381
10:33 AM
Thanks for the info.
After a few different attempts; I just realized that Arduino is actually doing the comparisons correctly. Just not sending the information back to Serial (using Serial.println("str").
C# Application will not receive the Incomming data. However Arduino Serial Monitor does.

After another Run: If i take the If statements on Arduino Project (on the method mentioned above); the Arduino Serial Communicates properly with C# Application.
 
user12761381
Weird
 
user12761381
12:44 PM
Alright. Regarding my questions above and after 2 more hours trying:
- Sending a command to arduino is received correctly.
- Checking that command the string is exactly the same as expected to be received; but:

a) I'm unable to compare the string. Sent from C# App the same string returns false.
From Arduino IDE Serial Monitor, the string is checked correctly.

b)instead of comparing the string; I tried "indexOf("mycommand")
 
user12761381
With indexOf("myCommand"); I can reach the matching command; however this interferes with remaining commands as they all start with "get" word.
Any Idea why this could occur?
I've also tried sending the terminator char \0 or \n but same thing occurs.
I'm clueless why would the arduino say the string is not equal to stored variable command
 
nwp
1:16 PM
I would recommend that you stop brute forcing comparison functions. It's not like you will eventually find a comparison function that "works".
When printing what the Arduino received, add markers around the text. Something like std::cout << ">>>" << cmd << "<<<\n";. That way you will see trailing spaces and similar that are difficult to spot on the serial monitor.
I also wonder how your Arduino code is supposed to know the end of a command. Is there a separator? Does it handle partially received commands correctly? Are you sure you didn't store the separator?
 
or print the hex of what you received
 
 
3 hours later…
4:44 PM
@ratchetfreak When printing hexes, be sure you protect yourself with a pentagram.
 
@JerryCoffin What do you think this is... some weird five bit architecture! We use octograms around here! 8 bit byte or die!
 
@Mgetz Anything beyond 5-bit Baudot codes is just frippery and nonsense.
 
5:01 PM
Next you'll want to go beyond punctuation, and try to support languages other than English. And that will just lead to pure madness!
 

« first day (1688 days earlier)      last day (1165 days later) »