Ankündigung

Einklappen
Keine Ankündigung bisher.

Anfrage für LBS

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    #31
    Ahja stimmt müsste hier nicht ein ; stehen am Ende der Zeile 432

    PHP-Code:
    $lastBalance false
    Bzw am Ende jeder Variabledeklaration von 426 bis 432

    also quasi so:

    PHP-Code:
    static $lastPower false;
                   
    $lastInputSelect false;
                   
    $lastVolumeMute false;
                   
    $lastVolumeControl false;
                   
    $lastTreble false;
                   
    $lastBass false;
                   
    $lastBalance false
    zumindest, wenn nur lastPower static sein soll. Wenn alle static sein sollen eben noch ein static vor die Zeilen jeweils.
    Zuletzt geändert von magiczambo; 20.07.2016, 12:29.
    Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

    Kommentar


      #32
      Hey, ihr seid meine Helde
      Der Fehler lag in der Zeile 432

      PHP-Code:
       $lastBalance false
      Hier stand vorher etwas anderes und ich hab beim löschen nicht gemerkt das in dieser Zeile ein Strichpunkt anstatt Komma war.
      So funktioniert es jetzt:
      PHP-Code:
       $lastBalance false

      Vielen vielen Dank für die Hilfe, und an jonofe für die tolle Arbeit
      Wenn ich heut abend noch dazu komm (was ich fast nicht glaub) dann teste ich mal ob es auch so funktioniert, währ ja der Hammer .
      Dann könnt ich nämlich gleich noch nen Baustein für mein Pioneer Plasma machen, der geht nämlich auch nur über RS232
      Zuletzt geändert von stonie2oo4; 20.07.2016, 12:42.
      Gruß Ben

      Kommentar


        #33
        Ob alle Zeilen ein Strichpunkt brauchen weiß ich nicht, das müsste vielleicht jonofe beantworten .
        Gruß Ben

        Kommentar


          #34
          http://php.net/manual/de/language.ba...separation.php
          Danke und LG, Dariusz
          GIRA | ENERTEX | MDT | MEANWELL | 24VDC LED | iBEMI | EDOMI | ETS5 | DS214+ | KNX/RS232-GW-ROTEL

          Kommentar


            #35
            Zitat von gaert Beitrag anzeigen
            NWarum kauft man noch Geräte ohne LAN?! Selbst mein billigst-Receiver hat einen (funktionierenden) LAN-Anschluss...
            Bei manchen Geräten ist das nach wie vor schwierig. Oder diese sind schon im Bestand und lassen sich nicht so einfach "rauswerfen".
            KWL (Lüftungsanlage) wäre so ein Beispiel. Heizung, Wärmepumpe, Entkalkung, oder PV-Wechselrichter vielleicht auch...
            Bei Neuanschaffungen muss ich dir allerdings vollkommen zustimmen, da sollte man wo immer möglich auf direkte IP-Anbindung Wert legen.

            Btw.: Gibt es bereits eine funktionierende edomi-Anbindung/LBS für die Comfoair (350/550) von Zehnder?

            Gruß -mfd-
            KNX-UF-IconSet since 2011

            Kommentar


              #36
              Also so leicht wie ich es gedacht hab, scheint es wohl doch nicht zu laufen...
              Hab jetzt grad mal ein paar Tests gemacht.

              Als erstes, weiß jemand wie ich mein Moxa einstellen muss?
              Habs momentan so probiert:
              1.JPG

              2.JPG
              Zweitens, welchen Port muss ich im LBS eintragen: Local TCP port oder Command port (habs schon mit beiden versucht, hat aber nichts geholfen)

              Hab mal ein paar Tests gemacht im RealCom Mode und mit meinem Windows Rechner mit Putty.
              Verkabelung scheint zu passen, weil so bekomm ich ne Verbindung und kann auch Befehle absetzten.

              z.B.: <11PR01 schaltet Zone 1 Power an
              Im LBS steh ja z.B. folgendes:
              PHP-Code:
              $cmd $this->ZoneID." PR 00"

              Wenn jetzt z.B. die ZoneID auf 11 steht dann kommt ja folgender Befehl raus:

              11 PR 00

              Richtig?
              Das währe ja aber falsch. Wie müsste ich das dann anpassen das es wie oben beschrieben richtig raus kommt?
              So?
              PHP-Code:
              $cmd $this->">".ZoneID."PR00"

              Hab auch schon versucht in der Visu (LBS) nen raw command abzusetzten, also z.B. wie oben: <11PR01
              Aber auch hier passiert "nix", also im Log steht folgendes:
              EXE19000501: Received Command to be executed: <11PR01 [v0.1]
              EXE19000501: Command: a:1:{i:0;s:7:"<11PR01";} [v0.1]
              EXE19000501: Value: [v0.1]
              Also sieht für mich so aus als wenn er den Befehl ausführt, bloß scheint iwie nix am Monoprice anzukommen.

              Irgend welche Ideen was ich noch probieren könnte?
              Gruß Ben

              Kommentar


                #37
                Zitat von stonie2oo4 Beitrag anzeigen
                Das währe ja aber falsch. Wie müsste ich das dann anpassen das es wie oben beschrieben richtig raus kommt?
                So?
                PHP-Code:
                $cmd $this->">".ZoneID."PR00"
                Naja wenn dann eher so:
                PHP-Code:
                $cmd ="<".$this->ZoneID."PR00"

                Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                Kommentar


                  #38
                  Ups natürlich, war falsch herum. Du hast aber auch Adleraugen
                  Gruß Ben

                  Kommentar


                    #39
                    Zitat von stonie2oo4 Beitrag anzeigen
                    Ups natürlich, war falsch herum. Du hast aber auch Adleraugen
                    Nicht nur falschherum, sondern auch außerhalb des $this->ZoneID
                    Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                    Kommentar


                      #40
                      Stimmt, bin wohl eher ich mit Tomaten auf den Augen.
                      Danke dir
                      Gruß Ben

                      Kommentar


                        #41
                        Also, bin jetzt schon mal einen Schritt weiter . Verbindung zum Monoprice über Moxa im TCP-Servermodus funktioniert und ich kann die vorgewählte Zone über „POWER_ON“ an schalten, bzw. über „POWER_OFF“ ausschalten. Ich nehme an, die anderen Befehle funktionieren auch, konnte es aber noch nicht testen.

                        So, jetzt zu dem was noch nicht geht:
                        1. Raw-Commando senden funktioniert komischer weiße nicht, also wenn ich z.B. „<11PR01“ eingebe kann ich ihn nicht einschalten, wobei ja bei „POWER_ON“ eigentlich das selbe Kommando geschickt werden sollte.
                        2. Die Rückmeldung funktioniert noch nicht.

                        Wenn ich über Putty in der Konsole folgendes eingebe: „?11PR“
                        Bekomme ich folgende zurück: „>11PR01“ oder halt „>11PR00“ je nachdem ob an oder aus. Man beachte bei der Rückmeldung ist das Größer-/ Kleiner Zeichen tatsächlich anderst herum als beim Befehl fürs einschalten/ausschalten.

                        Hab jetzt schon ein bisschen rumexperimentiert, aber es will noch nicht so richtig.
                        Im letzten Block nach dieser Zeile:
                        PHP-Code:
                         if ($power == 1)  // only retrieve further attributes when Monoprice is switched on 

                        Hab ich es mal so probiert:
                        PHP-Code:
                                    $inputSelect = (int) $this->sendCmd("?".$this->ZoneID."CH");
                                    if (
                        $inputSelect !== $lastInputSelect)
                                    {
                                        
                        setLogicLinkAusgang($id,4,$inputSelect);
                                        
                        $lastInputSelect $inputSelect;
                                    } 

                        Oder auch anstatt dem „?“ mit “<” oder “>”. Aber hat alles nicht geholfen.
                        Weiß jetzt nicht wo ich noch drehen kann. Jemand nen Tipp?
                        Gruß Ben

                        Kommentar


                          #42
                          Okay, ich glaub ich weiß jetzt ungefähr wo das Problem liegt.
                          Beim LG-TV LBS von jonofe gibt’s es (wenn ich es richtig verstanden hab) beim Auslesen des Status ein Ack zurück.
                          In diesem kommt entweder „OK“ vor oder „NG“. Und das wird im LBS verwendet um zu unterscheiden ob Status OK ist oder ein False zurück kommt.
                          Dementsprechend wird dann der Status ausgelesen und den Ausgängen zugeordnet.
                          So ungefähr

                          Das Problem welches ich jetzt hab, ist dass beim Monoprice dies nicht vor (OK oder NG) kommt und ich leider auch nicht weiß, wie ich den LBS umgestalte, dass es doch funktioniert.
                          Dort kann man nur mit folgendem Befehl den Status abfragen:

                          Code:
                          ?11PR
                          Und zurück kommt z.B. (wenn Power AUS):

                          Code:
                          >11PR00
                          Und bei Fehler:

                          Code:
                          Command Error.

                          Weiß vielleicht jemand, bzw. hat Lust mir zu Zeigen wie ich den LBS umbauen muss, damit dies auch funktioniert?
                          Gruß Ben

                          Kommentar


                            #43
                            Das kommt darauf an, was du genau willst.

                            Willst du die Rückmeldung ebenfalls auswerten oder fire and forget?

                            Wenn du die Rückmeldung willst, dann müsstest eben an allen stellen, des LG Bausteines an dem eine Rückmeldung geprüft wird, den Code so umgestalten, dass du dort eine Status Abfrage an den Monoprice sendest und dann die Rückmeldung entsprechend auswertest.

                            Auf die schnelle nachgeschaut. Schau dir in diesem Fall die function readResponse dazu genauer an.

                            Wenn du fire and Forget willst, dann müsstest du die Prüfung des RM Wertes entfernen.

                            So ca.
                            Zuletzt geändert von magiczambo; 26.07.2016, 06:24.
                            Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                            Kommentar


                              #44
                              Hier mal der LBS, wie ich ihn bisher umgestellt hab.
                              Und ja, will den Status zurück haben, ohne ist iwie doof.
                              Glaub die Abfrage ist nicht das Problem, eher die Auswertung .


                              PHP-Code:
                              ###[DEF]###
                              [name        = Monoprice 10761 RS-232C    (v0.1) ]

                              [e#1        = IP ]
                              [e#2        = Port ]
                              [e#3        = ZoneID ]
                              [e#4        = Command ]
                              [e#5        = Log level ]

                              [a#1        = Result ]
                              [a#2        = Error ]
                              [a#3        = Power ]
                              [a#4        = Input ]
                              [a#5        = Volume Mute ]
                              [a#6        = Volume ]
                              [a#7        = Treble ]
                              [a#8        = Bass ]
                              [a#9        = Balance ]

                              [v#1        = 0 ]
                              [v#2        = 0 ]
                              [v#100        = 0.1 ]
                              [v#101        = 19000501 ]
                              [v#102        = Monoprice 10761 RS-232C ]
                              [v#103        = 0 ]

                              ###[/DEF]###


                              ###[HELP]###
                              This LBS controls an Monoprice 10761 connected via a Ethernet-to-RS-232C adapter (e.g. Moxa NPort 5110)  to your home network.

                              Simple Configutaion:
                              E1: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
                              E2: Port, which you have configured you TCP/IP Server on
                              E3: ZoneID, which Zone you want to control of your Monoprice 10761 (10-All Zone|11-Zone1|12-Zone2|13-Zone3|14-Zone4|15-Zone5|16-Zone6)
                              E4: The Command, which you want to send to your Monoprice 10761
                              E5: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)

                              Available commands:

                              COMMAND - raw command accoring to the RS-232C documentation of Monoprice ==> e.g. "11 PR 01" (11=ZoneID, PR=Power, 01=ON)
                              POWER (00|01)
                              POWER_ON
                              POWER_OFF
                              VOLUMEMUTE (00-Volume mute on|01-Volume mute off)
                              MUTE (same as VOLUMEMUTE)
                              VOLUMEMUTE_ON (=MUTE 00)
                              MUTE_ON (same as VOLUMEMUTE_ON)
                              VOLUMEMUTE_OFF (=MUTE 01)
                              MUTE_OFF (same as VOLUMEMUTE_OFF)
                              VOLUME (00-38)
                              VOLUMECONTROL (same as VOLUME)
                              TREBLE (00-14)
                              BASS  (00-14)
                              BALANCE  (00-20)
                              INPUTSELECT (01-Source 1|02-Source 2|03-Source 3|04-Source 4|05-Source 5|06-Source 6)
                              INPUT        (same as INPUTSELECT)

                              The outputs are updated automatically every 1/4 second. You can expect 1-3 seconds delay when sending an command, until the outputs are updated.
                              The outputs correspond to the commands above and should self explanatory. If the Monoprice is switched off, only the POWER output contains valid information.
                              Monoprice will not respond to other requests.

                              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                              Prerequesite before using this LBS
                              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                              - Install php-process:

                              yum install php-process

                              Enjoy ...
                               
                              Changelog:
                              ==========
                              v0.1: Initial version

                              ###[/HELP]###


                              ###[LBS]###
                              <?

                              function LB_LBSID_logging($id, $msg, $priority=8)
                              {
                                  $E=getLogicEingangDataAll($id);
                                  $logLevel = getLogicElementVar($id,103);
                                  if (is_int($priority) && $priority<=$logLevel && $priority>0)
                                  {
                                      $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                                      $version = getLogicElementVar($id,100);
                                      $lbsNo = getLogicElementVar($id,101);
                                      $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                                      strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                                      writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
                                  }
                              }

                              function LB_LBSID($id) {
                                  if ($E=getLogicEingangDataAll($id)) {
                                      setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103
                                      LB_LBSID_logging($id,'Logic started');
                                      if (getLogicElementVar($id,1)!=1) {
                                          setLogicElementVar($id,1,1);
                                          $uniqid = hexdec(uniqid());
                                          setLogicElementVar($id,2,$uniqid);
                                          callLogicFunctionExec(LBSID,$id);
                                      } else {
                                          $uniqid = getLogicElementVar($id,2);
                                          $msg_queue = msg_get_queue ( $uniqid );
                                          if ($E[4]['refresh']==1) {
                                              $cmd = $E[4]['value'];
                                              msg_send($msg_queue,1,$cmd);
                                              LB_LBSID_logging($id,'Sending command to EXEC daemon: '.$cmd);
                                          }
                                      }
                                      LB_LBSID_logging($id,'Logic finished');
                                  }
                              }
                              ?>
                              ###[/LBS]###


                              ###[EXEC]###
                              <?
                              require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
                              set_time_limit(0);
                              sql_connect();

                              function logging($id,$msg, $priority=8)
                              {
                                  $E=getLogicEingangDataAll($id);
                                  $logLevel = getLogicElementVar($id,103);
                                  if (is_int($priority) && $priority<=$logLevel && $priority>0)
                                  {
                                      $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                                      $version = getLogicElementVar($id,100);
                                      $lbsNo = getLogicElementVar($id,101);
                                      $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                                      strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                                      writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
                                  }
                              }

                              if ($E=getLogicEingangDataAll($id))
                              {
                                  $ip = $E[1]['value'];
                                  $port = $E[2]['value'];
                                  $ZoneID = $E[3]['value'];

                                  setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103

                                  logging($id,'Daemon started');
                                  
                                  $uniqid=getLogicElementVar($id,2);
                                  $msg_queue = msg_get_queue ( $uniqid );
                                  
                                  $mono = new mono_moxa($ip,$port,$ZoneID);
                                  $mono->connect();
                                  $commandExecutionTime = 0;
                                  
                                  while (getSysInfo(1))
                                  {
                                      logging($id,'READ:'.MSG_IPC_NOWAIT);
                                      ;
                                      if (msg_receive($msg_queue,1,$msgtype, 4096, $msg, true, MSG_IPC_NOWAIT, $msg_error))
                                      {
                                          logging($id,'Received Command to be executed: '.$msg);
                                          $command = explode(' ',$msg);
                                          $result = $mono->command($command);
                                          $commandExecutionTime = microtime(true);
                                          if (!$result)
                                          {
                                              setLogicLinkAusgang($id,1,'ERROR');
                                              setLogicLinkAusgang($id,2,1);
                                          } else {
                                              setLogicLinkAusgang($id,1,$result);
                                              setLogicLinkAusgang($id,2,0);
                                          }
                                      }

                                      // read status regularly but not during the first second after a command was issued
                                      if ((microtime(true)-$commandExecutionTime)>=1)
                                      {
                                        $commandExecutionTime = 0;  
                                        $mono->status();
                                      }
                                      usleep(100000);
                                      logging($id,'END');
                                  }
                                  logging($id,'Daemon terminated');
                              }

                              $mono->disconnect();
                              msg_remove_queue($msg_queue);

                              sql_disconnect();


                              class mono_moxa
                              {
                                  private $moxa_ip;
                                  private $moxa_port;
                                  private $moxa_connection;
                                  private $ZoneID;

                                  function mono_moxa($moxa_ip, $moxa_port ,$ZoneID)
                                  {
                                      $this->moxa_ip = $moxa_ip;
                                      $this->moxa_port = $moxa_port;
                                      $this->ZoneID = $ZoneID;

                                  }

                                  function connect()
                                  {
                                      // Create socket
                                      if ($this->moxa_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
                                      {
                                          // Bind the source address
                                          if (socket_bind($this->moxa_connection, global_serverIP))
                                          {
                                              // Connect to destination address
                                              if (socket_connect($this->moxa_connection, $this->moxa_ip, $this->moxa_port))
                                              {
                                                  if (socket_set_nonblock($this->moxa_connection)) return true;
                                              }
                                          }
                                      }
                                      return false;
                                  }
                                  
                                  function disconnect()
                                  {
                                      if (isset($this->moxa_connection)) socket_close($this->moxa_connection);
                                  }
                                      
                                  function command($cmd)
                                  {
                                      global $id;
                                      logging($id,'Command: '.serialize($cmd));
                                      $command = strtoupper($cmd[0]);
                                      array_shift($cmd);
                                      $value = strtoupper(implode(' ',$cmd));
                                      logging($id,'Value: '.$value);
                                      switch ($command)
                                      {
                                          case "STATUS":
                                              return $this->status();
                                              break;
                                          case "COMMAND":
                                              return $this->sendCmd($value);
                                              break;
                                          case "POWER":
                                              return $this->power($value);
                                              break;
                                          case "POWER_ON":
                                              return $this->powerOn();
                                              break;
                                          case "POWER_OFF":
                                              return $this->powerOff();
                                              break;
                                          case "INPUTSELECT":
                                          case "INPUT":
                                              return $this->inputSelect($value);
                                              break;
                                          case "VOLUMEMUTE":
                                          case "MUTE":
                                              return $this->mute($value);
                                              break;
                                          case "VOLUMEMUTE_ON":
                                          case "MUTE_ON":
                                              return $this->muteOn();
                                              break;
                                          case "VOLUMEMUTE_OFF":
                                          case "MUTE_OFF":
                                              return $this->muteOff();
                                              break;
                                          case "VOLUME":
                                          case "VOLUMECONTROL":
                                              return $this->volume($value);
                                              break;
                                          case "TREBLE":
                                              return $this->treble($value);
                                              break;
                                          case "BASS":
                                              return $this->bass($value);
                                              break;
                                          case "BALANCE":
                                              return $this->balance($value);
                                              break;
                                          default:
                                              return false;
                                              break;
                                      }

                                  }

                                  
                                  function sendCmd($cmd)
                                  {
                                      $cmd .= chr(0x0D);
                                      if ($this->moxa_connection)
                                      {
                                          $i = 0;
                                          do {
                                              $i++;
                                              $res = socket_write($this->moxa_connection,$cmd);
                                              if ($res===FALSE)
                                              {
                                                  $this->disconnect();
                                                  $this->connect();
                                                  $res = socket_write($this->moxa_connection,$cmd);
                                              }

                                              $j = 0;
                                              do {
                                                  $j++;
                                                  usleep(200000);
                                                  $response = $this->readResponse();
                                                  if ($response != FALSE)
                                                  {
                                                      if (count($response)<3) continue;
                                                      $status = substr($response[2],0,2);
                                                      if ($status == "NG") return FALSE;
                                                      else if ($status == "OK")
                                                      {
                                                          $result = substr($response[2],2,2);
                                                          return $result;
                                                      }
                                                      else continue;
                                                  }
                                              } while ($j < 3);
                                          } while ($i < 3);
                                      }
                                      return FALSE;
                                  }

                                  function readResponse()
                                  {
                                      global $id;
                                      if ($this->moxa_connection)
                                      {
                                          $buf = socket_read($this->moxa_connection,8192);
                                          if (strlen($buf) >= 10)
                                          {
                                              // logging($id,'Received Response: '.$buf);
                                              $response = explode(' ',trim($buf));
                                              return $response;
                                          } else return FALSE;
                                      }
                                      return FALSE;
                                  }

                                  function power($status)
                                  {
                                      if ($status=="ON" || $status=="01") return $this->powerOn();
                                      else if ($status=="OFF" || $status=="00") return $this->powerOff();
                                  }

                                  function powerOn()
                                  {
                                      $cmd = "<".$this->ZoneID."PR01";
                                      $result = $this->sendCmd($cmd);
                                      sleep(3);
                                      return $result;
                                  }

                                  function powerOff()
                                  {
                                      $cmd = "<".$this->ZoneID."PR00";
                                      return $this->sendCmd($cmd);
                                  }

                                  function inputSelect($input)
                                  {
                                      $cmd = "<".$this->ZoneID."CH".$input;
                                      return $this->sendCmd($cmd);
                                  }
                                  
                                  function mute($mute)
                                  {
                                      $cmd = "<".$this->ZoneID."MU".$mute;
                                      return $this->sendCmd($cmd);
                                  }

                                  function muteOn()
                                  {
                                      $cmd = "<".$this->ZoneID."MU00";
                                      return $this->sendCmd($cmd);
                                  }

                                  function muteOff()
                                  {
                                      $cmd = "<".$this->ZoneID."MU01";
                                      return $this->sendCmd($cmd);
                                  }

                                  function volume($vol) // 0-38
                                  {
                                      $cmd = "<".$this->ZoneID."VO".$vol;
                                      return $this->sendCmd($cmd);
                                  }

                                  function treble($treble) // 0-14
                                  {
                                      $cmd = "<".$this->ZoneID."TR".$treble;
                                      return $this->sendCmd($cmd);
                                  }

                                  function bass($bass) // 0-14
                                  {
                                      $cmd = "<".$this->ZoneID."BS".$bass;
                                      return $this->sendCmd($cmd);
                                  }

                                  function balance($balance) // 0-20
                                  {
                                      $cmd = "<".$this->ZoneID."BL".$balance;
                                      return $this->sendCmd($cmd);
                                  }

                                  function status()
                                  {
                                      global $id;
                                      static $lastPower = false,
                                             $lastInputSelect = false,
                                             $lastVolumeMute = false,
                                             $lastVolumeControl = false,
                                             $lastTreble = false,
                                             $lastBass = false,
                                             $lastBalance = false;
                                             
                                      $power = (int) $this->sendCmd("?".$this->ZoneID."PR");
                                      if ($power !== $lastPower)
                                      {
                                          setLogicLinkAusgang($id,3,strval($power));
                                          $lastPower = $power;
                                          if ($power == 0)
                                          {
                                              // change all other ouputs to -1
                                              setLogicLinkAusgang($id,4,-1);
                                              setLogicLinkAusgang($id,5,-1);
                                              setLogicLinkAusgang($id,6,-1);
                                              setLogicLinkAusgang($id,7,-1);
                                              setLogicLinkAusgang($id,8,-1);
                                              setLogicLinkAusgang($id,9,-1);
                                              $lastInputSelect = $lastVolumeMute = $lastVolumeControl =
                                              $lastTreble = $lastBass = $lastBalance = false;
                                          }
                                      }

                                      if ($power == 1)  // only retrieve further attributes when Monoprice is switched on
                                      {
                                          $inputSelect = (int) $this->sendCmd("?".$this->ZoneID."CH");
                                          if ($inputSelect !== $lastInputSelect)
                                          {
                                              setLogicLinkAusgang($id,4,$inputSelect);
                                              $lastInputSelect = $inputSelect;
                                          }
                                          
                                          $volumeMute = (int) $this->sendCmd("?".$this->ZoneID."MU");
                                          if ($volumeMute !== $lastVolumeMute)
                                          {
                                              setLogicLinkAusgang($id,5,$volumeMute);
                                              $lastVolumeMute = $volumeMute;
                                          }
                                              
                                          $volumeControl = (int) $this->sendCmd("?".$this->ZoneID."VO");
                                          if ($volumeControl !== $lastVolumeControl)
                                          {
                                              setLogicLinkAusgang($id,6,$volumeControl);
                                              $lastVolumeControl = $volumeControl;
                                          }

                                          $treble = (int) $this->sendCmd("?".$this->ZoneID."TR");
                                          if ($treble !== $lastTreble)
                                          {
                                               setLogicLinkAusgang($id,7,$treble);
                                               $lastTreble = $treble;
                                          }
                                          
                                          $bass = (int) $this->sendCmd("?".$this->ZoneID."BS");
                                          if ($bass !== $lastBass)
                                          {
                                               setLogicLinkAusgang($id,8,$bass);
                                               $lastBass = $bass;
                                          }
                                          
                                          $balance = (int) $this->sendCmd("?".$this->ZoneID."BL");
                                          if ($balance !== $lastBalance)
                                          {
                                               setLogicLinkAusgang($id,9,$balance);
                                               $lastBalance = $balance;
                                          }
                                      }
                                      return TRUE;
                                  }
                                  
                              }

                              ?>
                              ###[/EXEC]###



                              Die Kommandos für die Abfrage sind ja ganz unten und werden nur abgefragt wenn "Power == 1". Soweit so gut.
                              Aber wo findet die Auswertung statt?
                              Hier?

                              PHP-Code:
                                              $j 0;
                                              do {
                                                  
                              $j++;
                                                  
                              usleep(200000);
                                                  
                              $response $this->readResponse();
                                                  if (
                              $response != FALSE)
                                                  {
                                                      if (
                              count($response)<3) continue;
                                                      
                              $status substr($response[2],0,2);
                                                      if (
                              $status == "NG") return FALSE;
                                                      else if (
                              $status == "OK")
                                                      {
                                                          
                              $result substr($response[2],2,2);
                                                          return 
                              $result;
                                                      }
                                                      else continue;
                                                  }
                                              } while (
                              $j 3);
                                          } while (
                              $i 3);
                                      }
                                      return 
                              FALSE;
                                  }

                                  function 
                              readResponse()
                                  {
                                      global 
                              $id;
                                      if (
                              $this->moxa_connection)
                                      {
                                          
                              $buf socket_read($this->moxa_connection,8192);
                                          if (
                              strlen($buf) >= 10)
                                          {
                                              
                              // logging($id,'Received Response: '.$buf);
                                              
                              $response explode(' ',trim($buf));
                                              return 
                              $response;
                                          } else return 
                              FALSE;
                                      }
                                      return 
                              FALSE;
                                  }

                                  function 
                              power($status)
                                  {
                                      if (
                              $status=="ON" || $status=="01") return $this->powerOn();
                                      else if (
                              $status=="OFF" || $status=="00") return $this->powerOff();
                                  } 

                              Ich nehm mal an, dass des wenn beim LG-TV ein "OK" in der Antwort auf die Statusabfrage steht, dieser dann einen Wert zurückliefert.
                              Und bei "NG" eben ein "FALSE".


                              Hab mir das jetzt beim Monoprice so vorgestellt:

                              Wenn ein ">" zurück kommt bei einer Statusabfrage (z.B. bei "?11PR") dann les den Wert aus, z.B. bei dieser Rückmeldung >11PR01. In dem Fall die 01 ganz hinten im Befehl die sagt ob Monoprice an.
                              Oder wenn "Command Error" dann eben ein "FALSE".

                              Soviel zur Theroie, bloß in der Umsetzung harperts . Denk man muss doch auch irgenwie festlegen welchen Wert der LBS als Rückmeldung verwendet, also wie im Beispiel oben die "01" an letzter Stelle.
                              Sonst weiß er ja nict welchen Wert er zurück liefern soll.

                              Richtig?
                              Aber wie ich das festleg, puh gar nicht so einfach...
                              Gruß Ben

                              Kommentar


                                #45
                                Naja du müsstest grundsätzlich ja schon unterscheiden, was der send Command war, da ja die Status Abfrage bei dem Monoprice individuell ist.

                                D.h. du müsstest der readResponse function den ursprünglich gesendeten Command mitgeben und dort jeweils die entsprechende Statusabfrage formulieren und dann auch entsprechend der zu erwartenden Antwort individuell reagieren.
                                Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                                Kommentar

                                Lädt...
                                X