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.
[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:
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):
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:
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
dsbros:
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.
dsbros:
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.
dsbros:
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.
dsbros:
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?
dsbros:
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.
pert:
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 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
dsbros:
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.
Robin2:
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.
dsbros:
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.