IPSModule base class

Hi IPS developers

I am trying to get a better understanding of how IPS works (and what can be done) while learning oop php.

I am trying get to a point where I can write a module of my own, while studying the module.php file I see that new class derives from IPSModule (extends IPSModule).

Where can I find more information about IPSModule? What methods dose it have? Dose it have a parent class? Etc.

E.g. can I get more fine-grained control of I/O Instances Client Socket? In my case I would want blocking to be an option when I use Client Socket to send.

Thanks in advance

yoggi

The methods from IPSModule are described in the PHP SDK documentation
If you have further questions how to use a special method don‘t hesitate to ask.

Hi Fonzo,

I wasn’t sure if you where working for Symcon or if you are a very dedicated user, I am guessing that you work for Symcon.

Thanks for pointing me in the right direction regarding the documentation.

Where is the code for the class IPSModule located (where in the IPS installation is the file located), can I have look at it?

Can the I/O Instances Client Socket object be controlled in a more fine-grained manner? Can it be set to work in a blocking mode (I am assuming it is using php socket)?

yoggi

Yes I am just a user who is working with the software IP-Symcon as many other experienced users for quite a few years now. You can indentify an IPS Delevoper writing things in the forum, near the user name is signed IPS-Developer for example Dr. Niels or Pio are sometimes writing in the forum, say can be identified as employees from IP-Symcon.

I personally don‘t know but I think the code is inside IP-Symcon. Perhaps someone more experienced or an employee from IP-Symcon can answer this better.

Perhaps Nall-Chan or paresy or anybody can give you here more advice.

  1. The sourcecode is unavailable. Is there anything that the documentation of the functions is lacking in particular?
  2. No. IP-Symcon’s dataflow is fully event driven. You will need to create a splitter, which will collect data-packets. Did you already have a look at our SymconTest GitHub repository?

paresy

Hi Paresy,

Regarding the documentation lacking or not, being a new beginner I am at a disadvantage and it would help if the explanations and code examples provided in the documentation where a bit more verbose.

I have looked at a lot of modules including your SymconTest GitHub repository but I haven’t found a good starting of example. I have also bein helped by users in the forum but sometimes the advice given have come across as being conflicting regarding the need for a splitter or not (at least to me). Do you have a particular module in mind for me to look at?

How is the work with translating the dokumentation going? I ask as I use google to translate between German an English and sometimes the meaning gets lost.

yoggi

We are here to help :slight_smile: I was just trying to find out what type of module you want to build. If you want some synchronization of the data flow, you definitely need a splitter. Because propably you want multiple device instances behind the Splitter.

paresy

He wants to send commands to an aquos tv and receive the state of the tv, until now he worked with a register variable and a cutter. Now he would like to do the same with a module.

Then I think no splitter is needed.

paresy

The topic where he needs help is he wants to send a command and then wait for the response. Until the response is there he wants ip-symcon to stop sending any further commands. I think he needs an example how to do this.

If yes, should it?

In my class I have a private property named $isSending that start out as false. I then call PowerOn() from form.json ({ „type“: „Button“, „label“: „Power On“, „onClick“: „Aquos_PowerOn($id)“ }).

public function PowerOn()
{
.   $this->SendToIO("POWR1");
}

When I enter method SendToIO(string $payload) I test if $isSending is false, if it is I send the command and set $isSending to true (to disable send until reply is received back).

When I receive data back on ReceiveData I set $isSending to false.

I can see that $isSending is set to true when the command is sent out and that it gets set to false when reply is received back on ReceiveData.

The problem I have is if I press the power on button more then once, more commands are sent out despite the $isSending is set to true. To me it appears that a new object is created every time the button is pressed.

Am I wrong to think that it should be the same object I am taking to?

I guess I am just confused.

yoggi

You have to enter a semaphore if you want to wait for the state is received.

Try something like this:


/################# SEMAPHOREN Helper  - private

    private function lock($ident)
    {
        for ($i = 0; $i < 10; $i++) {
            if (IPS_SemaphoreEnter('AQUOSTV_'.(string) $this->InstanceID.(string) $ident, 1000)) {
                return true;
            } else {
                IPS_Sleep(mt_rand(1, 5));
            }
        }

        return false;
    }

    private function unlock($ident)
    {
        IPS_SemaphoreLeave('AQUOSTV_'.(string) $this->InstanceID.(string) $ident);
    }


If you send a command you have to check if look is true, if not you can send otherwise enter the semaphore


   // set Semaphore 
            if ($this->lock('POWERON')) {
                // send data
                try {
                    $this->SendToIO("POWR1");
                } catch (Exception $exc) {
                    // could not send
                    $this->unlock('POWERON');

                    throw new Exception($exc);
                }
                $this->unlock('POWERON');
            } else {
                $msg = 'Can not set lock \'POWERON\'';
                echo $msg.PHP_EOL;

                throw new Exception($msg, E_USER_NOTICE);
            }

Hi Fonzo,

Thanks for the code example and the help in general. I will have a good look at the semaphore.

But I am trying to understand how IPS classes and object works vs normal OOP in PHP. At the moment I am trying to brush up on my understanding by reading a good four part serie about PHP OOP.

What I don’t understand is the instantiation of objects in IPS. Normally instantiation of an object looks like this $member = new Member(), but in IPS I have no control of the instantiation of objects (at least to my knowledge).

<?php 
 
class Member
{
  // property, method etc.
}
 
$member = new Member();
 
?>

And then I can use the $member to call methods of the object. I can reuse my object but from what I can see with IPS I get more then one object for my module each time I pressa a button in my module.

Anny chans you could shed some light on this and the inner workings of IPS?!

yoggi

You could say the instance in IP-Symcon is the object created from the class. So you can have many instances, but every instance has different properties. Instead of using a constructor the instance (object) is setup in the Create Part of the module. The properties of every instance (object) are stored from IP-Symcon. If you start the service from IP-Symcon all instances (objects) are created from your php module (class) with the stored properties from every instance.

The $member in this case the instance created by IP-Symcon, that is your object that you can really see. A user can use a public method with your object (instance). The part with the buttons I don’t understand, perhaps you can explain that a little more. A button is calling a public method you can call the public method as often as you like.