Scientific Computing

Minicom serial comms with file transfer

The Minicom serial communication program allows connecting to devices over the serial port and transferring files using XMODEM, YMODEM, or ZMODEM protocols–PuTTY can’t currently do file transfer over serial links.

Install Minicom like:

  • macOS: brew install minicom lrzsz (lrzsz is for file transfer)
  • Linux: apt install minicom lrzsz (or similar for relevant package manager)
  • Windows: use WSL (Windows Subsystem for Linux)

On macOS in particular for file transfers, first be sure that Minicom can find the sz, rz commands by looking under Esc-O for “File transfer protocols”. It may be necessary to point to lsz and lrz installed by Homebrew.

As noted in the documentation for Minicom, it is possible to save profiles. To just use a device directory, set command line options like:

minicom -D /dev/tty.usbserial-0001 -b 115200

List the USB-serial adapter ports:

  • Linux: ls /dev/ttyUSB*
  • macOS: ls /dev/tty.usbserial*

To send a file from Minicom once the device is ready, press Esc-Z and then S for send, select the appropriate protocol.

Python asyncio.run boilerplate

Concurrency is built into Python via asyncio. AsyncIO generators are implemented with yield much like synchronous generators. async for also simplifies expression of asynchronous for loops.

As in Julia, the expression of asynchronous structures in Python does not implement concurrent execution. Concurrent execution in Python is governed by collections of tasks or futures such as asyncio.gather and initiated by a runner such as asyncio.run.

Debugging asyncio code is facilitated by introspection built into Python.

asyncio.subprocess

AsyncIO subprocess may need specific asyncio loop configuration. The options needed are not the same for every project, depending on the asynchronous functions used.

Example date_coro.py uses AsyncIO subprocess.

asyncio.open_connection

For networking apps asyncio.open_connection allows massive amounts of connection, as shown in findssh.

Import Python user modules in Matlab

Matlab can call user Python modules via the Matlab external language interface. For concurrent Python modules using asyncio, you may need to create a shim function to allow Matlab to call the Python module. Anaconda Python works fine from Matlab.

Configure Matlab for Python: Matlab is designed to work with specific Python versions for each Matlab version. Matlab will not specifically tell you when you’re using an incompatible Python version, but you may get unstable operation or errors. pyenv Python environment manager configures the Python interface.

The Python executable is found from Terminal / Command Prompt:

python -c "import sys; print(sys.executable)"

For Windows, it may be like C:/Miniconda3/python.exe and for macOS / Linux it may be like ~/Miniconda3/python.

This Matlab command is persistent–Matlab remembers this Python choice even after restarting Matlab.

pyenv(Version='C:/Miniconda3/python.exe')

Verify Matlab → Python config by typing pyenv from within Matlab.

Troubleshooting

If a non-supported Python version is used, upon the pyenv() command Matlab may show a warning like:

Warning: Python version 3.xx is not supported. See this topic.

In that case, some Python operations may work, but others may not. An example test that may fail is:

py.tuple([1,1])

PythonError ImportError: PyCapsule_Import could not import module "libmwbuffer"'

Numpy

If only Python standard library modules work, and even commonly used modules like Numpy will not work, errors may occur from Matlab like:

py.numpy.arange(1)
Unable to resolve the name py.numpy.arange

Try diagnosing the issue from Matlab like:

pyenv

help('py.numpy')

Verify the desired Python install is being used, and that there isn’t an error as below. If such an error occurs, check the PATH as seen by Matlab by:

getenv('PATH')

If the Python directories are missing, this may be why user modules are not importable in Python. These paths can be added to Matlab. On Windows, the necessary path is like ~/Miniconda3/Library/bin, the directory with lots of *.{so,dylib,dll} files and the fix is like:

setenv('PATH', fullfile(getenv("USERPROFILE"), "Miniconda3/Library/bin") + pathsep, getenv('PATH'))

The install path on non-Windows OS is like ~/miniconda3/lib.

This command can be issued after a Python command was attempted, it’s not necessary to restart Matlab. Note that this needs to be in PATH, since PYTHONPATH does not help in this case. This change does not persist across Matlab sessions. If it works for you, put it in the ~/Documents/MATLAB/startup.m file to have it reload each time Matlab is started.

This Numpy problem is fixed by the procedure above:

problem in numpy - ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "C:/Miniconda3/python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.4" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load failed: The specified module could not be found.
  • Python module import is implicit in the Matlab → Python module function call. There is no need to import numpy etc. from Matlab
  • Python executable choice persists across Matlab sessions–Matlab “remembers” even after you restart Matlab or reboot the computer.
  • editing imported Python module code requires restarting Matlab to take effect.

WMIC.exe removed from Windows

Starting with Windows 25H2, WMIC.exe (Windows Management Instrumentation Command-line) has been removed from the operating system. Microsoft recommends using PowerShell cmdlets for managing and querying system information instead. There is a migration guide available to help users transition from WMIC to PowerShell cmdlets that invoke WMI.

There are a lot of .bat batch scripts and .ps1 PowerShell scripts that use WMIC.exe, but they can be updated to use PowerShell cmdlets instead.

CMake / Meson force shared library

Build systems like CMake and Meson have specific syntax and variables to manage shared library creation and linking. By default, CMake builds static libraries, but this can be changed by setting the BUILD_SHARED_LIBS variable to ON or by setting the SHARED type option of the add_library() command.

To use C, C++, Fortran, etc. library binaries from Python, shared libraries are required to load the compiled code at runtime in Python. Of course, the Python code must be configured to match the symbols in the shared library.


Meson builds shared libraries by default, but this can be changed by setting the default_library option to static in project() or by the shared_library() function.

Hugo page content variables

Hugo content Markdown files cannot use Hugo variables directly. The way to access variables (including site parameters, data sources, and front matter) from content Markdown files is to use Hugo shortcodes or to use a custom template for those content pages. However, areas inside code fences cannot use shortcodes. What I wanted to do was make examples of code inside code fences used on several pages on my site update with a version number. However, I don’t currently see a feasible way to do this with Hugo that wouldn’t be overly specific to the particular set of examples. It’s OK, I wanted to note this limitation I ran into. An alternative is to use find/replace across files like “sed” or the VSCode GUI.

GNSS-SDR on Windows

To run Linux programs on a Windows computer, normally Windows Subsystem from Linux (built into Windows by Microsoft) is generally the best / most performant way to run most Linux programs, especially programs relevant to data processing and geospace science in general.

The WSL Install Guide notes from Windows Terminal:

wsl --install

That will install Ubuntu. After a few minutes the Ubuntu WSL install will be complete. From Windows terminal type:

wsl

to start Ubuntu.

From there type

sudo apt install gnss-sdr

That installs numerous packages needed to run GNSS-SDR.

Then proceed to the first-run examples.

When building GNSS-SDR and examples, don’t worry about CMake warnings about missing packages, as long as the project builds.

macOS Network Interface priority order

The macOS network interface priority order determines which network interface (like WiFi, Ethernet, etc.) the system uses first when multiple interfaces are available. Set this priority order through the System Preferences or via the command line:

List all network services in priority order:

networksetup -listallnetworkservices

Set the network interface priority order with:

networksetup -ordernetworkservices "Service1" "Service2" ...

Replace "Service1", "Service2", etc., with the actual network service names.


Regarding WiFi SSID priority, macOS automatically scores based on several factors, including the user manually selecting a WiFi network.

8m 40 MHz and 4m 70 MHz ham bands in the USA

Several countries have created an 8 meter ham band near 40 MHz. The USA FCC has a proposed rulemaking RM-11843 to create an 8 meter ham band in the USA. A key conflicting user SNOTEL, which used meteorburst communications to connect very remote sites, has ceased use of the 40 MHz band. As commenters indicate, a rich surplus equipment market exists of military surplus radios and commercial equipment that can be used on the 8 meter ham band. Proposed bandplans allocate FM, CW, and digital modes.


This 8 meter band proposal stands in contrast to the 2014 proposal to make a 4m 70 MHz allocation as exists in numerous other countries around the world. The FCC summarily dismissed the 4m proposal due to incumbent TV channel 4 users. Use this link to query the FCC TV database for channel 4 users. For example, in 2025 there were about 10 full-power DTV licensees (including newly coming on air) across the USA on TV channel 4, an increase from 2014 licensees. Since other countries have allocations close to 70 MHz, the best option for USA ham in the 4m band may be to co-exist in the 72-76 MHz band, perhaps in-between the existing 20 kHz spaced channels. Since typical 4m radios cover 66 MHz - 88 MHz, for international DX, USA hams could receive on 70 MHz and transmit on 72-76 MHz channels. This would be akin to operations for international DX for USA hams in the 60 meter channelized band.