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
Hot Topic (More than 8 Replies) Knowing Com port at compile time. (Read 11024 times)
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Knowing Com port at compile time.
Sep 17th, 2014 at 9:42am
Print Post  
Hello there, thanks for VMicro, I do enjoy using VS for Arduino work.

A question, when compiling do you #define the Com port to be used for uploading? I would find this very handy when working with two boards with ethernet shields as it would allow me to switch the mac address depending on the target. Perhaps there is a way to do this already?

If you were do do this defineing the baud rate would occasionally be handy too.

Thanks,

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #1 - Sep 17th, 2014 at 11:25am
Print Post  
Hi,

No define is available but you can add your own defines to the project properties

Look for "Defines - Project" in the project properties help.

Thanks

  
Back to top
WWW  
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #2 - Sep 17th, 2014 at 11:46am
Print Post  
Yes. I'm using the same project to program two sets of hardware, if they both have the same address it fails! I's actually easier to define in the project than in the setup.. And when I forget..

The best way I've found so far is to tie a pin either high or low and test it in setup.

Ah well, thanks!

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #3 - Sep 17th, 2014 at 11:53am
Print Post  
Your solution is probably best but what I do in this case is create a new "Configuration" via the tool bar, then use the "Defines - Configuration" project property. That way I just switch configuration using the toolbar to use the different settings.
« Last Edit: Sep 17th, 2014 at 11:53am by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #4 - Sep 17th, 2014 at 1:00pm
Print Post  
That will do me a treat, I will learn how to use it properly. May revert to 'h/w numbering' the boards, but it's worth a punt and may be the only way on I/O limited boards.

Many thanks

Glyn
  
Back to top
 
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #5 - Sep 20th, 2014 at 9:53am
Print Post  
Tried it out, sadly you do not allow the COM port to be defined on a configuration basis, so it's still a two step process. Scope for errors. Ah well, I can cope - but perhaps you could pass the request for one or the other on?

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #6 - Sep 20th, 2014 at 11:24am
Print Post  
There is an Sp3 release of Visual Micro here http://www.visualmicro.com/forums/YaBB.pl?num=1410736832

It allows you to use the build properties within the project defines. You can see all the build properties when you switch on tools>options>visual micro>show build properties.

However the one you want is {serial.port}

So change your "defines - project" to be something like this:-

Code
Select All
myport {serial.port} 



This will give your code access to a define called myport with whatever port you have selected.

« Last Edit: Sep 21st, 2014 at 4:34pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #7 - Sep 21st, 2014 at 4:32pm
Print Post  
Many, many thanks, though to help anyone else that read this that


myport {serial.port}

works better.

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #8 - Sep 21st, 2014 at 4:35pm
Print Post  
Ahh good point thanks very much, I have also changed the example  Smiley
  
Back to top
WWW  
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #9 - Sep 22nd, 2014 at 3:54pm
Print Post  
Oh dear, I think I'm being stupid I set Defines - Project to:
SERIALPORT {serial.port}

This shows up in vsarduino.h as:
#define SERIALPORT {serial.port}

However I get the little red error sign at the to of the .ino file showing an error:
Error: Command line error: invalid macro definition definition: SERIALPORT {serial.port}
This is probably not the problem though, 

The code:
#ifdef SERIALPORT
     Serial << "Something set up \n\n";
#endif


#if SERIALPORT == COM7
     Serial << "COM7 set up\n";
#elif SERIALPORT == COM8
     Serial << "COM8 set up\n";
#elif SERIALPORT == COM6
     Serial << "COM6 set up\n";
#endif

Always tells me that 'Something set up' and 'COM7 set up' irrespective of the port set up

Though if I:
#define SERIALPORT 8

and mod the code it works.

#define TESTIT <stringliteral>
seems to be very implemetation dependant.

And I'm very new to complex preprocessor stuff, so some (more) help would be appreciated.

Ta,

Glyn
  
Back to top
 
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #10 - Sep 22nd, 2014 at 4:06pm
Print Post  
Whoops again, I have found a way for it to work:

int COM6 = 6;
int COM7 = 7;
int COM8 = 8;

if (SERIALPORT == 6)
     Serial << "in code COM6 set up\n";
if (SERIALPORT == 7)
     Serial << "in code COM6 set up\n";
if (SERIALPORT == 8)
     Serial << "in code COM6 set up\n";

That gets me going, what way do you reccomnd I do it, if different.

Glyn
  
Back to top
 
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #11 - Sep 22nd, 2014 at 5:58pm
Print Post  
Sorry, that makes no sense to me.

#if SERIALPORT == "COM7"

produces the error:
error: token ""COM7"" is not valid in preprocessor expressions

Must references I've found say that you can only compare to integer constants and character constants, NOT strings.

My suggested way works, but cannot be used to define variables.

Perhaps if the designed added {serial.port.number}?? Though probably there is a more complex way using macros. 

What preprocessor are you using in VM, doesn't use GPP methinks.

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #12 - Sep 22nd, 2014 at 7:06pm
Print Post  
Okay so dumb idea and I tried just using {serial.port} and it works fine. I forgot that Visual Micro parses the entire string of defines so you can create #variables

Code
Select All
{serial.port} 



Produces the following ...

Code
Select All
-DCOM7 



Remember that defines do not need values

So in your you can test if a define is defined

Code
Select All
#ifdef COM7 



Make sense?

ps: Visual Micro uses the tool chain described in the config files installed with the arduino ide. It changes depending on the board you use. There is a difference between intellisense and compile. For intellisense we hijack the compiler of the respective Ide (Visual Studio C++ or Atmel Studio Gcc). For compile we do exactly what the Arduino Ide does with Arduino's tools
« Last Edit: Sep 22nd, 2014 at 7:10pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Glyn Phillips
Newbies
*
Offline


Posts: 9
Joined: Sep 17th, 2014
Re: Knowing Com port at compile time.
Reply #13 - Sep 22nd, 2014 at 8:59pm
Print Post  
Aha!

So obvious when you (I) eventually get it. {serial.port} is just substituted in so it can be token OR value.

So just an #ifdef spots the correct case.

Well, I got there at last. Thanks for facility and help.

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Knowing Com port at compile time.
Reply #14 - Sep 22nd, 2014 at 9:00pm
Print Post  
Great thanks
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint