My IDE configuration using Notepad++, ampy and Tera Term

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
pmulvey
Posts: 29
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Wed Oct 16, 2019 10:26 pm

I use Notepad++ for editing, ampy for downloading and Tera Term for serial terminal. In Notepad++ I use NPPExec to execute the following commands:
NPP_SAVE
ampy --port COM4 put $(FULL_CURRENT_PATH)
reset.bat
exit

The file is first saved, then downloaded via COM4. The reset.bat file sends a Ctrl-D to COM4 and resets the esp8266. I set up a shortcut key Alt-Z to trigger the NPPExec script above. So Alt-Z saves, downloads and resets the device. Without the reset in the script you have to go to Tera Term, connect to the port and do a Ctrl-D, a bit of a pain if you don't need the REPL.

Reset.bat contains:
echo off
mode COM4 BAUD=115200 PARITY=n DATA=8 >nul
echo off
echo ** >COM4

To get the actual Ctrl-D character into a text file type the following in DOS:
echo {Do the key combinations CTRL-P followed by CTRL-D} > temp.bat

Edit this file with Notepad++ and you will see in reverse colours DLE EOT which it displays for CTRL-P and CTRL-D these should be pasted into the reset.bat file in place of the two asterisks.
Paul Mulvey

pmulvey
Posts: 29
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Sat Oct 26, 2019 7:58 pm

This works great on my home laptop (Win 8.1) but when I tried it on the students' Win 7 machines it doesn't work. Seems to be something different going on at the DOS level. Anyway I made a grand improvement that does work.

My Project has a workspace folder with a globals folder in this so I have a package arrangement with the __init__.py in the globals folder. So the task is to use a shortcut key to execute a NPPExec script:

Code: Select all

NPP_CONSOLE -

set port = COM4

cd  $(CURRENT_DIRECTORY)
npe_console v+					// Send console to the $(OUTPUTL) variable
cmd /c if exist "boot.py" echo Exists	// Am I in the workspace folder?
npe_console v-

if "$(OUTPUTL)" = "Exists"
   NPP_SAVE					// Save the file
   NPP_CONSOLE +
   ampy --port $(port) put $(FULL_CURRENT_PATH)	// Download to ESP
   NPP_CONSOLE -
   cd  $(CURRENT_DIRECTORY)
   cd..						// The SendCTRLD.py script is up one level from here
   NPP_CONSOLE +
   py SendCTRLD.py $(port)
else
   NPP_SAVE
   NPP_CONSOLE +   
   ampy --port $(port) put $(FULL_CURRENT_PATH) \Globals\$(FILE_NAME)
   NPP_CONSOLE -
   cd  $(CURRENT_DIRECTORY)
   cd..						// The SendCTRLD.py script is up two levels from here
   cd..
   NPP_CONSOLE +   
   py SendCTRLD.py $(port)
   NPP_CONSOLE +   
exit
echo No

This is SendCTRLD.py which sends a CTRL-D to the Board. So one shortcut key saves the file, downloads it and does a soft reset on the ESP8266.

Code: Select all

import serial
import sys

ser = serial.Serial(
    port=sys.argv[1],
    baudrate=115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
)
ser.write(serial.to_bytes([0x04]))
ser.close()
print("Board Reset")
Paul Mulvey

pmulvey
Posts: 29
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Thu Dec 12, 2019 10:45 pm

Ignore my previous posts... this is a work in progress!

When I am using Tera Term to view serial output I had to close the connection before downloading and then open it again because ampy needs the port. In order to improve the automation around programming the device I have added two python programs, DisTeraTerm to close it and ConTeraTerm to reconnect. These essentially find the Tera Term application and send it the appropriate keystrokes. I have just finished it so I'm not 100% sure how bullet proof it is. The updated NPPExec script now looks like this:

Code: Select all

NPP_CONSOLE -
set port = COM4
cd  $(CURRENT_DIRECTORY)
npe_console v+
cmd /c if exist "boot.py" echo Exists
npe_console v-
if "$(OUTPUTL)" = "Exists"
   NPP_SAVE
   cd..
   NPP_CONSOLE +
   py DisTeraTerm.py $(port)
   ampy --port $(port) put $(FULL_CURRENT_PATH)
   NPP_CONSOLE -
   cd  $(CURRENT_DIRECTORY)
   cd..
   NPP_CONSOLE +
   py SendCTRLD.py $(port)
   py ConTeraTerm.py
else
   NPP_SAVE
   cd..
   cd..
   NPP_CONSOLE + 
   py DisTeraTerm.py $(port) 
   ampy --port $(port) put $(FULL_CURRENT_PATH) \Globals\$(FILE_NAME)
   NPP_CONSOLE -
   cd  $(CURRENT_DIRECTORY)
   cd..
   cd..
   NPP_CONSOLE +   
   py SendCTRLD.py $(port)
   py ConTeraTerm.py
   NPP_CONSOLE +   
exit

echo No
This is DisTeraTerm.py:

Code: Select all

import win32api
import win32ui
from time import sleep
import sys
teraterm = sys.argv[1] + " - Tera Term VT"
try:
    PyCWnd1 = win32ui.FindWindow( None, teraterm )
    print ("Stopping " + teraterm)
    PyCWnd1.SetForegroundWindow()
    PyCWnd1.SetFocus()
    win32api.keybd_event(0x12, 0, ) # Alt
    win32api.keybd_event(0x12, 0, 2 ) # Alt release
    win32api.keybd_event(0x46, 0, ) # F
    win32api.keybd_event(0x44, 0, ) # D
except:
    print ("No Tera Term")
and ConTeraTerm.py is:

Code: Select all

import win32api
import win32ui
from time import sleep
import sys
teraterm = "Tera Term - [disconnected] VT"
try:
    PyCWnd1 = win32ui.FindWindow( None, teraterm )
    print ("Starting " + teraterm)
    PyCWnd1.SetForegroundWindow()
    PyCWnd1.SetFocus()
    win32api.keybd_event(0x12, 0, ) # Alt
    win32api.keybd_event(0x12, 0, 2 ) # Alt release
    win32api.keybd_event(0x46, 0, ) # F
    win32api.keybd_event(0x4E, 0, ) # N
    win32api.keybd_event(0x2B, 0, ) # Enter Key
except:
    print ("No Tera Term")

This folder structure is

Code: Select all

ProjectX
     DisTeraTerm.py
     ConTeraTerm.py
     SendCTRLD.py
     workspace
        boot.py
        main.py
        MyProg.py
        Globals
           MyLibrary.py
           LCDLib.py
   
I would welcome feedback on this.
Paul Mulvey

pmulvey
Posts: 29
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Wed Jan 29, 2020 10:19 am

Just discovered, Thonny 3.2.7 does all of the above!
Paul Mulvey

adomanim
Posts: 3
Joined: Wed Dec 25, 2019 5:55 pm

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by adomanim » Tue Feb 04, 2020 4:55 pm

Does anyone use Notepad++ for coding? How can I use its features effectively for C++?





Lucky Patcher Kodi nox

tll
Posts: 5
Joined: Fri Feb 07, 2020 10:16 am

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by tll » Sat Feb 08, 2020 6:54 pm

Paul, great pieces of Python!

I use EditPadPro, and since I started with MC, I defined "tools" on it called "μP Put" and "μP PutAsMain", which appear as icons on the tool bar when a python file is selected. Each tool invocation causes the file to be saved and an specific CMD file to be called. Very similar to what you are doing.

I also have a "μP Run" which upon ampy run completion, returned an open editor file with the run output. It was very handy for syntax debugging. It somehow got broken recently, not sure why, now I do not get the redirected ampy output... I have not had the time to look into it.

This tools had the annoying requirement of having to stop Teraterm. Now I have added your Python pieces, which seem to be working fine. Upon completion of the tool runs, I end up on the Teraterm window, which I am not sure yet, is what I want or not. But in any case a great improvement.

Thanks!

Post Reply