Interface group assignment

The group assignment consists of comparing different tools to develop interfaces that communicate with my board (MidTiny), in this case the tools that I will use are Python Tkinter, Processing and C#, all the interfaces perform the same function which is to turn on and off an LED on the board, also all the interfaces communicate with the board by means of serial communication.

Comparing the applications based on the number of lines of code does not seem to me a very fair measure so I will use as a parameter of comparison the disk space used by each one.

The Python Tkinter program is the following:

/*
* super_button.py
* The following program shows a basic interface consisting of a button 
* that sends the "H" character via serial communication to the defined port.
* 
* Author: Harley Lara
* Create: 25 May 2021
* License: (CC BY-SA 4.0) Attribution-ShareAlike 4.0 International
* 
* This work may be reproduced, modified, distributed,
* performed, and displayed for any purpose, but must
* acknowledge this project. Copyright is retained and
* must be preserved. The work is provided as is; no
* warranty is provided, and users accept all liability.
* 
*/

import tkinter as tk
import serial

class App(tk.Frame):

      led_status = False

      def __init__(self, master=None, title="App Title", geometry="300x300"):
         super().__init__(master)
         self.master.title(title)
         self.master.geometry(geometry)
         self.pack()

         # Serial Connection
         self.serialport = serial.Serial(
            'COM15', baudrate=9600, timeout=.1)  # open serial port
         print(self.serialport.name)

         # Create GUI components
         self._createWidgets()

      def _createWidgets(self):
         self.tkButton1 = tk.Button(
            self,
            text="Turn ON",
            height=50,
            width=50,
            bg='white',
            command=self._sendData)
         self.tkButton1.pack()

         self.tkLabel = tk.Label(self)
         self.tkLabel["text"] = "This a label"
         self.tkLabel.pack()

      def _sendData(self):
         self.serialport.write("H".encode())
         print("[SEND] 'H'")
         if (self.led_status == False):
            self.tkButton1.configure(bg="green", text="Turn OFF")
            self.led_status = True
         else:
            self.tkButton1.configure(bg="white", text="Turn ON")
            self.led_status = False


def main():
      root = tk.Tk()
      app = App(master=root, title="Super button", geometry="300x300")
      app.mainloop()


if __name__ == "__main__":
      main()                        
                     

Advantages: Tkinter is a module that is installed by default with python and does not need to download any external module.

Disadvantages: PySerial module is not installed by default with python so you need to install it additionally as "pip install pyserial".

The used space of the python file "super_button.py" is 1.98 KB and the size on disk is 4 KB.

The next tool is processing the code is as follows:

/*
* super_button.pde
* The following program shows a basic interface consisting of a window 
* in which pressing any area of it sends the character "H" via serial 
* communication to the defined port.
* 
* Author: Harley Lara
* Create: 25 May 2021
* License: (CC BY-SA 4.0) Attribution-ShareAlike 4.0 International
* 
* This work may be reproduced, modified, distributed,
* performed, and displayed for any purpose, but must
* acknowledge this project. Copyright is retained and
* must be preserved. The work is provided as is; no
* warranty is provided, and users accept all liability.
* 
*/

import processing.serial.*;

Serial serialPort;

boolean led_status = false;

void setup(){
  size(300, 300);
  background(127);
  serialPort = new Serial(this, "COM15", 9600);
}

void draw(){
  if (mousePressed == true) {
    serialPort.write('H');
    println("[SEND] H");
    
    if (led_status == true){
       background(127);
      led_status = false;
    }
    else{
      background(0, 255, 0);
      led_status = true;
    }
  }
  
  delay(100);
}
                     

Advantages: With the default installation processing you have all the necessary tools to realize the interface, it is not necessary to download the serial communication library since it is integrated.

Disadvantages: Creating objects as buttons requires an extra coding effort since it is necessary to constantly capture the position of the mouse pointer and compare it if it is over the object that we consider a button and after that, to know if the mouse pressed event occurs within that area.

The used space of the Processing file "super_button.pde" is 489 bytes and the size on disk is 0 KB.

The last tool to compare is C# using .NET Core, the code is as follows:

/*
* Form1.cs
* The following program shows a basic interface consisting of a button 
* that sends the "H" character via serial communication to the defined port.
* 
* Author: Harley Lara
* Create: 25 May 2021
* License: (CC BY-SA 4.0) Attribution-ShareAlike 4.0 International
* 
* This work may be reproduced, modified, distributed,
* performed, and displayed for any purpose, but must
* acknowledge this project. Copyright is retained and
* must be preserved. The work is provided as is; no
* warranty is provided, and users accept all liability.
* 
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace SuperButton
{
    public partial class Form1 : Form
    {
        static SerialPort _serialPort;
        bool led_status = false;
        public Form1()
        {
            InitializeComponent();
            _serialPort = new SerialPort();
            _serialPort.PortName = "COM15";
            _serialPort.BaudRate = 9600;
            _serialPort.Open();
        }

        private void btnLED_Click(object sender, EventArgs e)
        {
            _serialPort.Write("H");
            if (led_status == true)
            {
                btnLED.BackColor = SystemColors.Control;
                btnLED.Text = "Turn ON";
                led_status = false;
            }
            else
            {
                btnLED.BackColor = Color.Green;
                btnLED.Text = "Turn OFF";
                led_status = true;
            }

        }
    }
}
                     

Advantages: The interface can be created more easily using the basic drag and drop component tools, also the component attributes can be edited in a properties panel, and all this without writing a line of code, although of course it can be done that way.

Disadvantage: It is necessary to install the package for serial communication, by default in .NET Core the dependency "using System.IO.Ports;" is missing, but it can be installed using NuGet packages manager.

The used space of the project (it is not a single file but several files that form the final result) is 1.2 MB and the size on disk is 1.27 MB.