Files
qitech-control/docs/io.md
T
2025-04-11 17:05:57 +02:00

7.4 KiB

IO Types

The IO abstraction types create a device-agnostic interface between the machine logic and the devices. With this possibility, different functionalities can be virtually routed to different devices if they match the IO type.

A hypothetical functionality "XY" needs three digital outputs. On a logical level, it's not important which devices these are; they just have to be digital output devices. The digital output devices can still have different electrical characteristics which might be important for the application but are not relevant for the machine logic, like direct drive or relay.

A functionality can be virtually wired to any device that matches the IO type. Either to one EL2004 which has 4 digital outputs or to two EL2002 which have 2 digital outputs each. Also, different functionalities can be wired to the same device without interacting with each other.

Functionalities of different machines should not be wired to the same devices because of possibly conflicting configuration and machine identification issues (which devices belong to what machine).

Implemented IO types

  • Digital Output (DO)
  • Digital Input (DI)
  • Analog Input (AI)
  • Analog Output (AO)
  • Temperature Input (TI)
  • Pulse Train Output (PTO)

Usage

Implementing for a device

Since each device has one or multiple ports, it needs to define an enum representing each port/pin.

#[derive(Debug, Clone)]
pub enum EL2002Port {
    DO1, // Digital Output 1
    DO2, // Digital Output 2
}

Then the device must implement the respective device trait like DigitalOutputDevice.

The digital_output_write is used to set the desired level of the output of a given port.

The digital_output_state is used to read the current state of the output of a given port.

impl DigitalOutputDevice<EL2002Port> for EL2002 {
    fn digital_output_write(&mut self, port: EL2002Port, value: DigitalOutputOutput) {
        match port {
            EL2002Port::DO1 => self.rxpdo.channel1.as_mut().unwr