Tag Archives: python

3M Microtouch touchscreen emulator in Python

A colleague asked about virtualising a touch screen DOS application, designed for use with a microtouch touch screen interfacing over RS232. The familiar story of the monitor / old PC hardware dying and replacing it seemed a shorter term solution to a problem that could be solved with virtualisation or emulation. Note: This software no longer has any external hardware connected.

The proposal:

  1. Virtualise or emulate the application within the windows environment.
  2. Link the application to a serial port on the host system (virtual or real)
  3. Write a touch screen emulator to simulate presses using mouse clicks within the application window.

VirtualBox and VMWare Workstation are two virtualisation solutions that support mapping host serial ports to virtual ports. After attempting to use both of these, the timing critical nature of this specific DOS application upon startup didn’t like [my suspected]  lag of the virtualised ports. Running it again in DOSBox, a x86 emulator, resolved this issue. Virtual Serial Port Emulator is a tool to create virtual ports that can act as a connector between programs. This maps the serial streams from the touchscreen emulator to the serial port DOSBox is looking for in this case (how-to configure DOSBox serial ports).


Finally, the touch screen emulation is written in Python as a quick and simple way to test it out. PyHook is used to capture mouse clicks and mouse position, while PySerial is used for all serial communication. This program  will firstly respond to a handful of serial commands that are required upon loading the system in DOSBox. Once in, it will ask you to calibrate the emulated touch screen by clicking the top left and bottom right of the application window. It will only action on clicks in the specified window, in this case, DOSBox. Each click within this area will be mapped across the standard 10 bit vertical and horizontal touch screen space and sent to the serial port specified.

Please note that this has been tailored to the application that I’m running – but can be easily tweaked / amended as necessary using the microtouch reference guide. The shell output:


The DOS application running  – with some numbers entered through the emulator using a mouse.


Scraping data from the BBC with Python

There is an annoying tendency of the BBC News site to have numerous ancient stories in their ‘Popular’ sidebar. It was a good excuse to try out Python and collect a bit more information on when this occurs.

This Python script follows the following process:

  • Visit the BBC News homepage and scrape the ‘Most Popular’ sidebar.
  • Visit the URL of each story.
  • Collect the published date (from the meta data and front end)
  • Calculate the difference between present date / time and the published date.
  • Store the data as a CSV file.
  • Repeat the whole process every n minutes or seconds.

Beautiful Soup makes relatively light work of parsing what we want, along with PrettyTable, CSV, Regular Expressions and Requests.

Running this in IDLE shell looks like this:

and some of the ‘old’ results collected over a 3 hour period can be seen in this spreadsheet . Out of 46 news stories listed under popular stories during this period, 21 were over 67 days old!