HMIAInOneNetlog, Manages the Netlog HMI

List

Questa pagina fa parte del Manuale Programmazione IEC 61131-3. Vai all indice.

Questo blocco funzione da eseguire in task Back, gestisce il terminale di un dispositivo Netlog. Attivando l’ingresso Enable si attiva l’uscita Enabled e viene gestito il terminale acquisendo i tasti, sul display viene visualizzato il messaggio (32 caratteri) il cui indirizzo è indicato in DData. In DVCmd può essere passata una stringa di definizione del comportamento di ogni digit del display, permettendo di eseguirne il lampeggio alternato con uno space, con il simbolo – o il simbolo +.

Attivando i bits in ingresso è possibile comandare le logiche poste sul terminale, in uscita è ritornato lo stato dei tasti. Questo permette di utilizzarli nel proprio programma come comandi.

Information Circle

Blocco funzione

CODESYS: Non disponibile

LogicLab: eLLabUtyLib

Descrizione

Enable (BOOL) Comando di abilitazione blocco funzione.
SpyOn (BOOL) Se attivo permette di spiare il funzionamento della FB (Vedi articolo).
File (FILEP) Flusso dati stream di gestione HMI definire PCOM0.1.
DVCmd (@STRING) Stringa definizione modo visualizzazione digit sul display.
DData (@STRING) Stringa da visualizzare sul display.
DEStart (BOOL) Comando start inputazione variabile.
DEType (VR_TYPE) Tipo variabile in inputazione (Vedi definizione).
DEPosition (USINT) Posizione sul display di inputazione variabile.
DELength (USINT) Numero di digit variabile in inputazione.
DEValue (PVOID) Indirizzo buffer memorizzazione valore inputato.
Enabled (BOOL) Attivo su abilitazione blocco funzione.
Ready (BOOL) Attivo se il terminale è pronto.
Fault (BOOL) Attivo per un loop su errore esecuzione.
KeyFUN (BOOL) Stato tasto [FUN] del terminale.
KeyENT (BOOL) Stato tasto [ENT] del terminale.
KeyUP (BOOL) Stato tasto [UP] del terminale.
KeyDW (BOOL) Stato tasto [DW] del terminale.
KeyLEFT (BOOL) Stato tasto [LEFT] del terminale.
KeyRIGHT (BOOL) Stato tasto [RIGHT] del terminale.
DEAbort (BOOL) Attivo per un loop su abort sequenza inputazione.
DEEnd (BOOL) Attivo per un loop al termine della sequenza di inputazione, il dato inputato è trasferito nel buffer puntato da DEValue.

Immagine FB HMIAInOneNetlog

Esempi

Come utilizzare gli esempi.

ST_HMIAInOneNetlog: Viene gestita una visualizzazione a menù, alla attivazione viene visualizzato un messaggio di benvenuto e dopo pochi secondi si visualizza il menù. Dal quado di menù premendo il tasto [DW] si passa alla visualizzazione di un messaggio con la data e ora, col tasto [UP] si ritorna al menù.

ST_DataEntryOnNetlog: Struttura a menù come nel precedente esempio ma oltre al quadro Data/Ora vi è un quadro che visualizza due variabili. Agendo sui tasti [UP] e [DW] è possibile scegliere la variabile di cui eseguire l’inputazione del valore (Diventa lampeggiante). Il tasto [FUN] abilita l’inputazione, accettando il valore con [ENT] il valore inputato verrà memorizzato nella relativa variabile.

LogicLab (Ptp114, ST_HMIAInOneNetlog)
PROGRAM ST_HMIAInOneNetlog
VAR
    i : UDINT; (* Auxiliary counter *)
    DData : STRING[ 32 ]; (* Display data *)
    ScreenIDx : USINT; (* Screen index *)
    TimeBf : UDINT; (* Time buffer (mS) *)
    LDTValue : LDATE_AND_TIME; (* Long Date/Time value *)
    Sp : SysSerialPort; (* Serial port management *)
    HMI : HMIAInOneNetlog; (* Netlog terminal *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_HMIAInOneNetlog"
// *****************************************************************************
// An example how to use the Netlog builtin HMI.
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // INITIALIZATION
    // -------------------------------------------------------------------------

    IF (SysFirstLoop) THEN

        // Initialize the pheripheral COM port used to manage the HMI.

        Sp.COM:=ADR('PCOM0.1'); //COM port definition
        Sp.Baudrate:=115200; //Baudrate
        Sp.Parity:='E'; //Parity
        Sp.DataBits:=8; //Data bits
        Sp.StopBits:=1; //Stop bits
        Sp.DTRManagement:=DTR_AUTO_WO_TIMES; //DTR management
        Sp.DTRComplement:=FALSE; //DTR complement
        Sp.EchoFlush:=FALSE; //Received echo flush
        Sp.DTROnTime:=0; //DTR On time delay (mS)
        Sp.DTROffTime:=0; //DTR Off time delay (mS)
        Sp.FlushTm:=0; //Flush time (mS)
        Sp.RxSize:=0; //Rx buffer size
        Sp.TxSize:=0; //Tx buffer size

        // Initialize HMI FB.

        HMI.SpyOn:=TRUE; //Spy On
        HMI.DData:=ADR(DData); //Display data
    END_IF;

    // -------------------------------------------------------------------------
    // NETLOG MANAGEMENT
    // -------------------------------------------------------------------------
    // Here manages the HMI.
    
    Sp(Open:=TRUE); //Serial port management
    HMI.File:=Sp.File; //File pointer
    HMI(Enable:=Sp.Opened); //Netlog terminal

    // Display data and view command are set as default, this is made after FB
    // execution to allow the following program instructions to overwrite them.

    HMI.DData:=ADR(DData); //Display data
    HMI.DVCmd:=ADR('                                '); //Display view command
    IF NOT(HMI.Ready) THEN ScreenIDx:=0; RETURN; END_IF;   

    // -------------------------------------------------------------------------
    // MESSAGE DISPLAY
    // -------------------------------------------------------------------------
    // By using the ScreenIDx variable some messages are displayed.

    CASE (ScreenIDx) OF

        // ---------------------------------------------------------------------
        // SELECTION SCREENS
        // ---------------------------------------------------------------------
        // At system power up a welcome screen is displayed.
        // +----------------+
        // |Hello!          |
        // |I am Netlog     |
        // +----------------+

        0:
        TimeBf:=SysTimeGetMs(); //Time buffer (mS)
        ScreenIDx:=ScreenIDx+1; //Screen index

        // ---------------------------------------------------------------------
        // The welcome message is displayed for a while.

        1:
        HMI.DData:=ADR('Hello!          I am Netlog     '); //Display data
        IF ((SysTimeGetMs()-TimeBf) > TO_UDINT(T#2s)) THEN ScreenIDx:=10; END_IF;

        // ---------------------------------------------------------------------
        // The menu message is displayed, the "keyboard" string is blinking.
        // +----------------+
        // |Use keyboard to |
        // |make your choice|
        // +----------------+

        10:
        HMI.DData:=ADR('Use keyboard to make your choice'); //Display data
        HMI.DVCmd:=ADR('    ********                    '); //Display view command
        IF (HMI.KeyDW) THEN ScreenIDx:=50; END_IF; //Date and time display

        // ---------------------------------------------------------------------
        // DATE/TIME MESSAGE
        // ---------------------------------------------------------------------
        // The date and time is displayed.
        // +----------------+
        // |Date:xx/xx/xxxx |
        // |Time:xx:xx:xx   |
        // +----------------+

        50:
        LDTValue:=TO_LDATE_AND_TIME(SysDateGetNs()); //Long Date/Time value
        i:=DateTimeFormat(LDTValue, ADR('^"Date:"d\/m\/Y "Time:"H\:i\:s   '), ADR(DData), SIZEOF(DData));
        IF (HMI.KeyUP) THEN ScreenIDx:=10; END_IF; //Selection screen
    END_CASE;

// [End of file]
LogicLab (Ptp114, ST_DataEntryOnNetlog)
PROGRAM ST_DataEntryOnNetlog
VAR
    i : UDINT; (* Auxiliary counter *)
    EDVSelect : USINT; (* Data entry variable selection *)
    ScreenIDx : USINT; (* Screen index *)
    RLVar : REAL := 12345.678; (* REAL variable *)
    TimeBf : UDINT; (* Time buffer (mS) *)
    UDVar : UDINT := 12345678; (* UDINT variable *)
    LDTValue : LDATE_AND_TIME; (* Long Date/Time value *)
    DData : STRING[ 32 ]; (* Display data *)
    Sp : SysSerialPort; (* Serial port management *)
    HMI : HMIAInOneNetlog; (* Netlog terminal *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_DataEntryOnNetlog"
// *****************************************************************************
// An example how to use the Netlog HMI with data entry.
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // INITIALIZATION
    // -------------------------------------------------------------------------

    IF (SysFirstLoop) THEN

        // Initialize the pheripheral COM port used to manage the HMI.

        Sp.COM:=ADR('PCOM0.1'); //COM port definition
        Sp.Baudrate:=115200; //Baudrate
        Sp.Parity:='E'; //Parity
        Sp.DataBits:=8; //Data bits
        Sp.StopBits:=1; //Stop bits
        Sp.DTRManagement:=DTR_AUTO_WO_TIMES; //DTR management
        Sp.DTRComplement:=FALSE; //DTR complement
        Sp.EchoFlush:=FALSE; //Received echo flush
        Sp.DTROnTime:=0; //DTR On time delay (mS)
        Sp.DTROffTime:=0; //DTR Off time delay (mS)
        Sp.FlushTm:=0; //Flush time (mS)
        Sp.RxSize:=0; //Rx buffer size
        Sp.TxSize:=0; //Tx buffer size

        // Initialize HMI FB.

        HMI.SpyOn:=TRUE; //Spy On
        HMI.DData:=ADR(DData); //Display data
    END_IF;

    // -------------------------------------------------------------------------
    // NETLOG MANAGEMENT
    // -------------------------------------------------------------------------
    // Here manages the HMI.

    Sp(Open:=TRUE); //Serial port management
    HMI.File:=Sp.File; //File pointer
    HMI(Enable:=Sp.Opened); //Netlog terminal

    // Display data and view command are set as default, this is made after FB
    // execution to allow the following program instructions to overwrite them.

    HMI.DData:=ADR(DData); //Display data
    HMI.DVCmd:=ADR('                                '); //Display view command
    IF NOT(HMI.Ready) THEN ScreenIDx:=0; RETURN; END_IF;   

    // -------------------------------------------------------------------------
    // MESSAGE SELECTION
    // -------------------------------------------------------------------------
    // By using keyboard it's possible to select some mesages.

    IF (HMI.KeyLEFT) THEN ScreenIDx:=10; END_IF; //Date and time display
    IF (HMI.KeyRIGHT) THEN ScreenIDx:=20; END_IF; //Variables display

    // -------------------------------------------------------------------------
    // DATA ENTRY SELECTION TIMEOT
    // -------------------------------------------------------------------------
    // The data entry selection is timeout after a while..

    IF (EDVSelect = 0) THEN TimeBf:=SysTimeGetMs(); END_IF;
    IF ((SysTimeGetMs()-TimeBf) > TO_UDINT(T#5s)) THEN EDVSelect:=0; END_IF;

    // -------------------------------------------------------------------------
    // MESSAGE DISPLAY
    // -------------------------------------------------------------------------
    // By using the ScreenIDx variable some messages are displayed.

    CASE (ScreenIDx) OF

        // ---------------------------------------------------------------------
        // SELECTION SCREENS
        // ---------------------------------------------------------------------
        // The menu message is displayed, the "keyboard" string is blinking.
        // +----------------+
        // |Use keyboard to |
        // |make your choice|
        // +----------------+

        0:
        HMI.DData:=ADR('Use keyboard to make your choice'); //Display data
        HMI.DVCmd:=ADR('    ********                    '); //Display view command

        // ---------------------------------------------------------------------
        // DATE/TIME MESSAGE
        // ---------------------------------------------------------------------
        // The date and time is displayed.
        // +----------------+
        // |Date:xx/xx/xxxx |
        // |Time:xx:xx:xx   |
        // +----------------+

        10:
        LDTValue:=TO_LDATE_AND_TIME(SysDateGetNs()); //Long Date/Time value
        i:=DateTimeFormat(LDTValue, ADR('^"Date:"d\/m\/Y "Time:"H\:i\:s   '), ADR(DData), SIZEOF(DData));

        // ---------------------------------------------------------------------
        // DATA ENTRY MESSAGE
        // ---------------------------------------------------------------------
        // Two variables are displayed.
        // +----------------+
        // |UDINT:xxxxxxxx  |
        // |REAL:xxxxxxxxx  |
        // +----------------+

        20:
        i:=SysVsnprintf(ADR(DData), SIZEOF(DData), ADR('UDINT:%08d  '), UDINT_TYPE, ADR(UDVar));
        i:=SysCVsnprintf(ADR(DData), SIZEOF(DData), ADR('REAL:%05.3f  '), REAL_TYPE, ADR(RLVar));

        // [UP] and [DW] allow to select the variable to be edited.

        IF (HMI.KeyUP) THEN EDVSelect:=1; END_IF;
        IF (HMI.KeyDW) THEN EDVSelect:=2; END_IF;

        // Blink the selected variable.

        CASE (EDVSelect) OF

            // -----------------------------------------------------------------
            // Blink UDINT variable value and by pressing [ENT] key edit it.

            1:
            HMI.DVCmd:=ADR('      ********                  '); //Display view command
            IF NOT(HMI.KeyFUN) THEN RETURN; END_IF;
            HMI.DEPosition:=6; //Data entry position
            HMI.DELength:=8; //Data entry length
            HMI.DEType:=UDINT_TYPE; //Data entry type
            HMI.DEValue:=ADR(UDVar); //Data entry value (Pointer)
            HMI.DEStart:=TRUE; //Data entry start
            ScreenIDx:=ScreenIDx+1; //Screen index

            // -----------------------------------------------------------------
            // Blink REAL variable value and by pressing [ENT] key edit it.

            2: HMI.DVCmd:=ADR('                     *********  '); //Display view command
            IF NOT(HMI.KeyFUN) THEN RETURN; END_IF;
            HMI.DEPosition:=21; //Data entry position
            HMI.DELength:=9; //Data entry length
            HMI.DEType:=REAL_TYPE; //Data entry type
            HMI.DEValue:=ADR(RLVar); //Data entry value (Pointer)
            HMI.DEStart:=TRUE; //Data entry start
            ScreenIDx:=ScreenIDx+1; //Screen index
        END_CASE;

        // ---------------------------------------------------------------------
        // Waits until data entry ends.

        21:
        IF (HMI.DEEnd OR HMI.DEAbort) THEN EDVSelect:=0; ScreenIDx:=ScreenIDx-1; END_IF;
    END_CASE;

// [End of file]
Was this article helpful?