I have a code that reads a letter from serial port and configures pin outputs accordingly. When I upload it to Arduino Nano and use serial monitor - all works. If I manually reset Arduino by pressing a button - it works. If I send letters via batch file - it works.
However, if I reconnect the USB cable Serial Monitor still works, but Batch files just make the board restart.
I want batch files to work regardless of how many times I reconnect USB. Any ideas?
So it is expected that the board will reset when a batch file opens its serial port. As @gilshultz mentioned, it is theoretically possible to avoid this if you can control the technical details of how the port is opened by your batch file. The reset is triggered when the computer asserts the DTR signal. If you can configure the way the port is opened so that the signal is not asserted then opening the port will not reset the board.
Alternatively, you can use the hardware solution of disabling the reset circuit on the board. This can be done by connecting a capacitor with a value somewhere in the ballpark of 10 uF between the reset and ground pins of the Nano. If you do that, you must remember to remove the capacitor when you are uploading new sketches to the board because the board must be reset at the right point during the upload process and the auto-reset circuit normally takes care of that for you.
However, I'm wondering if it is truly necessary to avoid the reset in order to solve your problem since you seem to be indicating that Serial Monitor (which also resets the board when it is first opened) and manually resetting the board does not cause the unspecified problem.
So if you want effective assistance, I think it will be necessary for you to provide us with more information:
Your sketch
Please post your full sketch.
I'll provide instructions you can follow to do that:
Select Tools > Auto Format from the Arduino IDE menus. ⓘ This is done to make the code easier for us to read.
Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
In a forum reply here, click on the post composer field.
Press the Ctrl+V keyboard shortcut.
This will paste the sketch to the post composer.
Move the cursor outside of the code block markup before you add any additional text to your reply.
Repeat the above process if your sketch has multiple tabs.
When your code requires a library that's not pre-installed in "Arduino Cloud Editor", please post a link to where you downloaded that library from.
Click the <CODE/> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.