Questo blocco funzione da eseguire in task Back, esegue la gestione di un comando di uscita digitale sui dispositivi Milesight.
L’uscita Synced si attiva solo dopo avere inviato il comando ed averne verificato lo stato, quindi se è attivo si è certi che la l’uscita digitale si trovi nello stato settato in Out.
Descrizione
Out (BOOL) Comando uscita.
MDev (@MlsDevice) Indirizzo allocazione FB MlsMlsDevice di supporto.
OName (@STRING) Definizione nome comando da inviare.
TRetry (TIME) Definizione tempo reinvio comando se non ricevuto da dispositivo (S).
Fault (BOOL) Attivo per un loop se errore esecuzione.
Synced (BOOL) Attivo se stato uscita sincronizzato con comando.
Retries (UDINT) Counter reinvii effettuati.

OName: Definizione nome comando
Nel campo OName occore indicare il nome del comando da inviare per gestire l’uscita desiderata, il nome varia in base al programma di codifica Encoder utilizzato (Vedi capitolo Milesight payload codec in questo articolo). Di seguito le definizioni normalmente utilizzate:
Dispositivo | Nome comando |
---|---|
UC300 | gpio_output_1: Comanda uscita logica DO_1 gpio_output_2: Comanda uscita logica DO_2 |
UC51x | valve_1: Comanda solenoide valvola OUT1 valve_2: Comanda solenoide valvola OUT2 |
Esempi
Viene gestito un UC512 controllore di elettrovalvole LoRaWAN della Milesight.
LogicLab (Ptp208, MlsDOutput)
PROGRAM ST_MlsDOutput
VAR
i : UDINT; (* Auxiliary variable *)
SPData : MQTT_TS_DATA; (* MQTT topic subscribe data *)
TCPClient : SysTCPClient; (* TCP client management *)
FIFO : FIFOFile_v1; (* FIFO on file *)
MQTT : MQTTClient_v3; (* MQTT client FB *)
MDev : MlsDevice; (* Milesight device manager *)
DOut : ARRAY[0..1] OF MlsDOutput; (* Milesight digital output *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_MlsDOutput"
// *****************************************************************************
// Are managed the two digital output of a Milesight UC51x device.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// INITIALIZATION
// -------------------------------------------------------------------------
// Initialize the FB parameters.
IF (SysFirstLoop) THEN
// Set FIFO parameters.
FIFO.FIFOFilename:=eNULL; //Path and name of FIFO file
FIFO.FIFOSize:=2048; //FIFO file size
FIFO.FIFOIDx:=eNULL; //FIFO indexes
// Set TCPClient parameters.
TCPClient.PeerAdd:=ADR('192.168.1.150'); //Peer address
TCPClient.PeerPort:=1883; //Peer port
TCPClient.LocalAdd:=ADR('0.0.0.0'); //Local address
TCPClient.LocalPort:=0; //Local port
TCPClient.FlushTm:=0; //Flush time (mS)
TCPClient.LifeTm:=90; //Life time (S)
TCPClient.RxSize:=1512; //Rx buffer size
TCPClient.TxSize:=512; //Tx buffer size
// Set MQTTClient parameters.
MQTT.SpyOn:=FALSE; //Spy active
MQTT.FIFOFile:=ADR(FIFO); //FIFO on file
MQTT.CFlags:=16#02; //Clean session
MQTT.Username:=ADR('loraadm'); //Broker username
MQTT.Password:=ADR('URloraadm123456'); //Broker password
MQTT.ClientID:=eNULL; //Client identifier
MQTT.KeepAlive:=T#90s; //Keep alive time
MQTT.Delay:=T#1s; //Send delay time
MQTT.Timeout:=T#5s; //Execution timeout
// Topic subscribe definitions.
// Subscribe to all applications and all devices rx data.
MQTT.TSData:=ADR(SPData); //Topic subscribe data
MQTT.TSNumber:=1; //Topic subscribe number
eTO_JUNK(MQTT.Subscribe(0, ADR('application/+/device/+/rx'), eNULL, 0, 0));
// Milesight device definitions.
MDev.Enable:=TRUE; //FB enable
MDev.SpyOn:=TRUE; //Spy On
MDev.MQTT:=ADR(MQTT); //MQTT client
MDev.DTopic:=ADR('application/1/device'); //Device topic
MDev.EUI:=ADR('24e124460d445153'); //Device EUI
MDev.Timeout:=T#5m; //Timeout
// Milesight UC51x digital outputs.
DOut[0].OName:=ADR('valve_1'); //Output name
DOut[1].OName:=ADR('valve_2'); //Output name
FOR i:=0 TO 1 DO DOut[i].MDev:=ADR(MDev); DOut[i].TRetry:=T#15s; END_FOR;
END_IF;
// -------------------------------------------------------------------------
// FBs EXECUTION
// -------------------------------------------------------------------------
// FBs execution.
TCPClient(Connect:=MQTT.Connect); //TCPClient management
MQTT(Enable:=TRUE, File:=TCPClient.File); //MQTTClient management
// Device management, send the init downlink settings.
MDev(); //Milesight device manager
IF (MDev.DInit) THEN
eTO_JUNK(MDev.DLinkJSON(ADR('{"report_interval":120}'))); //Set reporting interval, 120 (S)
eTO_JUNK(MDev.DLinkJSON(ADR('{"response_time":30}'))); //Set response time, 30 (S)
END_IF;
// Manage the device digital outputs.
FOR i:=0 TO 1 DO DOut[i](); END_FOR;
// [End of file]