Get_DI_Data

Overview

The Get_DI_Data function block is used to read the status of digital inputs from a Digital Input (DI) module.

💡 DI Channels

Each DI module provides eight input channels.

Module_ID           :=  (USINT)
Ch0                 =>  (BOOL)
Ch1                 =>  (BOOL)
Ch2                 =>  (BOOL)
Ch3                 =>  (BOOL)
Ch4                 =>  (BOOL)
Ch5                 =>  (BOOL)
Ch6                 =>  (BOOL)
Ch7                 =>  (BOOL)
STS_Done            =>  (BOOL)
STS_Failed          =>  (BOOL)
STS_Fault_Code      =>  (USINT)

Interface

Inputs

NameTypeRange / UnitsDescription
Module_IDUSINT1 - 15Unique identifier of the DI module.

Outputs

NameTypeRange / UnitsDescription
Ch0BOOL0 / 1Logical input state for channel 0.
Ch1BOOL0 / 1Logical input state for channel 1.
Ch2BOOL0 / 1Logical input state for channel 2.
Ch3BOOL0 / 1Logical input state for channel 3.
Ch4BOOL0 / 1Logical input state for channel 4.
Ch5BOOL0 / 1Logical input state for channel 5.
Ch6BOOL0 / 1Logical input state for channel 6.
Ch7BOOL0 / 1Logical input state for channel 7.
STS_DoneBOOL0 / 1TRUE when all DI data has been successfully read from the module.
STS_FailedBOOL0 / 1TRUE if the DI data read operation failed.
STS_Fault_CodeUSINT#Diagnostic code indicating the reason for failure.

Fault Codes

CodeMeaningDescription
97Module FaultedThe DI module reported an internal fault.
98Module MismatchThe detected module type does not match the expected DI module.
99Module Not FoundThe specified Module_ID is not part of the current hardware configuration.

Example

(* Define custom data type *)
TYPE 
  DI_8CH : STRUCT
    Ch0 : BOOL;
    Ch1 : BOOL;
    Ch2 : BOOL;
    Ch3 : BOOL;
    Ch4 : BOOL;
    Ch5 : BOOL;
    Ch6 : BOOL;
    Ch7 : BOOL;
  END_STRUCT;
END_TYPE

PROGRAM PROG_Read_DI
  VAR_EXTERNAL
    Module2_DI : DI_8CH;
  END_VAR
  VAR
    DI_Read_Instance : Get_DI_Data;
  END_VAR

  (* Read from Module 2 *)
  DI_Read_Instance(Module_ID := 2);

  (* Map function block outputs to global structure *) 
  Module2_DI.Ch0 := DI_Read_Instance.Ch0;
  Module2_DI.Ch1 := DI_Read_Instance.Ch1;
  Module2_DI.Ch2 := DI_Read_Instance.Ch2;
  Module2_DI.Ch3 := DI_Read_Instance.Ch3;
  Module2_DI.Ch4 := DI_Read_Instance.Ch4;
  Module2_DI.Ch5 := DI_Read_Instance.Ch5;
  Module2_DI.Ch6 := DI_Read_Instance.Ch6;
  Module2_DI.Ch7 := DI_Read_Instance.Ch7;
END_PROGRAM


CONFIGURATION Config0
  RESOURCE PLC ON PLC
    VAR_GLOBAL
      Module2_DI : DI_8CH;
    END_VAR
    TASK Task_50ms(INTERVAL := T#50ms, PRIORITY := 1);
    PROGRAM Read_DI WITH Task_50ms : PROG_Read_DI;
  END_RESOURCE
END_CONFIGURATION