Arduino double command [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to find a way for my Arduino to recognize some of the commands I'm attempting to send over serial (via Raspberry Pi)
I'm come as far as to detect 2 commands, but I'm stuck at my last.
To give a little bit more detail, I have my fingerprint scanner (GT-511C3) connected, and the library installed that will make it work.
That said, with the first 2 commands consist the verifying of fingerprints to ID (which works great) and the enrolling of fingerprints to new ID's (also work great) these parts of the script are triggered by the respective ASCII code "0" and "1".
My last, and problematic command "2" to remove an ID, is where I'm seeking help with.
Here's the code I'm currently working with:
if(ser == '2'){
while(val2 == 0){
char val3 = 0;
delay(10);
Serial.println("Type the ID to be deleted");
delay(2500);
fps.DeleteID(Serial.read());
val3 == Serial.read();
delay(10);
Serial.println("Deleted ID:");
Serial.print(val3);
delay(10);
val2 = 1;
}
}
I'm attempting to send the ASCII code "2" over Raspberry Pi through serial to the Arduino, followed by the ID that needs to be removed. It triggers after the command "2" is send, but refuses to read the ID and as such, I'm unable to finish it.
Any help or insight would really be appreciated.

val3 == Serial.read(); should be val3 = Serial.read();. You have an extra = which turns it into a useless comparison.

Related

"string too long" crash, c++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
im crashing on xstring with this error, can't figure out why
error:
the piece of code where its crashing on:
std::string response = f_network.request_to_server((xorstr_("a=") + crypt.rsa_enc(params.m_cUsername) + xorstr_("&b=") + crypt.rsa_enc(params.m_cPassword) + xorstr_("&c=") + crypt.rsa_enc(f_main.get_hwid()) + xorstr_("&pc=") + f_main.base64_encode(reinterpret_cast<unsigned char*>(hwid_part.data()), hwid_part.length())));
im using VS 2022, with the latest SDK
I already enabled multi-byte character set, but that didn't change anything, im desperate
this is a request to my API, where it asks for the username and password, i don't know why its crashing tho, i've tried everything i could, and it doesn't seem to work

Remove character from String c++/Arduino UNO [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I need to delete some characters from string. When i used erase it doesn`t work, compilation error erase no member named. Please help me. Probaly it is because I writing for Arduino UNO.
Arduino String class is quite different from std::string. For example erase doesn't exists. But there is method remove.
Anyway, you should start with: https://www.arduino.cc/en/Reference/HomePage
Expanding on what KIIV suggested, you could possibly do something like this:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
String words = "This is a sentence."; //reassign same string at the start of loop.
delay(1000);
Serial.println(words);
char c;
char no = ' '; //character I want removed.
for (int i=0; i<words.length()-1;++i){
c = words.charAt(i);
if(c==no){
words.remove(i, 1);
}
}
Serial.println(words);
delay(5000);//5 second delay, for demo purposes.
}
The Libraries in Arduino are customized in order to factor the memory constraints of the target Micro controller. For example , the Uno runs on a mega328P Atmel (now Microchip) device, which has only has 32 KB flash memory.

Probable reasons for Illegal seek in socket programming [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have received following error while sending data.
send:29-Illegal seek
Please explain the probable reasons for it. I am new to socket programming. Thanks in advance.
CHAR datasend[200];
DOUBLE64 fTime=0.0;
LONG32 sent_bytes=0;
while(TRUE)
{
memset(datasend,0,200);
fTime=getTime();
sprintf(datasend,"0=%.0lf ",fTime);
sent_bytes = send ( isockfd, datasend, strlen(datasend),0);
logDebug1("Pulse is %s and data bytes is %d",datasend,strlen(datasend));
if(sent_bytes <= 0)
{
logPError("send");
logTimestamp("Closing socket\n");
close(isockfd);
return NULL;
}
sleep(25);
}
You're not interpreting the right error because of the intervening logDebug1 call.
You have a send that returns something <= 0 and possibly an errno that you could inspect
You print something (logDebug1) which likely clobbers errno
You do some sort of perror which interprets the clobbered errno
What you want to do instead is check if sentBytes < 0, perror immediately and then maybe print more debugging stuff if you want.

How to explain the strange output by "puts" in c++? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am reading a piece of code written by others, there is one line like this:
cout << "Data Loaded" << endl;
it seems nothing strange, however, the actually output is:
[18607330327, 18790481919] [19144201237, 19327352831] [20754813973, 20937965567] [21291684885, 21474836479] [21474836482, 21653864362] [22011707392, 22190735274] [23622320128, 23801348010] [24159191040, 24338218922] [27197264917, 27204255743] [27205653525, 27212644351] [27230819349, 27230959453] [27233615872, 27235153757] [30064771072, 30067638186] [30073159680, 30076026794] [30098325504, 30098440106] [30098456576, 30098536200] Data Loaded
where does the extra output come from? if I comment that line, then, nothing is output.
I then include the <cstdio> and replace that line by puts("Data Loaded"), still, the extra info get printed.
cout is a buffered output stream, and endl not only creates a new line, it also flushes the buffer. Without the flushing of the buffer it might happen that you do not see the output of a previous cout.

Ncurses: movement [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.
What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.
Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR