User Program Upload Error

My customer can compile my sketch with no problems but when he attempts to upload the sketch to the Mega 2560 R3 board, he gets a list of errors related to the code in one of the included files. He is running Windows 10 and using Arduino version 1.8.19.

I have no problem compiling or uploading the sketch on my Windows 7 and Windows 10 computers.

** HERE IS THE INCLUDED CODE **

//========================================
// Copy string cSource to cDest and prevent overflow
//========================================
void stringCpy(char * cDest, char * cSource, int nLen)
{
int n = 0;
strcpy(cDest, "");

for (n = 0; n < nLen; n++) {
  cDest[n] = cSource[n];
}
cDest[nLen] = NULL;

}
//=======================================
// Determine the number of "cDelim" in "cSource".
//=======================================
int countData(char * cSource, char * cDelim)
{
char * cPos;
char * cBeg;
int nCnt = 0;

//* INITIALIZATION

cBeg = cSource;
if (cSource[0] == NULL) return 0;

//* MAIN PROCESSING

cPos = strstr(cBeg, cDelim);
while (cPos != NULL) {
nCnt += 1;
cBeg = cPos + strlen(cDelim);
cPos = strstr(cBeg, cDelim);
}
return nCnt;
}

** HERE ARE SOME OF THE ERROR S**

Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\DEVELOPMENT\NASDIO\NASDIO.ino:14:0:

C:/DEVELOPMENT/NASDIO/GenLib.h: In function 'void stringCpy(char*, char*, int)':

C:/DEVELOPMENT/NASDIO/GenLib.h:36:19: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]

 cDest[nLen] = NULL;

               ^~~~

C:/DEVELOPMENT/NASDIO/GenLib.h: In function 'int countData(char*, char*)':

C:/DEVELOPMENT/NASDIO/GenLib.h:134:23: warning: NULL used in arithmetic [-Wpointer-arith]

 if (cSource[0] == NULL) return 0;

                   ^~~~

Thanks in advance,

Nick Amendola

THAT IS WHAT i THOUGHT BUT HE TELLS ME THAT HE DOESN'T GET ANY ERRORS WHEN HE COMPILES THE SKETCH, ONLY WHEN HE TRIES TO UPLOAD IT.

Please, first of all start editing your post to include all the code inside a "code" tag (select all the code lines and click on the "CODE" button on the top of the editor). Without that, the code is almost unreadable, with some missing parts interpreted by the forum as special tags.

In the meanwhile and just to start, the only thing I notice is the almost useless "stringCpy()" function, doing the same as the standard "strncpy()" function. Further hints after you'll comply the requested
correct forum code formatting.
Thanks.

What if they were compile errors, what is wrong with the code?

If I copy all the code from the "Genlib.h" file to the sketch, I still don't get any errors.

Can you show us the errors, please?
You have only posted warnings.

Are you saying that Warnings can be ignored and the upload was successful?

Again
Your warnings/errors has nothing to do with upload process.

It considered a good practice do not ignore warnings, but fixing the problems they indicate.

You shouldn't ignore them, but often you can.
I can't tell if the upload was successful, because you didn't post the full message.

1 Like

The number of lines in the error file were too great so I only included a few of them. Here is the end of the file.

=======================================================
Sketch uses 27298 bytes (10%) of program storage space. Maximum is 253952 bytes.

Global variables use 1930 bytes (23%) of dynamic memory, leaving 6262 bytes for local variables. Maximum is 8192 bytes.

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_ReceiveMessage(): timeout

avrdude: stk500v2_getsync(): timeout communicating with programmer

An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

By the way - what is purpose of this function?

it is exact copy of strncpy() function

...but strncpy doesn't generate warnings.

2 Likes

Regarding warnings - please read about correct using of NULL statement

Please use forum search - this problem discussed every day here

I don't use this function in my sketch. It was written Visual Basic and merely converted to C++ since I didn't know at the time whether or not it was needed. I included the warnings as an example. I will check to see if I use any of the functions that we are getting warnings on.

If none are used, I will eliminate those that are not used and have him try again.

Strange solution - instead of fixing the problem, you want to remove the entire function...

No one has told me what is wrong with the code. If there is something wrong with the code, why can I compile and upload it on my computer. This sketch has been is installed and is operational for many customers. In all those cases, I uploaded the sketch to the board and sent them the hardware. I am trying to save time by allowing the customer to upload new versions of the sketch rather than send the hardware back to me.

I did - see post 14
Did you try to google with compiler messages?

You still don't understand that compilation and uploading are different processses.

What is your programming background?
You pretend to write software for the customers - and at the same time you do not know how an error differs from a warning and compilation from download

I have been programming for more than 50 years when the computers wouldn't fit in your house. I am fairly new to programming the Arduino. I know the difference between compilation, upload and download. Rather than criticize me, why don't you just tell me how I am using the NULL incorrectly or tell me where I can find the information.

The meaning of NULL can differ from compiler to compiler, but most widely it used as an implementation-defined null pointer constant. Using it as replacement of zero digit or null terminated char in string is incorrect.

In your code your should use null-terminator '\0' or just zero:

or

Google - your friend
https://en.cppreference.com/w/cpp/types/NULL

Thank you !!!