Go Down

Topic: Execute .bat file when verify button is pressed in arduino IDE (Read 3238 times) previous topic - next topic

dsbros

Hello Everyone,

I am newbie to arudino programming and currently using arduino 1.8.1.
I want to run a .bat file stored in particular location when arduino verify button is pressed, the .bat file will perform certain task on my PC.
Is it possible to edit source code of arduino IDE such that after verify button is pressed and hex file is generated, the .bat file execute at the end of compilation.

Thanks

pert

[quote author=dsbros link=msg=3727590 date=1526015656
Is it possible to edit source code of arduino IDE such that after verify button is pressed and hex file is generated, the .bat file execute at the end of compilation.
[/quote]
Yes. Here are the build instructions for the Arduino IDE source code:
https://github.com/arduino/Arduino/wiki/Building-Arduino

It might actually make more sense to do the modification on the arduino-builder tool the Arduino IDE uses to run the verify process (the IDE code is intended to be only for the GUI):
https://github.com/arduino/arduino-builder

But that's all a bit of a hack. The Arduino IDE actually provides a way to do what you want to do without modifying the source code and building executables. I will proceed to explain:

The first thing you need to understand is that each Tools > Board selection has a hardware package that contains, among other things, compilation and upload recipes the Arduino IDE uses to determine exactly which actions should be taken during verify or upload. This system of hardware packages is what allows 3rd parties to easily add support for other hardware without needing to supply a customized IDE.

This technique involves adding an extra recipe to the hardware package, thus you would need to do so for every hardware package of a board you want the modification to apply to. It may be that you are only using one hardware package. Many Arduino users only use the Arduino AVR Boards of the Uno, Nano, Leonardo, Mega boards.

The easiest way to find the active hardware package location is as follows:
  • Select a board from the hardware package from the Tools > Board menu
  • File > Examples > SPI > BarometricPressureSensor
  • Sketch > Show Sketch Folder
  • Move up folder levels until you reach the one that contains platform.txt


platform.txt contains the compilation recipes but Arduino has provided a method by which you can add additional compilation recipes without messing around in platform.txt by instead defining them in a file you create named platform.local.txt in the same folder. This makes it easier to apply your modification to multiple packages or when you update to a new package (or IDE in the case of Arduino AVR Boards) version.

A number of hook recipes may be defined. These hooks are run at various points through the verification process:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#pre-and-post-build-hooks-since-ide-165

Robin2

Another approach to this may be to use the Arduino IDE to compile and upload from the command line. The program that generates the call to the IDE could also call the batch file.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

dsbros

Hello Pert,

Thank you for quick reply.
I check platform.txt files , it mentions the following thing:

Code: [Select]

#
# OpenOCD sketch upload
#

tools.openocd.path={runtime.tools.openocd-0.10.0-dev.nrf5.path}
tools.openocd.cmd=bin/openocd
tools.openocd.cmd.windows=bin/openocd.exe

tools.openocd.upload.params.verbose=-d2
tools.openocd.upload.params.quiet=-d0
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -f interface/{upload.interface}.cfg -c "{upload.setup_command}" -f target/{upload.target}.cfg -c "program {{{build.path}/{build.project_name}.hex}} verify reset; shutdown;"

tools.openocd.program.params.verbose=-d2
tools.openocd.program.params.quiet=-d0
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -f interface/{program.interface}.cfg -c "{program.setup_command}" -f target/{upload.target}.cfg -c "program {{{build.path}/{build.project_name}.hex}} verify reset; shutdown;"

tools.openocd.erase.params.verbose=-d3
tools.openocd.erase.params.quiet=-d0
tools.openocd.erase.pattern=

tools.openocd.bootloader.params.verbose=-d2
tools.openocd.bootloader.params.quiet=-d0
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -f interface/{program.interface}.cfg -c "{program.setup_command}" -f target/{upload.target}.cfg -c "init; halt; nrf51 mass_erase; program {{{runtime.platform.path}/cores/nRF5/SDK/components/softdevice/{softdevice}/hex/{softdevice}_{upload.target}_{softdeviceversion}_softdevice.hex}} verify reset; shutdown;"


This talks about upload, so I have to mention .bat file execute command in this code location, correct?
I checked the link which you provided, it mentions about recipes, however I didn't find any command for executing .bat file.

Usually to run a batch file, we move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "abc.bat", we can type "abc" to execute the batch file.
However, in this case how to mention the command?
Is there recipe. format for .bat file? I am newbie to this programming so its slightly difficult to understand  :'(


pert

This talks about upload, so I have to mention .bat file execute command in this code location, correct?
It all depends on what you're trying to accomplish. The upload recipes will only run when you click the Upload button. If you want your .bat file to be run when you click the Verify/Compile button then you would not want to add it to the upload recipe. Keep in mind that the Arduino IDE does the Verify process every time before uploading so if you add a custom recipe to the Verify process it will be run whether you do Verify or Upload.

it mentions about recipes, however I didn't find any command for executing .bat file.
You can run any executable. Whether that's an .exe or a .bat makes absolutely no difference.

Usually to run a batch file, we move to the directory containing the file and type the name of the batch file.
Or you can specify the path to the .bat file and run it from the current directory.

However, in this case how to mention the command?
I could keep trying to explain this in generalities but at this point it looks like that will be very time consuming. How about you provide complete details of what you're trying to accomplish?

I am newbie to this programming so its slightly difficult to understand
This isn't really a project for a newbie. This is something even most advanced Arduino users don't do. That doesn't mean you won't be able to accomplish it but you definitely can't expect this to be easy like the standard things a beginner would be expected to do.

dsbros

Thank you for your reply.

I could keep trying to explain this in generalities but at this point it looks like that will be very time consuming. How about you provide complete details of what you're trying to accomplish?
Here are the details of what I am trying to achieve:
I am programming nrf51822 module (datasheet) following this repo:https://github.com/sandeepmistry/arduino-BLEPeripheral

I am able to compile the program succesfully without any problem.
For uploading I am not able to do directly from arduino IDE. So I am using command line tools
suggested by nordic to upload the program. I have created a batch file that picks up hex file and does uploading job automatically.

However, everytime I compile program I have to separately run the batch file (by double clicking on file).
So I was wondering if arduino IDE can be modified little bit such that when I compile the program at the end of successful compilation, it runs the batch file to upload the program.
Hope this explanation helps

Robin2

However, everytime I compile program I have to separately run the batch file (by double clicking on file).
So I was wondering if arduino IDE can be modified little bit such that when I compile the program at the end of successful compilation, it runs the batch file to upload the program.
Hope this explanation helps

That would be easy to do using the Arduino IDE from the command line to compile the program and then using your BAT file to upload it.

I use this Python program to compile and upload my Arduino programs (because I don't use the IDE to edit my code) and the Python program could be amended to do what you want without too much effort.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

dsbros

Hello Robin,

Thanks for reply :)

That would be easy to do using the Arduino IDE from the command line to compile the program and then using your BAT file to upload it.
Let me know if my understanding is correct.
I can add these commands inside my batch file at the initial part, which will verify the program and then the later in the same batch file there will be command for uploading (commands specific to module). So in single batch file click, I can verify and upload the program, correct?

P.S: I am using J-link to upload program to nrf51822 module.

Robin2

I can add these commands inside my batch file at the initial part, which will verify the program and then the later in the same batch file there will be command for uploading (commands specific to module). So in single batch file click, I can verify and upload the program, correct?
I think that should work. You could try compiling and uploading the simple BLINK file to an Uno.

I am not sufficiently familiar with script files on Linux (similar to .bat files) so I use Python - but I guess you are competent using .bat files.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up