Documentation
RegisterVariable
The RegisterVariable provides a data forwarding interface and data processing interface.
Configuration
If you have not set up your device, please follow the steps on this page: [embed devices] [2]
The RegisterVariable module connects automatically with a parent instance. You need to select parent instance or create a new one. You can also add another splitter (e.g. cutter) to synchronize the incoming data directly before evaluation.
The execution of scripts is serial. It means that you do not have to protect your scripts with semaphores.
Date processing
If the the parent instance (communication interface) receives new data, the target script of the RegisterVariable instance will be run. In this the received data over $ _IPS ['VALUE'] is available.
There are data sources that provide a meaningful evaluation after receiving several data transmissions. Therefore, the received data is temporarily stored. Problem can occur, if you store binary data in a normal string variable in IP-Symcon (defective IP-Symcon configuration). There is the function RegVar_SetBuffer (integer $InstanzID, string $buffer) that stores the data in the buffer associated to the RegisterVariable instance. The data stored in the buffer can be read with the function RegVar_GetBuffer (integer $InstanzID). The function RegVar_SendText (integer $InstanzID, string $ text) can send data strings over the communication interface. Internally, the appropriate transmission function (e.g. COMPort_SendText) is executed.
The buffer is cleared after restarting IP-Symcon
Please DO NOT use VARIABLE as a buffer. Otherwise, it may cause instability within IP-Symcon and at worst cause a completely destroyed configuration. Since this problem can also affect the incremental backup folder, you may not even have a backup configuration. Take advantage of the internal buffer of the instance, to cache data.
RegVar_SetBuffer / RegVar_GetBuffer
Example
The following example chaines received data and gives out by ; separated records at completion:
// wenn das Skript von einer RegisterVariable-Instanz aus aufgerufen worden ist if ($_IPS['SENDER'] == "RegisterVariable") { // bereits im Puffer der Instanz vorhandene Daten in $data kopieren $data = RegVar_GetBuffer($_IPS['INSTANCE']); // neu empfangene Daten an $data anhängen $data .= $_IPS['VALUE']; // wenn das Trennzeichen ; in $data gefunden worden ist if (strpos($data, ';')) { // $data in durch ; separierte Datensätze zerlegen $datasets = explode(';', $data); // alle nicht durch ; terminierten Datensätze ausgeben for ($i = 0; $i < count($datasets) - 1; $i++) { echo "empfangener Datensatz: ".$datasets[$i]."\n"; } // $data auf den Inhalt des letzten (unvollständigen) Datensatzes setzen $data = $datasets[count($datasets) - 1]; } // Inhalt von $data im Puffer der RegisterVariable-Instanz speichern RegVar_SetBuffer($_IPS['INSTANCE'], $data); }
Following example chaines received data and outputs blocks from a length of exactly 16 characters:
// wenn das Skript von einer RegisterVariable-Instanz aus aufgerufen worden ist if ($_IPS['SENDER'] == "RegisterVariable") { // bereits im Puffer der Instanz vorhandene Daten in $data kopieren $data = RegVar_GetBuffer($_IPS['INSTANCE']); // neu empfangene Daten an $data anhängen $data .= $_IPS['VALUE']; // wenn $data mindestens 16 Zeichen lang ist if (strlen($data) >= 16) { // $data in Blöcke von bis zu 16 Zeichen zerlegen $datasets = str_split($data, 16); // $data leeren $data = ""; // alle Datensätze durcharbeiten for ($i = 0; $i < count($datasets); $i++) { // vollständige Datensätze (genau 16 Zeichen lang) ausgeben if (strlen($datasets[$i]) == 16) { echo "empfangener Datensatz: ".$datasets[$i]."\n"; } else { // Unvollständige Datensätze in $data schreiben $data = $datasets[$i]; } } } // Inhalt von $data im Puffer der RegisterVariable-Instanz speichern RegVar_SetBuffer($_IPS['INSTANCE'], $data); }