HMIAInOnePicoface, Manages the Picoface 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 Picoface, il terminale può essere connesso al sistema su bus di estensione I2C oppure in seriale sia in configurazione FullDuplexRS232 che in configurazione HalfDuplex RS485. Il parametro CType definisce il tipo di comunicazione utilizzata. Il FB deve essere eseguito in task Back.

Attivando l’ingresso Enable si attiva l’uscita Enabled e viene gestito il terminale acquisendo i tasti e gestendo i LEDs, 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 i LEDs e le uscite logiche poste sul terminale, in uscita è ritornato lo stato dei tasti e degli ingressi logici posti sul terminale. 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).
CType (BOOL) Tipo comunicazione. FALSE: Full duplex (Default), TRUE: Half duplex.
File (FILEP) Flusso dati stream di gestione HMI, per il terminale connesso in I2C definire PCOM15.1.
FLed0~6 (BOOL) Comando LED tasti funzione da [0] a [6].
Backlight (BOOL) Comando accensione backlight display.
Out0~1 (BOOL) Comando uscite logiche del terminale.
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 (UDINT) 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.
FKey0~9 (BOOL) Stato tasti funzione da [0] a [9] del terminale.
KeyFUN (BOOL) Stato tasto [FUN] del terminale.
KeyESC (BOOL) Stato tasto [ESC] del terminale.
KeyENT (BOOL) Stato tasto [ENT] del terminale.
KeyUP (BOOL) Stato tasto [UP] del terminale.
KeyDW (BOOL) Stato tasto [DW] del terminale.
Inp0~1 (BOOL) Stato ingressi digitali 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.
PCode (STRING[10]) Codice terminale Picoface, viene acquisito dal terminale.
SCode (STRING[10]) Versione software terminale Picoface, viene acquisito dal terminale.
OneWireOk (BOOL) Attivo se almeno un dispositivo One-Wire è connesso al connettore del terminale.
OneWireTrig (BOOL) Attivo per un loop di programma, da usare come trigger sull’array OneWireData.
OneWireData (BYTE[16]) Ritorna i dati letti dal dispositivo One Wire connesso al connettore del terminale.

Immagine FB HMIAInOnePicoface
Gestione dispositivi OneWire

Il terminale Picoface può gestire dispositivi 1Wire, al connettore 1-WIRE deve essere connesso un solo dispositivo, per tutti i dispositivi connessi viene ritornato il loro UID. I dati sono ritornati con un array da 16 bytes nel formato indicato:

Formato array 1Wire

Attualmente sono gestiti:

  • DS1990R “Silicon Serial Number” per il quale viene tornato il solo UID. Per acquisire l’UID aggiungere al programma di esempio. IF (HMI.OneWireTrig) THEN i:=Sysmemmove(ADR(UID), ADR(HMI.OneWireData), SIZEOF(UID)); END_IF;
  • DS18B20: “Programmable resolution digital thermometer” per il quale viene tornato UID e temperatura in °C. Per acquisire la temperatura aggiungere al programma di esempio. IF (HMI.OneWireTrig) THEN i:=LEArrayToVar(REAL_TYPE, ADR(Temperature), (HMI.OneWireData[8])); END_IF;

Esempi

Come utilizzare gli esempi.

ST_HMIAInOnePicoface: 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 [0] si passa alla visualizzazione di un messaggio con la data e ora, col tasto [CLR] si ritorna al menù.

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

LogicLab (Ptp114, ST_HMIAInOnePicoface)
PROGRAM ST_HMIAInOnePicoface
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 : HMIAInOnePicoface; (* Picoface terminal *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_HMIAInOnePicoface"
// *****************************************************************************
// An example how to use the Picoface HMI.
// -----------------------------------------------------------------------------

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

    IF (SysFirstLoop) THEN

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

        Sp.COM:=ADR('PCOM15.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.CType:=FALSE; //Communication type
        HMI.DData:=ADR(DData); //Display data
    END_IF;

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

    Sp(Open:=TRUE); //Serial port management
    HMI.File:=Sp.File; //File pointer
    HMI(Enable:=Sp.Opened); //Picoface 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

    // Function key LEDs are switched off, this is made after FB execution to
    // allow the following program instructions to switch on them.

    HMI.FLed0:=FALSE; //LED command [0]
    HMI.FLed1:=FALSE; //LED command [1]
    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 Picoface   |
        // +----------------+

        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 Picoface   '); //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

        // Blink the function key LEDs.

        HMI.FLed0:=SysClock1000; //LED command [0]

        // By pressing the function key [0] the Data/Time message is displayed.

        IF (HMI.FKey0) THEN ScreenIDx:=50; END_IF; //Date and time display

        // ---------------------------------------------------------------------
        // DATE/TIME MESSAGE
        // ---------------------------------------------------------------------
        // The date and time is displayed, exit by pressing the [ESC] key.
        // +----------------+
        // |Date:xx/xx/xxxx |
        // |Time:xx:xx:xx   |
        // +----------------+

        50:
        HMI.FLed0:=TRUE; //LED command [0]
        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.KeyESC) THEN ScreenIDx:=10; END_IF;
    END_CASE;

// [End of file]
LogicLab (Ptp114, ST_DataEntryOnPicoface)
PROGRAM ST_DataEntryOnPicoface
VAR
    i : UDINT; (* Auxiliary counter *)
    KeyFUN : BOOL; (* Function key pulse *)
    Selector : USINT; (* Variable selector *)
    ScreenIDx : USINT; (* Screen index *)
    TimeBf : UDINT; (* Time buffer (mS) *)
    UINTVar : UINT; (* UINT data input variable *)
    REALVar : REAL; (* REAL data input variable *)
    LDTValue : LDATE_AND_TIME; (* Long Date/Time value *)
    DData : STRING[ 32 ]; (* Display data *)
    Sp : SysSerialPort; (* Serial port management *)
    HMI : HMIAInOnePicoface; (* Picoface terminal *)
END_VAR

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

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

    IF (SysFirstLoop) THEN

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

        Sp.COM:=ADR('PCOM15.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 Picoface FB.

        HMI.SpyOn:=TRUE; //Spy On
        HMI.CType:=FALSE; //Communication type
        HMI.DData:=ADR(DData); //Display data

        // Initialize dat input variables

        UINTVar:=1234; //UINT data input variable    
        REALVar:=12.3; //REAL data input variable    
    END_IF;

    // -------------------------------------------------------------------------
    // PICOFACE MANAGEMENT
    // -------------------------------------------------------------------------
    // Here manages the Picoface terminal.

    Sp(Open:=TRUE); //Serial port management
    HMI.File:=Sp.File; //File pointer
    HMI(Enable:=Sp.Opened); //Picoface 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

    // Function key LEDs are switched off, this is made after FB execution to
    // allow the following program instructions to switch on them.

    HMI.FLed0:=FALSE; //LED command [0]
    HMI.FLed1:=FALSE; //LED command [1]
    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 Picoface   |
        // +----------------+

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

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

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

        // ---------------------------------------------------------------------
        // The menu message is displayed.
        // +----------------+
        // |Use keyboard to |
        // |make your choice|
        // +----------------+

        10:
        HMI.DData:=ADR('Use keyboard to make your choice'); //Display data
        HMI.DVCmd:=ADR('    ********                    '); //Display view command
        
        // Blink the function key LEDs.

        HMI.FLed0:=SysClock1000; //LED command [0]
        HMI.FLed1:=SysClock1000; //LED command [1]

        // By pressing the function key a selection is done.

        IF (HMI.FKey0) THEN ScreenIDx:=50; END_IF; //Date and time display
        IF (HMI.FKey1) THEN ScreenIDx:=60; END_IF;

        // ---------------------------------------------------------------------
        // DATE/TIME MESSAGE
        // ---------------------------------------------------------------------
        // The date and time is displayed, exit by pressing the [ESC] key.
        // +----------------+
        // |Date:xx/xx/xxxx |
        // |Time:xx:xx:xx   |
        // +----------------+

        50:
        HMI.FLed0:=TRUE; //LED command [0]
        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.KeyESC) THEN ScreenIDx:=10; END_IF;

        // ---------------------------------------------------------------------
        // BLINK EXAMPLE MESSAGE
        // ---------------------------------------------------------------------
        // It's possible to set a LED[5] blinking time.
        // The date and time is displayed, exit by pressing the CLR key.
        // +----------------+
        // |UINT value:---- |
        // |REAL value:---.-|
        // +----------------+
        // 'UINT value:---- REAL value:---.-'
        // '           ****                 '
        // '                           *****'

        60:
        HMI.FLed1:=TRUE; //LED command [1]

        i:=SysVsnprintf(ADR(DData), SIZEOF(DData), ADR('UINT value:%04.1d '), UINT_TYPE, ADR(UINTVar));
        i:=SysCVsnprintf(ADR(DData), SIZEOF(DData), ADR('REAL value:%05.1f'), REAL_TYPE, ADR(REALVar));

        // By using the [FUN] key it's posible to select the variable to set.
        // The selected variable will blink.

        IF (HMI.KeyFUN <> KeyFUN) THEN
            KeyFUN:=HMI.KeyFUN; //Function key pulse
            TimeBf:=SysTimeGetMs(); //Time buffer (mS)

            IF (HMI.KeyFUN) THEN
                Selector:=Selector+1; //Variable selector
                IF (Selector > 2) THEN Selector:=1; END_IF;
            END_IF;
        END_IF;

        // After a timeout the selection is cleared.

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

        // Blink the relate data value on the disply.

        CASE (Selector) OF

            // ---------------------------------------------------------------------
            // UINT variable data input.

            1:
            HMI.DVCmd:=ADR('           ****                 '); //Display view command
            IF (HMI.KeyCLR) THEN
                Selector:=0; //Variable selector
                HMI.DEPosition:=11; //Data entry position
                HMI.DELength:=4; //Data entry length
                HMI.DEType:=UINT_TYPE; //Data entry type
                HMI.DEValue:=ADR(UINTVar); //Data entry value (Pointer)
                HMI.DEStart:=TRUE; //Data entry start
            END_IF;

            // ---------------------------------------------------------------------
            // REAL variable data input.

            2:
            HMI.DVCmd:=ADR('                           *****'); //Display view command
            IF (HMI.KeyCLR) THEN
                Selector:=0; //Variable selector
                HMI.DEPosition:=27; //Data entry position
                HMI.DELength:=5; //Data entry length
                HMI.DEType:=REAL_TYPE; //Data entry type
                HMI.DEValue:=ADR(REALVar); //Data entry value (Pointer)
                HMI.DEStart:=TRUE; //Data entry start
            END_IF;
        END_CASE;
    END_CASE;

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