DO von CC100 hinzugefühgt.

This commit is contained in:
2024-10-07 16:19:07 +02:00
parent ead95013f3
commit 105672301a
5 changed files with 210 additions and 2 deletions

1
.gitignore vendored
View File

@@ -29,4 +29,3 @@
/User_Template /User_Template
/Wechselrichter /Wechselrichter
/CC100_HW

67
CC100_HW/README.md Normal file
View File

@@ -0,0 +1,67 @@
# Manager_1
Beschreibung des Moduls.
### Inhaltsverzeichnis
1. [Funktionsumfang](#1-funktionsumfang)
2. [Voraussetzungen](#2-voraussetzungen)
3. [Software-Installation](#3-software-installation)
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
6. [WebFront](#6-webfront)
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
### 1. Funktionsumfang
*
### 2. Voraussetzungen
- IP-Symcon ab Version 7.1
### 3. Software-Installation
* Über den Module Store das 'Manager_1'-Modul installieren.
* Alternativ über das Module Control folgende URL hinzufügen
### 4. Einrichten der Instanzen in IP-Symcon
Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden.
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
__Konfigurationsseite__:
Name | Beschreibung
-------- | ------------------
|
|
### 5. Statusvariablen und Profile
Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.
#### Statusvariablen
Name | Typ | Beschreibung
------ | ------- | ------------
| |
| |
#### Profile
Name | Typ
------ | -------
|
|
### 6. WebFront
Die Funktionalität, die das Modul im WebFront bietet.
### 7. PHP-Befehlsreferenz
`boolean GEF_BeispielFunktion(integer $InstanzID);`
Erklärung der Funktion.
Beispiel:
`GEF_BeispielFunktion(12345);`

9
CC100_HW/locale.json Normal file
View File

@@ -0,0 +1,9 @@
{
"translations": {
"de": {
"Translation 1": "Übersetzung 1",
"Translation 2": "Übersetzung 2"
}
}
}

12
CC100_HW/module.json Normal file
View File

@@ -0,0 +1,12 @@
{
"id": "{21F800F4-A506-62C9-CF26-9CA152629C22}",
"name": "CC100_HW",
"type": 3,
"vendor": "Belevo AG",
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "GEF",
"url": ""
}

121
CC100_HW/module.php Normal file
View File

@@ -0,0 +1,121 @@
<?php
class CC100_HW extends IPSModule
{
private $DigOutPID = '/sys/kernel/dout_drv/DOUT_DATA';
private $PT1PID = '/sys/bus/iio/devices/iio:device2/in_voltage13_raw';
private $PT2PID = '/sys/bus/iio/devices/iio:device2/in_voltage1_raw';
private $waitingTime = 1; // Waiting time (in ms) for a new attempt to write a digital output (if file is blocked)
private $maxTime = 5000; // Max time (in ms) for the writing process
public function Create()
{
parent::Create();
$this->RegisterPropertyString('FilePath', $this->DigOutPID);
$this->RegisterVariableBoolean('Bit1', 'DO 1', '~Switch', 1);
$this->RegisterVariableBoolean('Bit2', 'DO 2', '~Switch', 2);
$this->RegisterVariableBoolean('Bit3', 'DO 3', '~Switch', 3);
$this->RegisterVariableBoolean('Bit4', 'DO 4', '~Switch', 4);
$this->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5);
$this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6);
$this->EnableAction('Bit1');
$this->EnableAction('Bit2');
$this->EnableAction('Bit3');
$this->EnableAction('Bit4');
// Timer für PT1 und PT2 einrichten
$this->RegisterTimer("ReadPTValues", 30000, 'IPS_RequestAction(' . $this->InstanceID . ', "DOUT_ReadPTValues", "");');
}
public function ApplyChanges()
{
parent::ApplyChanges();
// Timer aktivieren
$this->SetTimerInterval('ReadPTValues', 30000);
}
public function RequestAction($Ident, $Value) {
switch ($Ident) {
case "DOUT_ReadPTValues":
$this->DOUT_ReadPTValues();
break;
default:
throw new Exception("Invalid Ident");
}
}
private function UpdateFile()
{
$starttime = microtime(true) * 1000;
$this->TryWriteFile($starttime);
}
private function TryWriteFile($starttime)
{
$currentTime = microtime(true) * 1000;
if (($currentTime - $starttime) <= $this->maxTime) {
$file = $this->ReadPropertyString('FilePath');
if (is_writable($file)) {
$bit1 = GetValueBoolean($this->GetIDForIdent('Bit1'));
$bit2 = GetValueBoolean($this->GetIDForIdent('Bit2'));
$bit3 = GetValueBoolean($this->GetIDForIdent('Bit3'));
$bit4 = GetValueBoolean($this->GetIDForIdent('Bit4'));
$value = ($bit4 ? 8 : 0) + ($bit3 ? 4 : 0) + ($bit2 ? 2 : 0) + ($bit1 ? 1 : 0);
if (@file_put_contents($file, $value) === false) {
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht beschrieben werden. Möglicherweise gesperrt.");
usleep($this->waitingTime * 1000);
$this->TryWriteFile($starttime);
} else {
IPS_LogMessage("DOUTModule", "Wert $value erfolgreich in die Datei $file geschrieben.");
}
} else {
IPS_LogMessage("DOUTModule", "Fehler: Datei $file ist nicht schreibbar.");
usleep($this->waitingTime * 1000);
$this->TryWriteFile($starttime);
}
} else {
IPS_LogMessage("DOUTModule", "Fehler: Schreibvorgang für Datei $file hat zu lange gedauert.");
}
}
public function DOUT_ReadPTValues()
{
$pt1Value = $this->ReadPTValue($this->PT1PID);
$pt2Value = $this->ReadPTValue($this->PT2PID);
SetValue($this->GetIDForIdent('PT1'), $pt1Value);
SetValue($this->GetIDForIdent('PT2'), $pt2Value);
}
private function ReadPTValue($file)
{
if (file_exists($file)) {
$data = @file_get_contents($file);
if ($data !== false) {
$data = intval($data);
$scale = 0;
if ($data >= 600 && $data < 3600) { $scale = 37;}
else if ($data >= 3600 && $data < 6700) { $scale = 43;}
else if ($data >= 6700 && $data < 9750) { $scale = 45;}
else if ($data >= 9750 && $data < 12740) { $scale = 49;}
else if ($data >= 12740 && $data < 15700) { $scale = 50.6;}
else if ($data >= 15700 && $data < 21000) { $scale = 52.4;}
else if ($data > 21000) { $scale = 53.7;}
$numb = $data / $scale - 200;
return round($numb, 1);
} else {
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht gelesen werden.");
}
} else {
IPS_LogMessage("DOUTModule", "Fehler: Datei $file existiert nicht.");
}
return 0;
}
}
?>