Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic String samples from Arduino site don't compile on Visual Studio 2015 with VM (Read 5803 times)
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
String samples from Arduino site don't compile on Visual Studio 2015 with VM
May 5th, 2016 at 5:48pm
Print Post  
The following example from the Arduino site on the String library works fine using the Arduino IDE but doesn't upload and run on VS2015 with VM add-in. It gives the following error.
Code (C++)
Select All
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // send an intro:
  Serial.println("\n\nString indexOf() and lastIndexOf()  functions:");
  Serial.println();
}

void loop() {
  // indexOf() returns the position (i.e. index) of a particular character
  // in a string. For example, if you were parsing HTML tags, you could use it:
  String stringOne = "<HTML><HEAD><BODY>";
  int firstClosingBracket = stringOne.indexOf('>');
  Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);

  stringOne = "<HTML><HEAD><BODY>";
  int secondOpeningBracket = firstClosingBracket + 1;
  int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket);
  Serial.println("The index of  the second > in the string " + stringOne + " is " + secondClosingBracket);

  // you can also use indexOf() to search for Strings:
  stringOne = "<HTML><HEAD><BODY>";
  int bodyTag = stringOne.indexOf("<BODY>");
  Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag);

  stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
  int firstListItem = stringOne.indexOf("<LI>");
  int secondListItem = stringOne.indexOf("<LI>", firstListItem + 1);
  Serial.println("The index of the second list tag in the string " + stringOne + " is " + secondListItem);

  // lastIndexOf() gives you the last occurrence of a character or string:
  int lastOpeningBracket = stringOne.lastIndexOf('<');
  Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket);

  int lastListItem = stringOne.lastIndexOf("<LI>");
  Serial.println("The index of the last list tag in the string " + stringOne + " is " + lastListItem);


  // lastIndexOf() can also search for a string:
  stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
  int lastParagraph = stringOne.lastIndexOf("<p");
  int secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);
  Serial.println("The index of the second to last paragraph tag " + stringOne + " is " + secondLastGraf);

  // do nothing while true:
  while (true);
}
 




Quote:

Uploading 'StringTets' to 'Arduino/Genuino Uno' using 'ArduinoISP'
The uploader returned an error
avrdude: Error: Could not find USBtiny device (0x2341/0x49)


And while we are at it. The VM add-in doesn't like this either which should work.

Code (C++)
Select All
boolean writeToFileOnSD(File fileObj, String fileName, String textToWrite) {
	int fileSize;

	if (!SD.begin(4)) {
		Serial.println("initialization failed!");
		return false;
	}

	//good to go, open the file
	fileObj = SD.open(fileName, FILE_WRITE);

	if (fileName.toLowerCase.indexOf("error") > 0)
	{
		//create error string
	}
	if (fileName.toLowerCase.indexOf("data") > 0)
	{
		//create data string
	}
	fileSize = fileObj.size();
	fileObj.println(tempString);
	fileObj.close();

	if (fileObj.size() > fileSize)
	{
		return true;
	}
	return false;

}
 



With this error:

Quote:


RFIDTesting.ino:In function 'boolean writeToFileOnSD(SDLib::File, String, String)
RFIDTesting.ino:86:25: error: 'fileName.toLowerCase' does not have class type
:if (fileName.String::toLowerCase.indexOf("error") > 0)
Error compiling project sources
« Last Edit: May 5th, 2016 at 5:58pm by dinotomFL »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #1 - May 5th, 2016 at 6:35pm
Print Post  
Hi,

These errors are nothing to do with string samples.

Code
Select All
Uploading 'StringTets' to 'Arduino/Genuino Uno' using 'ArduinoISP'
The uploader returned an error
avrdude: Error: Could not find USBtiny device (0x2341/0x49) 



This probably means you have ticked "vMicro>Always use programmer for upload" by mistake. Untick it for standard serial usb upload.

The arduino ide is confusing for new users because it shows a programmer is selected but it only uses it if you click "Sketch>Upload using programmer". The normal upload button in the arduino ide always uses serial usb which is not classed as a programmer.

Code
Select All
RFIDTesting.ino:In function 'boolean writeToFileOnSD(SDLib::File, String, String)
RFIDTesting.ino:86:25: error: 'fileName.toLowerCase' does not have class type
:if (fileName.String::toLowerCase.indexOf("error") > 0)
Error compiling project sources 



Looks like a syntax error because I would expect fileName.toLowerCase should be a method fileName.toLowerCase()
« Last Edit: May 5th, 2016 at 6:46pm by Tim@Visual Micro »  
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #2 - May 5th, 2016 at 7:24pm
Print Post  
I never said the errors had anything to do WITH string samples, I said the string samples I was testing were producing errors in VM but not in Arduino IDE.

The proper syntax when chaining is
   
Code (C++)
Select All
 fileName.toLowerCase.indexOf("error");
 



if I was using it alone, yes it should be 
Code (C++)
Select All
fileName.toLowerCase();
 



In any event, the VS editor shows no error using as above but if you put two parens at end of toLowerCase it errs, so that's not proper syntax.

I'm more concerned as to why that error is occuring, vs the uploading. Every tutorial on string manipulation on Arduino shows it this why but VM won't compile it.

Quote:
RFIDTesting.ino:In function 'boolean writeToFileOnSD(SDLib::File, String, String)
RFIDTesting.ino:86:25: error: 'fileName.String::toLowerCase' does not have class type
:if (fileName.toLowerCase.indexOf("error") > 0)
Error compiling project sources


So what is the correct syntax, if above is NOT correct, to do this in the VM environment?
« Last Edit: May 5th, 2016 at 7:35pm by dinotomFL »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #3 - May 5th, 2016 at 7:42pm
Print Post  
Okay thanks and sorry if there is some confusion.

I want to be clear about a couple of things

1) 

The 1st error shown in your post is an upload error and that means the compile was successful. It might help if you post the full output so that I can highlight the output that shows compile success and program size.

Hopefully you can confirm that the upload error you posted is resolved with my previous instruction.

2)

I attach a picture showing identical error in the arduino ide when attempting to use your code. 

I included the SD library which I expect you have also done.

Can you confirm which board and arduino ide version you are using?

« Last Edit: May 5th, 2016 at 7:42pm by Tim@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #4 - May 5th, 2016 at 8:15pm
Print Post  
My apology for not being clear. The upload error, is using the code posted which is a string sample from the Arduino site. Question for that, how can I upload that in VS2015 with VM

The other problem, string.toLowerCase.indexOf("error"); is from another sketch method, shown below, which shows no intellisense erros but doesnt compile, and you've seen the error text already.

Code (C++)
Select All
boolean writeToFileOnSD(File fileObj, String fileName, String textToWrite) {
	int fileSize;

	if (!SD.begin(4)) {
		Serial.println("initialization failed!");
		return false;
	}

	//good to go, open the file
	fileObj = SD.open(fileName, FILE_WRITE);

	if (fileName.toLowerCase.indexOf("error") > 0)
	{
		//create error string
	}
	if (fileName.toLowerCase.indexOf("data") > 0)
	{
		//create data string
	}
	fileSize = fileObj.size();
	fileObj.println("error string here");
	fileObj.close();

	if (fileObj.size() > fileSize)
	{
		return true;
	}
	return false;

}
 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12188
Location: United Kingdom
Joined: Apr 10th, 2010
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #5 - May 5th, 2016 at 8:34pm
Print Post  
Quote:
The upload error, is using the code posted which is a string sample from the Arduino site. Question for that, how can I upload that in VS2015 with VM


Yes. I already explained previously that you ticked the menu item "vMicro>Always upload using programmer" by mistake. 

I asked you to un-tick it so that when you attempt to upload the usb cable is used.

Did you read my response about "vMicro>Always upload using programmer"?

Quote:
The other problem, string.toLowerCase.indexOf("error"); is from another sketch method, shown below, which shows no intellisense erros but doesnt compile, and you've seen the error text already


I explained that the same code fails to compile in the Arduino Ide for me with the same error.

Reading the Arduino string documentation I do not see how your code would work.

The arduino documentation shows that the method toLowerCase() changes the string variable. It does not work like you might expect in other languages where by toLowerCase() returns a lower case copy of the string.

You can clearly see this in their example code from the documentation page

https://www.arduino.cc/en/Tutorial/StringCaseChanges

Code
Select All
// toUpperCase() changes all letters to upper case:
  String stringOne = "<html><head><body>";
  Serial.println(stringOne);
  stringOne.toUpperCase();
  Serial.println(stringOne);
 



Here is the documented description for the case change functions

Quote:
The String case change functions allow you to change the case of a String. They work just as their names imply. toUpperCase() changes the whole string to upper case characters, and toLowerCase() changes the whole String to lower case characters. Only the characters A to Z or a to z are affected.


Summary

To avoid confusion I made the following code based on your snippet. You didn't answer the question about which Arduino Ide version you are using so I tested with Arduino.cc 1.6.7 and Arduino.org 1.7.8. Both gave the same error. Here is the full code:-

Code
Select All
#include <SD.h>
#include <SPI.h>
char tempString[50];
void setup() {}
void loop() {}

boolean writeToFileOnSD(File fileObj, String fileName, String textToWrite) {
	int fileSize;

	if (!SD.begin(4)) {
		Serial.println("initialization failed!");
		return false;
	}

	//good to go, open the file
	fileObj = SD.open(fileName, FILE_WRITE);

	if (fileName.toLowerCase.indexOf("error") > 0)
	{
		//create error string
	}
	if (fileName.toLowerCase.indexOf("data") > 0)
	{
		//create data string
	}
	fileSize = fileObj.size();
	fileObj.println(tempString);
	fileObj.close();

	if (fileObj.size() > fileSize)
	{
		return true;
	}
	return false;

} 

« Last Edit: May 5th, 2016 at 8:37pm by Tim@Visual Micro »  
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: String samples from Arduino site don't compile on Visual Studio 2015 with VM
Reply #6 - May 5th, 2016 at 9:16pm
Print Post  
Thank you. I understand solution one but am not at my computer to verify.

Re: the string lowercase problem, you are correct. I re-read the site as well. Unlike in other .Net languages, you don't set a variable to lowercase because this one is void, it just changes the current variable. Then I will need a new line to do indexOf. Thank you for you assistance.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint