Projects and Experiments

Overview

This page serves as a list of recent code projects, experiments, and interests using various languages, and technology frameworks including: C++, C#, and most recently Python and Rust.

Examples of recent projects that I will soon share on this site include:

Python Code Examples

I have a long history using C++ and C#, and currently experimenting with Python to use it for projects at work, and for personal interest. Below is a recent list of code examples (that will continue to evolve). Each exercises one or more Python 3 language constructs.

You can download and run the following list of examples by cloning the python3probs repository:
https://github.com/mwcorley79/python3probes.git

Message Passing Layer (MPLv2)

MPLv2 is cross-platform library/framework for developing message passing systems. It wraps full duplex TCP sockets, and supports concurrent clients. MPLv2 is implemented in six python scripts, described below. Note: this MPLv2 is identical to C# (dotnet) MPLv2 version described below (repo is here): dotnet MPLv2 .The interface syntax and semantics of these two projects is virtually identical. Message.py and Message.cs are wire format compatible, and thus can used to acheive C# and Python interop.

  1. TCPConnector.py - messaging connector client

    Create an instance of TCPConnector, connect to server (TCPResponder) to initiate message passing. Run Command: python .\TCPConnector.py

  2. TCPResponder.py - messaging connector server

    Create an instance of TCPResponder, and start tge listener, for incoming (concurrent) client (TCPConnector) requests . Run Command: python .\TCPResponder.py

  3. ClientHandler.py - abstract class for defining custom server processing

    Users must derive new from ClientHander, and implement asbtract methods: Clone, AppProc. The derived ClientHandler class must be registered with TCPResponder, to be used for service client requests.

    • clone - used by TCPResponder to create instance of the derived handler for servicing incoming client requests
    • app_proc - defines the custom (application specific) server processing
  4. pybq.py - a thread-safe queue that blocks the deQue operation, when the Queue is empty.

    This a first version port of Dr. Fawcett's C++ Blocking Queue. to Python. It helps to simplify code necessary to safely share data between threads. Locks and condition variable synchronization primitives are used.

    View pybq.py for additional details, and the terminal command to run the example.

  5. Message.py - a data management class for handling binary and string messages, packaged for TCP (socket) communication

    Message.py is being developed in part, for wire protocol compatibility with the Message class constructs defined and used in C++/Rust comm compare experiment described above. However, Message is a handy general utility for handling binary and string message types interchangeably. Message.py exercise multiple Python language constructs including:

    • struct - packet data, to convert native Python data types to string of bytes for achieving compatibility with external/networked systems written in other languages such as C++ or Rust.
    • properties - (managed) attributes used to manage internal implementation without changing the public API of a class
    • multiple dispatch (decorator) - for function overloading
    • Enum types
    • Class methods versus instance methods

    View Message.py for additional details, and the terminal command to run the example.

  6. EndPoint.py - a simple class to manage IP address and TCP port pairs used by TCPConnector and TCPResponder

Other Python probes

  1. pybqGeneric.py - a thread-safe queue (like pybq.py), but exercises Python Generics

    2nd version port of Dr. Fawcett's C++ Blocking Queue. to Python, and uses Generics. It helps to simplify code necessary to safely share data between threads. Locks and condition variable synchronization primitives are used.

    View pybqGeneric.py for additional details, and the terminal command to run the example.

  2. bq_test_with_message.py - a test script that imports Message.py and pybq.py to test the Message and BlockingQueue together.

    This is a more complex, combined test that uses multiple threads, much like the use in socket communication
    View bq_test_with_message.py for additional details, and the terminal command to run the example.

  3. withProbe1.py - a simple example that tests the Python "with" statement, used for scope-based resource management


    View withProbe1.py for additional details, and the terminal command to run the example.

  4. destructor_probe.py - a simple example that tests Python class destructor method


    View destructor_probe.py for additional details, and the terminal command to run the example.

  5. python_rpi_temperature_iot_device.py - a very simple (first example) of an IoT temperature device prototype, built using the Raspberry Pi.

    This example exercises GPIO (general purpose I/O) access libraries to read (over i2c) telemetry from a BME280 temperature sensor, and the Azure IoT Hub SDK to package and send JSON formatted telemetry to the Azure Cloud (IoT Hub).
    The Pi device (hardware) should resemble the following: https://www.raspberrypi-spy.co.uk/2016/07/using-bme280-i2c-temperature-pressure-sensor-in-python
    View python_rpi_temperature_iot_device.py for additional details.

C# Code Examples

Message Passing Layer (MPLv2)

MPLv2 is cross-platform library/framework for developing message passing systems. It wraps full duplex TCP sockets, and supports concurrent clients. MPL is implemented in six C# packages, described below. Note: this MPLv2 is identical to Python MPLv2 version described above. The interface syntax and semantics of these two projects is virtually identical. Message.py and Message.cs are wire format compatible, and thus can used to acheive C# and Python interop.

You can download and run the C# examples by cloning the repo here

  1. TCPConnector.cs - messaging connector client

    Create an instance of TCPConnector, connect to server (TCPResponder) to initiate message passing. Run Command: dotnet run --project .\TCPConnextor\TCPConnextor.csproj

  2. TCPResponder.cs - messaging connector server

    Create an instance of TCPResponder, and start the listener, for incoming (concurrent) client (TCPConnector) requests. Run Command: dotnet run --project .\TCPResponder\TCPResponder.csproj

  3. ClientHandler.cs - abstract class for defining custom server processing

    Users must derive new from ClientHander, and implement asbtract methods: Clone, AppProc. The derived ClientHandler class must be registered with TCPResponder, to be used for service client requests.

    • Clone - used by TCPResponder to create instance of the derived handler for servicing incoming client requests
    • AppProc - defines the custom (application specific) server processing
  4. BlockingQueue - a thread-safe queue that blocks the deQue operation, when the Queue is empty.

    This is Dr. Fawcett's BlockingQueue. Used it with his permission and taken directly from his website (repo) here: c# BlockingQueue It helps to simplify code necessary to safely share data between threads. Locks and condition variable synchronization primitives are used.

  5. Message.cs - a data management class for handling binary and string messages, packaged for TCP (socket) communication

    Message.py is being developed in part, for wire protocol compatibility with the Message class constructs defined and used in C++/Rust comm compare experiment described above. However, Message is a handy general utility for handling binary and string message types interchangeably.

  6. Utlity.cs - socket send/recv helpers and locking utility classes

Other (C# IoT) Project Code Examples

Prototype of IoT HVAC device, using Raspberry Pi

The objective of this project is to develop, and illustrate a simple design for a working prototype of an (IoT-enabled) Remote Temperature Management device. Temperature and humidity is monitored remotely in the Cloud, will activate a fan or air conditioning unit etc., (and optionally take action using IFTTT) when the temperature and/or humidity exceeds a user specified threshold.

You can download and run the Remote HVAC example on a Raspberry Pi by cloning the repo here