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 Code compiling in Arduino IDE but not VS with VM add-in (Read 5693 times)
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Code compiling in Arduino IDE but not VS with VM add-in
Apr 19th, 2016 at 8:27am
Print Post  
the following code compiles in the Arduino iIDE but not in VS with Visual Micro add-in. In VS I get type declaration errors on the enums RelayState and CrossingZoneStste where I try to use them as parameters to a function. Any reason why it compiles in Arduino IDE and not in VS?

Code attached as its too long for the post.
« Last Edit: Apr 19th, 2016 at 12:09pm by dinotomFL »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #1 - Apr 19th, 2016 at 12:00pm
Print Post  
Hi,

Please attach your code as a text file. Thanks

I suspect this issue is an o/s bit of work that Arduino implemented between arduino 1.6.6 and 1.6.8

The changes they have made allow for this scenario more easily and will shortly be applied to visual micro

Prior to arduino 1.6.6 you would have had to add the types/structs etc to a h then #included the .h in the .ino code

You might find it works with visual micro if you move the definitions of crossingzone etc. to the end of the code file.

Otherwise you can switch on file>preferences>external editor in the arduino ide so the project can be open in both visual micro and arduino. Edit in vm and upload with arduino. but the solutions above are best
« Last Edit: Apr 19th, 2016 at 12:01pm by Tim@Visual Micro »  
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #2 - Apr 19th, 2016 at 12:10pm
Print Post  
As I suspected, moving those enum declarations to the end of the file only causes more errors, since the functions above it use them as parameters.. The original post is updated with full code sample attached.
« Last Edit: Apr 19th, 2016 at 12:13pm by dinotomFL »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #3 - Apr 19th, 2016 at 12:21pm
Print Post  
I created a header file and included it in the code where the other #includes are

#include "MyHeader.h"

I moved these defs to the header:-

Code (C++)
Select All
#pragma once
// Arduino Digital I/O pin numbers for MEGA
//note: digital pins 30-45
//MEGA is a MUST for this project
enum {
	Relay1 = 30, Relay2 = 31, Relay3 = 32, Relay4 = 33, Relay5 = 34, Relay6 = 35,
	Relay7 = 36, Relay8 = 37, Relay9 = 38, Relay10 = 39, Relay11 = 40,
	Relay12 = 41, Relay13 = 42, Relay14 = 43, Relay15 = 44, Relay16 = 45
};

enum RelayState { RELAY_OFF = HIGH, RELAY_ON = LOW };
enum class CrossingZoneState : uint8_t {
	CROSSINGZONE_CLEAR = 0, // no train in crossing area, also initialized state
	CROSSINGZONE_OCCUPIED = 1, // train detected by the entry sensor
	CROSSINGZONE_EXITING = 2  // train detected by the exit sensor, when sensor clears, state= Clear
};

//*-----( Declare Variables )-----*/
// hardware is an optocoupler 16 channel 12V relay
const uint8_t relays[] = { Relay1,Relay2,Relay3,Relay4,
Relay5,Relay6,Relay7,Relay8,
Relay9,Relay10,Relay11,Relay12,
Relay13,Relay14,Relay15,Relay16 };
enum { maxRelayCount = sizeof relays / sizeof relays[0] };
 



This is how Arduino and C++ have historically worked however I will be adding the new intelligence to allow a header to be avoided.
« Last Edit: Apr 24th, 2016 at 8:19pm by Tim@Visual Micro »  
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #4 - Apr 19th, 2016 at 12:44pm
Print Post  
and yes, I am using arduino version 1.6.8. When are the changes for VM expected to be implemented? I dont see an option in VM to just add a header, only to add both an empty cpp and h file?
« Last Edit: Apr 19th, 2016 at 12:51pm by dinotomFL »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #5 - Apr 19th, 2016 at 12:54pm
Print Post  
1)
You were right the code need to go in the .h. Can you confirm that now works okay for you as described above? It's quite simple to do and in some ways easier to read.

2)
They made the changes along with some new ways of searching for conditional library includes within private library code. The system took a few months to perfect yet still some users are finding they need to use 1.6.5 or below.

Arduino have said that the changes have now stablized but you will see the compiler in the arduino ide doing a lot more work than it used to. Visual Micro has started to implement the same but the prototype insertion point work is still to be done. You can see the first part of these changes on the new "vMicro>Deep Search Includes" menu item. It can be enabled and disabled because some users prefer to use the older system which is faster but requires more structured code.

In the Arduino design the prototype insertion point is a result of the deep search. The complexity for Visual Micro is that we don't just need this info when users compile. We also need it for intellisense and it's not acceptable to have long pauses when it comes to intellisense. 

As you can imagine, pauses during compile are acceptable but not when editing code. So we have to add a layer of intelligence and cache the results of the includes discovery. There are a lot of files included in the discovery system so the cache needs to be implemented with a lot of thought and without breaking what already works.

Hope this makes sense. I know a lot of newer users will be hitting this so it won't be too long before it is implemented. It's just a bigger and more far reaching change than the norm.
« Last Edit: Apr 19th, 2016 at 12:56pm by Tim@Visual Micro »  
Back to top
IP Logged
 
dinotomFL
Junior Member
**
Offline


Posts: 25
Location: Florida
Joined: Mar 28th, 2016
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #6 - Apr 19th, 2016 at 1:05pm
Print Post  
ok Im all set. I moved the state variable (CrossingZoneState state = ....) back to the .ino from the header and now it builds
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Code compiling in Arduino IDE but not VS with VM add-in
Reply #7 - Apr 24th, 2016 at 8:21pm
Print Post  
Great thanks for the update. A more intelligent insertion point for prototypes and headers will be in a release during next few weeks.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint