# machin0r/cimsii-midas_ink_control architecture

> Architecture diagram of the GitHub repository machin0r/cimsii-midas_ink_control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/machin0r/cimsii-midas_ink_control
- Repository: https://github.com/machin0r/cimsii-midas_ink_control

## Overview

##### Main Components
- User Application: At the top level, applications that import and use this library.
- Midas Object (Core API): This is the heart of the library (provided in midas_comms.py) which handles overall control and information.
- Serial Connection Module: The internal mechanism (via the “create_serial_connection” function) that establishes and maintains communication over an RS422 serial link. This module uses the pySerial dependency.
- Specialized Sub-Components (Sub-classes): The README documents that the Midas object has several sub-classes for different functions:
- Midas.Status() for alarms and status bits.
- Midas.Pressures() for infeed and meniscus parameters.
- Midas.Temperatures() for heater parameters.
- Midas.Pumps() for recirculation and meniscus pumps.
- Midas.Purge() for purge pressures and control.
- External Hardware (Ink System): Representing the actual Megnajet/Xaar CIMS II/HV/Midas ink system that communicates via RS422 signals.

##### Out Relationships and Interactions
- The User Application calls functions of the Midas object.
- Upon initialization and configuration, the Midas object calls create_serial_connection to instantiate an RS422-based connection (represented by an internal “Midas_Serial” object).
- After establishing the connection, various specialized sub-components (Status, Pressures, Temperatures, etc.) use this open channel to send and receive control commands.
- Data flow is bidirectional: commands (such as enable bits settings) travel from the user/application through the Midas object to the external hardware, and status/feedback is received back.

##### Important Architectural Patterns/Design Principles
- Modular Design: The entire system is broken into a main controller (Midas) and several auxiliary components (for status, pump control, etc.), each responsible for a particular aspect of the ink system’s operations.
- Abstraction over Hardware Communication: The implementation hides the complexities of RS422 serial communications behind a simple Python API.
- Encapsulation: The handling of the serial connection and the different control parameters are encapsulated within specific classes and methods, exposing a neat interface to client code.

##### Relevant Technologies
- Python as the programming language.
- pySerial library is used for handling RS422 communications.
- RS422 as the communication protocol used to talk to the ink system hardware.

- The layered abstraction from high-level API to low-level hardware communication.
- The precise roles of each sub-module within the Midas library.
- The specific technological stack (Python, pySerial, RS422) being used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    UA("User Application"):::external

    %% Midas API Controller with sub-components
    subgraph "Midas API Controller"
        MID("Midas API"):::api
        STATUS("Midas.Status"):::subcomponent
        PRESS("Midas.Pressures"):::subcomponent
        TEMP("Midas.Temperatures"):::subcomponent
        PUMPS("Midas.Pumps"):::subcomponent
        PURGE("Midas.Purge"):::subcomponent
    end

    %% Serial communication and Hardware
    SERIAL("Midas_Serial (RS422 Communication)"):::serial
    INK("CIMS II/Midas Ink System"):::hardware

    %% Connections
    UA -->|"calls_API"| MID
    MID -->|"initiate_comm"| SERIAL
    SERIAL -->|"send_recv"| INK
    
    %% Sub-components interactions with Serial Connection
    STATUS ---|"uses"| SERIAL
    PRESS ---|"uses"| SERIAL
    TEMP ---|"uses"| SERIAL
    PUMPS ---|"uses"| SERIAL
    PURGE ---|"uses"| SERIAL

    %% Click Events
    click MID "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click SERIAL "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click STATUS "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click PRESS "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click TEMP "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click PUMPS "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"
    click PURGE "https://github.com/machin0r/cimsii-midas_ink_control/blob/main/midas_comms.py"

    %% Styles
    classDef external fill:#C2F0C2,stroke:#333,stroke-width:2px;
    classDef api fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef subcomponent fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef serial fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef hardware fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
