The design and features of the Python programming language make it useful for solving many problems, including those encountered in the day-to-day work of an Research and Development (R&D) department. Troubleshooting integrated systems in particular is one common application where Python really shines. To understand why, let’s first review the features of the Python programming language which enable very rapid writing and testing of code:
-Python is an interpreted, not a compiled language. This extra layer of abstraction provided by the Python interpreter frees developers from becoming sidetracked with low-level memory management details specific to both the operating system and CPU architecture. Developers instead can focus on the bigger picture, such as the logic of their algorithm.
-The interactive Python interpreter (Python prompt) enables rapid writing and testing of classes (software objects which either store data or something with it) because of its instant feedback. This is ideal for prototyping functions.
-The extensive standard library already includes classes for many common tasks. This makes easy tasks easy and hard tasks manageable.
-The large number of third-party modules makes harder problems much easier to solve with concise and straightforward code, without re-inventing the wheel.
This rapid development advantage lends itself to writing special-purpose (especially single-use) programs, for situations where the general steps of the program are clear, but they just need to be converted into computer instructions. In hardware Engineering, these single-use or “throwaway” programs are often needed because unexpected problems frequently occur in complex integrated systems which also require quick resolution, especially when that unexpected problem is discovered an ocean away by a paying customer.
The category “complex integrated systems” includes much more than large-scale machinery. Many hardware products (from office printers to automobile engine control systems) have many layers: electronic components and chips, firmware, communication (e.g. cabling or wireless links) and then finally the user-visible GUI application. This last layer of the system can be written in different languages, by different people (such as in-house coders or a loose band open-source developers). This often makes it difficult to isolate which layer of this integrated stack is the root cause of an error.
Suppose there is a longer than expected latency (i.e. delay between sending a command and receiving the result) between a digital printer and the PC it’s attached to. Is the firmware on the main circuit board not responding fast enough to the computer’s commands? Perhaps the slowdown is somewhere in the software stack on the PC? Python naturally lends itself to quickly writing and modifying programs which are able to bypass the higher levels of a software stack and communicate with the hardware directly. This is very valuable when you need to either exonerate either the software or the hardware. If the hardware replies as fast as your test program can query it, it’s the software engineer’s problem and not the hardware engineer’s. This “bypassing” capability can rescue a deadline when your lead software engineer is gone for the day and you need an answer TONIGHT because that customer an ocean away was considering buying a second unit, but is now having second thoughts.
For many troubleshooting scenarios such as the one above, the fact that Python is an interpreted language doesn’t matter, even though interpreted languages in general execute slower than compiled languages. This is especially true if the Python code is running on a recent PC and is communicating to a microcontroller or microprocessor-based devices over a protocol such as serial over Bluetooth, serial over USB, RS-485 or RS-232 (using the very useful third-party PySerial module). This can be a quite common occurrence because these types of data pipes are often used for firmware debugging interfaces or as the main communication interface for older devices. RS-485, for example is still used extensively for industrial equipment.
In almost all cases, the baud rate of the serial interface, not the Python interpreter’s bytecode translation and execution speed, will be the limiting factor. This is also often true for devices which communicate over a network.
Like a digital multimeter, Python is easy to pick up and start using. Like an oscilloscope with many modes and knobs, Python programs can be versatile and adaptable diagnostic tools. This is the power of Python in the Engineering department.
Copyright © Python People