Hm, hast du das „!“ auch berücksichtigt, das Paresy da rein gesetzt hat ? Von der Logik her ist es so, dass es sich dann beendet, wenn das Enter NICHT klappt. Ich glaube, dass stimmt dann mit deiner Logik überein, oder ?
Hier nun das Script:
<?
IPSUtils_Include ("IPSInstaller.inc.php","IPSLibrary::install::IPSInstaller");
if(!IPS_SemaphoreEnter("SR7007", 250 /* sehr kurz warten */)) {
return; //Läuft bereits
}
$freq=array(
"8760"=> "NDR 2",
"8830"=> "RB Nordwest",
"8980"=> "Energy Bremen",
"9030"=> "NDR 903",
"9110"=> "NDR 1",
"9250"=> "Radio WeserTV",
"9290"=> "NDR N-Joy",
"9380"=> "RB Bremen",
"9440"=> "NDR Kultur",
"9500"=> "NDR Info",
"9670"=> "WDR Funkhaus",
"9760"=> "BFBS Germany",
"9860"=> "NDR Info",
"9920"=> "NDR Kultur",
"9980"=> "NDR 2",
"10030"=> "DLF Kultur",
"10120"=> "RB Bremen",
"10170"=> "Radio FFN",
"10230"=> "Radio FFN",
"10360"=> "Radio Hamburg",
"10420"=> "Antenne Niedersachsen",
"10480"=> "Antenne Niedersachsen",
"10570"=> "Antenne Niedersachsen",
"10620"=> "DLF Kultur",
"10710"=> "DLF",
"10760"=> "Radio 21",
);
switch ($_IPS['SENDER']){
case 'Execute':
CreateProfile_Switch ('SR7007_Power','Aus', 'An', "", -1, 0x00ff00);
@IPS_CreateVariableProfile('SR7007_Frequenz', 2);
IPS_SetVariableProfileText('SR7007_Frequenz', '', ' MHz');
IPS_SetVariableProfileValues('SR7007_Frequenz', 0, 2000, 0.1);
IPS_SetVariableProfileDigits('SR7007_Frequenz', 2);
IPS_SetScriptTimer($_IPS['SELF'],10);
break;
case 'TimerEvent':
$t=microtime(true);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"PW?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"ZM?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2MU?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2CS?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2CV?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MV?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"SI?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MS?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"DC?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"PSMODE: ?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"TFAN?".chr(13));
usleep(100);
CSCK_SendText(52404 /*[Marantz SR7007]*/,"ST?".chr(13));
IPS_SetScriptTimer($_IPS['SELF'],4+ceil(microtime(true)-$t));
break;
case 'RegisterVariable':
// choe"SR7007: Empfange...
";
// 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, chr(13)))
{
// $data in durch ; separierte Datensätze zerlegen
$datasets = explode(chr(13), $data);
// alle nicht durch ; terminierten Datensätze ausgeben
for ($i = 0; $i < count($datasets) - 1; $i++)
{
if (strpos($datasets[$i],"PWON")===0){
setvalue(CreateVariable("Power", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),true);
}
elseif (strpos($datasets[$i],"PWSTANDBY")===0){
setvalue(CreateVariable("Power", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (strpos($datasets[$i],"ZMON")===0){
setvalue(CreateVariable("Main Zone", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),true);
}
elseif (strpos($datasets[$i],"ZMOFF")===0){
setvalue(CreateVariable("Main Zone", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (strpos($datasets[$i],"Z2ON")===0){
setvalue(CreateVariable("Zone 2", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),true);
}
elseif (strpos($datasets[$i],"Z2OFF")===0){
setvalue(CreateVariable("Zone 2", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (preg_match('/^Z2([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Zone 2 Volume", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^MV([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Master Volume", 1, IPS_GetParent($_IPS['SELF']), 0),(substr($result[1]."0",0,3)/10));
}
elseif (preg_match('/^MVMAX ([0-9]+)/',$datasets[$i],$result)){
echo "SR7007: ".$datasets[$i]."
";
setvalue(CreateVariable("Master Volume Max", 1, IPS_GetParent($_IPS['SELF']), 0),(substr($result[1]."0",0,3)/10));
}
elseif (preg_match('/^SI(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Audio Input", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^SV(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Video Input", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (strpos($datasets[$i],"PSDCO ON")===0){
setvalue(CreateVariable("Main Zone D.COMP", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),true);
}
elseif (strpos($datasets[$i],"PSDCO OFF")===0){
setvalue(CreateVariable("Main Zone D.COMP", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (preg_match('/^PSDRC (.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone DRC direct change", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^PSLFE ([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone LFE", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^PSBAS ([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Bass", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^PSTRE ([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Trebble", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (strpos($datasets[$i],"PSTONE CTRL OFF")===0){
setvalue(CreateVariable("Main Zone Tone Control", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (strpos($datasets[$i],"Z2MUON")===0){
setvalue(CreateVariable("Zone 2 Mute", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),true);
}
elseif (strpos($datasets[$i],"Z2MUOFF")===0){
setvalue(CreateVariable("Zone 2 Mute", 0, IPS_GetParent($_IPS['SELF']), 0, "SR7007_Power"),false);
}
elseif (strpos($datasets[$i],"Z2CSST")===0){
setvalue(CreateVariable("Zone 2 Channel Setting", 3, IPS_GetParent($_IPS['SELF']), 0),"STEREO");
}
elseif (strpos($datasets[$i],"Z2CSMONO")===0){
setvalue(CreateVariable("Zone 2 Channel Setting", 3, IPS_GetParent($_IPS['SELF']), 0),"MONO");
}
elseif (preg_match('/^Z2CVFL ([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Zone 2 Front L Level", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^Z2CVFR ([0-9]+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Zone 2 Front R Level", 1, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^Z2(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Zone 2 Input", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^MS(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Surround Mode", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^DC(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Decode Mode", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^PSMODE:(.+)/',$datasets[$i],$result)){
setvalue(CreateVariable("Main Zone Sourround Mode", 3, IPS_GetParent($_IPS['SELF']), 0),$result[1]);
}
elseif (preg_match('/^TFAN([0-9]{6})/',$datasets[$i],$result)){
if (!($disp=$freq[(int)$result[1]])) $disp=$result[1]/100;
setvalue(CreateVariable("Tuner Frequenzy", 2, IPS_GetParent($_IPS['SELF']), 0, 'SR7007_Frequenz'),$result[1]/100);
setvalue(CreateVariable("Tuner Display", 3, IPS_GetParent($_IPS['SELF']), 0, 'SR7007_Frequenz'),$disp);
}
elseif (substr($datasets[$i],0,1)!="@"){
echo "SR7007: ".$datasets[$i]."
";
}
// else{
// echo "SR7007: ".$datasets[$i]."
";
// }
}
// $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);
break;
case 'Designer':
if (strpos($_IPS['COMPONENT'],'SR7007WZ')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,(getvalue(59978 /*[sr7007 Wohnzimmer\Main Zone]*/ )?"ZMOFF":"ZMON").chr(13));
CSCK_SendText(52404 /*[Marantz SR7007]*/,"SICD".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMPWR')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,(getvalue(59978 /*[sr7007 Wohnzimmer\Main Zone]*/ )?"ZMOFF":"ZMON").chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMVOLP')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MVUP".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMVOLM')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MVDOWN".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMISTUNER')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"SITUNER".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMISC3PO')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"SISAT/CBL".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007ZMISCD')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"SICD".chr(13));
}
elseif (preg_match('/^SR7007ZMVOL([0-9]+)/',$_IPS['COMPONENT'],$result)){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MV".$result[1].chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007Z2PWR')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,(getvalue(25155 /*[sr7007 Wohnzimmer\Zone 2]*/ )?"Z2OFF":"Z2ON").chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007Z2VOLP')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2UP".chr(13));
}
elseif (strpos($_IPS['COMPONENT'],'SR7007Z2VOLM')===0){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2DOWN".chr(13));
}
elseif (preg_match('/^SR7007Z2VOL([0-9]+)/',$_IPS['COMPONENT'],$result)){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"Z2".$result[1].chr(13));
}
elseif (preg_match('/^SR7007MS(.+)/',$_IPS['COMPONENT'],$result)){
CSCK_SendText(52404 /*[Marantz SR7007]*/,"MS".str_replace("_"," ",$result[1]).chr(13));
}
break;
case 'Variable':
if ($_IPS['VARIABLE']==37778 /*[sr7007 Wohnzimmer\Command]*/){
$cmdarr=explode(";",$_IPS['VALUE']);
for ($i=0;$i<count($cmdarr);$i++){
CSCK_SendText(52404 /*[Marantz SR7007]*/,$cmdarr[$i].chr(13));
usleep(100000);
}
}
break;
default:
setvalue(25074 /*[sr7007 Wohnzimmer\Debug]*/,$_IPS['SENDER']);
break;
}
Aufräumen. Falls das Skript vorher stirbt, gibt es eine weitere Fehlermeldung, aber die Semaphore wird trotzdem aufgeräumt!
IPS_SemaphoreLeave("SR7007");
function SR7007_Input($value){
$arr=IPS_GetVariableProfile("SR7007_Input")['Associations'];
$ret=false;
for ($i=0;$i<count($arr);$i++){
if ($arr[$i]['Name']==$value){
$ret=$i;
}
}
return $ret;
}
?>
für weitere Anregungen insb. mit dem RunScript bin ich sehr dankbar ! Das Script läut super und auch stabil, wenn die Semaphore-Geschichte nicht drin ist. Jedoch kann es sein, dass es dann die Threads blockiert.
Mit dem Semaphore läuft es auch - aber dann nur einige Stunden stabil. Danach greift offenbar der ENTER nicht mehr und lässt das Script nur noch vorzeitig abbrechen (Ausstieg beim SemaphoreEnter)