HOWTO: Macros in Minicom

Minicom is an old-school serial terminal emulator, and is indispensable for developing serial projects with Linux. It turns out that most of the things I need to do involve repeating a few commands over and over, and it would be nice to be able to automate this so one button could send off a whole string of commands. On closer inspection, I found that there is a macro handler built into Minicom for just this purpose. Here are my notes on how to use it:


1. From a minicom window, type ctrl+a, then o to bring up the configuration menu (note: you can press z instead of o to see a list of the available options).

2. Use the arrow keys to select ‘screen and keyboard’.

??????[configuration]???????
? Filenames and paths      ?
? File transfer protocols  ?
? Serial port setup        ?
? Modem and dialing        ?
? Screen and keyboard      ?
? Save setup as skye       ?
? Save setup as..          ?
? Exit                     ?
????????????????????????????

3. Type m to get to the Edit Macros window

??????????????????[Screen and keyboard]??????????????????
?                                                       ?
? A - Command key is         : ^A                       ?
? B - Backspace key sends    : BS                       ?
? C - Status line is         : enabled                  ?
? D - Alarm sound            : Yes                      ?
? E - Foreground Color (menu): WHITE                    ?
? F - Background Color (menu): BLACK                    ?
? G - Foreground Color (term): WHITE                    ?
? H - Background Color (term): BLACK                    ?
? I - Foreground Color (stat): WHITE                    ?
? J - Background Color (stat): BLACK                    ?
? K - History Buffer Size    : 5000                     ?
? L - Macros file            : .macros                  ?
? M - Edit Macros                                       ?
? N - Macros enabled         : Yes                      ?
? O - Character conversion   :                          ?
?                                                       ?
?  Change which setting?  (Esc to exit)                 ?
?????????????????????????????????????????????????????????

4. Type 1-9 or a to edit a macro. On my system, F1 gets eaten by the window manager, so I started assigning macros from 2 on. Press enter when you are done writing the line. A tricky thing to do here is use a bunch of ^~ (1-second delay) strings in a row to pause between actions. I did find that for some things that required typing something, hitting enter, then typing again (such as entering a username/password), it helped to put a 1 second delay after the ^M- dont ask me why.

????????????????????????????[F1 to F10 Macros]?????????????????????????????
?                                                                         ?
? 1 :                                                                     ?
? 2 : /some/where/myprog -fancyoptions                                    ?
? 3 : myloginname^M^~mypassword                                           ?
? 4 :                                                                     ?
? 5 :                                                                     ?
? 6 :                                                                     ?
? 7 :                                                                     ?
? 8 :                                                                     ?
? 9 :                                                                     ?
? A :                                                                     ?
?                                                                         ?
? Change which setting?  (Esc to exit)                                    ?
?                                                                         ?
?  (LEGEND: ^M = C-M, ^L = C-L, ^G = C-G, ^R = C-R, ^~ = pause 1 second,  ?
?   \u = username, \p = password, \\ = \)                                 ?
???????????????????????????????????????????????????????????????????????????

note: these are the special characters:

^ + M = CONTROL-M (\n)   "enter key"
^ + L = CONTROL-L (\f)
^ + G = CONTROL-G (\b aka bell)
^ + R = CONTROL-R (\r)
^ + ~ = 1 second sleep() call (useful in login sequences)
^ + ^ = ^

5. When you are done defining macros, press enter twice to return to the configuration menu. You can press escape to exit from here, or if you want to save your macros, select ‘Save setup as..’ to create your own configuration. Your macros should show up as a .macros file in your home directory.

6. You can then use the function keys to automatically insert the text from the macro into the session. This works great for anything that you have to type repeatedly when debugging a serial device.

This entry was posted in tech. Bookmark the permalink.

3 Responses to HOWTO: Macros in Minicom

  1. thanks for the summary says:

    nuff said

  2. Javier says:

    Cool site. Great complement to the rather brief minicom world.

  3. Javier says:

    Cool site. Great complement to the rather brief minicom world. Wait..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>