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) Arduino project compile doesn't run post-build command? (Read 2798 times)
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Arduino project compile doesn't run post-build command?
Sep 22nd, 2021 at 6:34pm
Print Post  
Hi,

I have a Arduino project in VS2019 and have specified a post-build command to run after build in all configurations.  However, it doesn't seem to run - or at least I can't see any evidence that it runs.  The command line points to a very small console application that simply sends "Hello World" to the console.

I can run the executable from a command line, and I get the expected behavior, but nothing happens when I compile the Arduino project.

As another test, I created the WinApp example at https://docs.microsoft.com/en-us/visualstudio/ide/how-to-specify-build-events-cs..., and modified the post-build command to call my executable rather than the one in the example.  This worked, and I could see my 'Hello World' printout in the output area. 

Am I missing something here?

TIA,

Frank
« Last Edit: Sep 22nd, 2021 at 7:09pm by FrankP »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino project compile doesn't run post-build command?
Reply #1 - Sep 22nd, 2021 at 7:54pm
Print Post  
Because we perform an Arduino build you have to use the arduino build hooks.

We have some simple examples here which is linked into our documentation index on the main site.

https://www.visualmicro.com/page/Arduino-Build-Events-and-Hooks.aspx

You can add the hooks to a board.txt in the project folder (see the vMicro>Add Code menu for 1-click addition).
  
Back to top
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #2 - Sep 22nd, 2021 at 10:23pm
Print Post  
Tim,

Yep - that did it - Thanks!!

I see {ProjectDir} and {sketch_path} variables - is there a list of available parameters?

TIA,

Frank
« Last Edit: Sep 22nd, 2021 at 10:26pm by FrankP »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino project compile doesn't run post-build command?
Reply #3 - Sep 24th, 2021 at 3:05am
Print Post  
If you switch on the "show build properties" option you will see all the properties.

For users with VS knowlege some of the more popular macro names such as ProjectDir are made available.
  
Back to top
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #4 - Sep 25th, 2021 at 4:35pm
Print Post  
Tim,

Thanks for the info on build properties - I used 'show build properties' and selected a few for post-build 'hooks', as shown below in the output from a recent compile.

However, I have a question. For those postbuild recipe entries that use 'ECHO', I'm getting two lines of output - one shows the command that produces the echo, and the second one shows the actual output.  Is there any way to supress the 'this is what I'm going to do' line? 

Compiling 'Teensy Flash Demo V1' for 'Teensy 3.5'
Using previously compiled file: C:\Users\Frank\AppData\Local\Temp\VMBuilds\Teensy Flash Demo V1\teensy35\Release\pch\Arduino.h.gch
Program size: 47,584 bytes (used 9% of a 524,288 byte maximum) (0.86 secs)
Minimum Memory Usage: 5140 bytes (2% of a 262136 byte maximum)
 
C:\Program Files (x86)\Arduino\java\bin>ECHO Sat 09/25/2021 12:08:14.89 Postbuild Hook 1 
Sat 09/25/2021 12:08:14.89 Postbuild Hook 1
C:\Program Files (x86)\Arduino\java\bin>C:\Users\Frank\Temp\TeensyFlash\TeensyFlash.exe "C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1\" 
Hello World!
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1"
C:\Program Files (x86)\Arduino\java\bin>ECHO C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1\ 
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1\
C:\Program Files (x86)\Arduino\java\bin>ECHO C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1 
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1
C:\Program Files (x86)\Arduino\java\bin>ECHO 11 
11

TIA,

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #5 - Sep 25th, 2021 at 6:16pm
Print Post  
Tim,

I know this isn't really a Visual Micro problem, but I'm hoping you have run into this same problem and know the 'trick' to getting command line string arguments parsed properly into the args[] parameter in a C# Main() function.   

I'm calling a C# console app with a post-build command containing multiple string arguments, each of which may or may not contain spaces.  In the console app, I report the number of arguments (i.e. args.Length) and then write out each argument to the console.  I'm having a real problem getting the right number number of arguments when the {ProjectDir} and/or {sketch_path} values expand to a string with spaces.

Here's my command line in board.txt:

recipe.hooks.postbuild.2.pattern=cmd.exe /c "C:\Users\Frank\Documents\Visual Studio 2019\Projects\TeensyFlash\bin\Release\netcoreapp3.1\TeensyFlash.exe" "{sketch_path}" "{ProjectDir}" {serial.port.num}

and here's the printout from the console app:

C:\Program Files (x86)\Arduino\java\bin>ECHO Sat 09/25/2021 14:07:20.20 Postbuild Hook 1 
Sat 09/25/2021 14:07:20.20 Postbuild Hook 1
C:\Program Files (x86)\Arduino\java\bin>"C:\Users\Frank\Documents\Visual Studio 2019\Projects\TeensyFlash\bin\Release\netcoreapp3.1\TeensyFlash.exe" "C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1" "C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1\" 6 
Teensy Flash Console
Number of arguments in args = 2
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1" 6

and here's my console app:

using System;

namespace TeensyFlash
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Teensy Flash Console");
            Console.WriteLine("Number of arguments in args = {0}\n", args.Length);
            foreach (string str in args)
            {
                Console.WriteLine("{0}\n", str);
            }
        }
    }
}

TIA,

Frank


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


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino project compile doesn't run post-build command?
Reply #6 - Sep 25th, 2021 at 10:35pm
Print Post  
try running the exe via cmd with /c switch

Code (C++)
Select All
cmd.exe /c executable.exe arguments 

  
Back to top
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #7 - Sep 25th, 2021 at 11:47pm
Print Post  
Tim,

Oops!  Sorry - I was running it with the '/c', but decided to try it without and forgot to put it back before copy/pasting it.  It didn't work at all w/o the '/c', but still has the improper parsing problem with '/c' in the command

What does '/c' do, by the way?

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #8 - Sep 26th, 2021 at 12:18am
Print Post  
Tim,

Playing around some more, I actually found a method that [almost] works Wink

recipe.hooks.postbuild.2.pattern=cmd.exe /c "C:\Users\Frank\Documents\Visual Studio 2019\Projects\TeensyFlash\bin\Release\netcoreapp3.1\TeensyFlash.exe" "{sketch_path}" "\"{ProjectDir}"" {serial.port.num}

produces

 
C:\Program Files (x86)\Arduino\java\bin>ECHO Sat 09/25/2021 20:14:24.26 Postbuild Hook 1 
Sat 09/25/2021 20:14:24.26 Postbuild Hook 1
C:\Program Files (x86)\Arduino\java\bin>"C:\Users\Frank\Documents\Visual Studio 2019\Projects\TeensyFlash\bin\Release\netcoreapp3.1\TeensyFlash.exe" "C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1" "\"C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1\"" 6 
Teensy Flash Console
Number of arguments in args = 3
C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1
"C:\Users\Frank\Documents\Arduino\Teensy Flash Demo V1"
6

So I get the correct number of arguments (3) and the correct string layout.  The only thing that mystifies me is that I have to deal with the double quotes around the 2nd argument - no idea why only the second argument requires the additional treatment.

I think I'm close enough though, so no need to bother you; I don't really need two arguments that are both paths with spaces - I can get what I need from just {ProjectDir}, as it is essentially identical to {sketch_path}

Frank


The
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 245
Joined: Oct 19th, 2011
Re: Arduino project compile doesn't run post-build command?
Reply #9 - Sep 26th, 2021 at 10:30pm
Print Post  
Tim,

I was playing around some more with a slightly different Arduino program, but calling the same C# executable as before, using the same PostBuild string as shown:

Code (C++)
Select All
recipe.hooks.postbuild.2.pattern=cmd.exe /c "C:\Users\Frank\Documents\Visual Studio 2019\Projects\TeensyFlash\bin\Debug\netcoreapp3.1\TeensyFlash.exe" "\"{vm.runtime.build.final_output_path}"" {serial.port.num} 



However, this time my C# executable threw an exception, and when I looked into it - I found that the '{serial.port.num}' build properties parameter had not been expanded, and moreover, that parameter did not exist in the list of available parameters when I enabled 'show build properties'.  Here are all the serial port related parameters I could find for this program:

Code (C++)
Select All
serial.port.file=usb:10000/0/0/2/4/9
serial.port=usb:10000/0/0/2/4/9
serial.port.port=usb:10000/0/0/2/4/9
serial.port.label=COM11 (Teensy 3.5) Serial
serial.port.protocol=Teensy
extra.time.local=1632679733
extra.time.utc=1632694133
extra.time.dst=-14400
extra.time.zone=14400
serial.serial.port.port=usb:10000/0/0/2/4/9
serial.serial.port.label=COM11 (Teensy 3.5) Serial
serial.serial.port.protocol=Teensy
 



Am I missing something here?  Do some build properties appear and disappear?  If so, is it Debug/Release dependent or something else?

TIA,

Frank


  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint