Ankündigung

Einklappen
Keine Ankündigung bisher.

Python syntax

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

    HS/FS Python syntax

    Hi,

    I'l having a problem with the logical "AND" in the conditional part of the Python expression.

    Code:
    5012|0|"(EN[9] & 1)"|"EN[1]"|""|1|0|0|0
    5012|0|"(EN[9] & 2)"|"EN[2]"|""|2|0|0|0
    I'm trying to do a bit wise test on a 8 bit status byte (0-255).
    If the input value EN[9] = 3 and I do a logical "AND" with 1, the result should be non-zero (i.e. 1 in this case) and the formula should be executed. Right ?

    If the input value EN[9] = 3 and I do a logical "AND" with 4 (or 8 or 16 or 32 or 64 or 128), the result should be zero (i.e. 0 in this case) and the formula should not be executed. Right ?

    If I "force" the condition to 1, the formula works as expected, so I'm pretty sure I've a mistake with the "AND" in the condition, maybe a syntax problem ?

    I wonder if it is allowed to have an "AND" in the condition, at all ?
    According to the doc, yes, as long as the result is of type boolean 0-non zero.
    NB: the "AND" in the formula part of the expression works fine.

    Any hint ?

    #2
    Hey Raymond!

    I had this problem before while developing my Rolladen-Baustein.
    The solution which worked for me is:
    "((EN[9] & 1)==1)" to test if bit 1 is set
    "((EN[9] & 2)==2)" to test if bit 2 is set
    "((EN[9] & 4)==4)" to test if bit 4 is set
    and so on.

    That worked for me without any problems after I first tried it in the same way as you did...
    Gruß, Marc

    Kommentar


      #3
      Zitat von MarcNaroska Beitrag anzeigen
      The solution which worked for me is:
      "((EN[9] & 1)==1)" to test if bit 1 is set
      "((EN[9] & 2)==2)" to test if bit 2 is set
      "((EN[9] & 4)==4)" to test if bit 4 is set
      Hé, hé
      Thank for the tip . Will try it asap

      Zitat von MarcNaroska Beitrag anzeigen
      That worked for me without any problems after I first tried it in the same way as you did...
      The same cause often yields the same result

      Another question, about the variables EN and EC
      Code:
      EN Array The current value of the inputs.
      EC Array of Boolean
        1 == A telegramm has been received at the input.
      I don't see the subtle difference.
      A word of explanation is welcome.

      Thank you very much.

      Kommentar


        #4
        Hi Raymond,

        EC[m] tells you, that the logic module has been triggered by a telegramm arriving at pin number m, and
        EN[m] tells you the value of the telegramm.

        Greetinx!
        Gruß, Rainer

        Kommentar


          #5
          Zitat von Taxus Beitrag anzeigen
          EC[m] tells you, that the logic module has been triggered by a telegramm arriving at pin number m, and
          EN[m] tells you the value of the telegramm.
          ûh
          Still confused
          Can you tell me when to use the one or the other ?

          Maybe it's more appropriate to use EC[m] for variable inputs ? as it does 2 things at a time: it says:
          1) a telegramm has arrived at pin number m
          2) the value of that telegramm

          Is that correct ?

          Kommentar


            #6
            No, it is not.

            Example:

            EC[1]| EN[2] + en[3] | |..|4

            This says:

            If you have a telegramm on pin 1 (maybe a minute trigger), then send the sum of EN 2 and EN 3 to outpu no. 4

            EC does not contain the value of the input pin! It only says that there was a new telgramm on that input pin.
            Gruß Matthias
            EIB übersetzt meine Frau mit "Ehepaar Ist Beschäftigt"
            - PN nur für PERSÖNLICHES!

            Kommentar


              #7
              Zitat von MatthiasS Beitrag anzeigen
              EC does not contain the value of the input pin! It only says that there was a new telgramm on that input pin.
              Thank you very much.
              By looking at the existing examples, I see that EC is often used in the conditional part of the expression.

              PS:
              Isn't the behaviour of the "AND" in the condition, a bit disturbing ?

              Kommentar


                #8
                Hi Marc,

                Zitat von MarcNaroska Beitrag anzeigen
                The solution which worked for me is:
                "((EN[9] & 1)==1)" to test if bit 1 is set
                I'm unable to make these lines work
                Code:
                5012|0|"((EN[9] & 1)==1)"|"EN[1]"|""|1|0|0|0
                5012|0|"((EN[9] & 2)==2)"|"EN[2]"|""|2|0|0|0
                Seems to be the same as yours, at least about the condition.
                Again, when I force the condition, like this,
                Code:
                5012|0|""|"EN[1]"|""|1|0|0|0
                it works. So, it has to do with the condition.
                I guess I missed something.
                Any clue ?

                Kommentar


                  #9
                  Sorry for asking that - you have at least 9 input-pins?
                  Gruß, Rainer

                  Kommentar


                    #10
                    To your primary question: please use

                    5012|0|"((int(EN[9]) & 1)==1)"|"EN[1]"|""|1|0|0|0
                    Gruß, Rainer

                    Kommentar


                      #11
                      And another thing, in the unlikely case you don't do this already: install python idle shell for testing. I made myself a simple textfile to paste values for EN[x] and EC[x] for testing..

                      Makki
                      EIB/KNX & WireGate & HS3, Russound,mpd,vdr,DM8000, DALI, DMX
                      -> Bitte KEINE PNs!

                      Kommentar


                        #12
                        Zitat von Taxus Beitrag anzeigen
                        you have at least 9 input-pins?
                        Yes. Anyway, the Experte would complain if the number of declared inputs doesn't match.
                        I want to translate a status byte into the clear text equivalent of each status bit set to 1 (see picture below).
                        At input Pin 9, I get the unknown status, Byte, 0-255
                        At input Pins 1-8, I fil-in the meaning of each bit, static 14Byte text
                        At output Pins 1-8, I collect the clear text, according to the bits set in the status byte. Rather simple, no ?

                        Zitat von Taxus Beitrag anzeigen
                        5012|0|"((int(EN[9]) & 1)==1)"|"EN[1]"|""|1|0|0|0
                        I thought about it for a while, but I'm pretty sure it's an integer. Maybe I should cast it to force the type integer ? But why ? it has been declared as type integer.

                        Zitat von makki Beitrag anzeigen
                        in the unlikely case you don't do this already:
                        Bingo !

                        Zitat von makki Beitrag anzeigen
                        install python idle shell for testing.
                        Sounds very interesting, this tool for chasing the
                        Maybe a pointer to it ?
                        I was already looking for a tools to easy a bit the Python writing, didn't find any compatible with the situation at hand.

                        Thank you.
                        Angehängte Dateien

                        Kommentar


                          #13
                          Zitat von Taxus Beitrag anzeigen
                          please use

                          5012|0|"((int(EN[9]) & 1)==1)"|"EN[1]"|""|1|0|0|0
                          Mmm, you are right.
                          It works
                          Still confused, why casting an integer that is already declared as an integer, 0-255 ?
                          I guess this is a lesson from experience ?

                          Thank you

                          Kommentar


                            #14
                            Hey Raymond!

                            As far as I know you only define inputs and outputs of a Baustein as numerical or alphanumerical. Maybe all numerical variables are internally declared as double...

                            I'm sorry for my last post where I forgot the INT(), but I didn't had a look into my Baustein where I used this and wrote it just from memory...

                            Nevertheless, as long as it works now, don't worry about the why...
                            Gruß, Marc

                            Kommentar


                              #15
                              Zitat von MarcNaroska Beitrag anzeigen
                              As far as I know you only define inputs and outputs of a Baustein as numerical or alphanumerical.
                              That's perfectly correct
                              But I was referring to the
                              Experte/Stammdaten/Kommunikationsobjekte/Intern
                              and there, the "Status byte" is defined as "8-Bit (0..255/EIS 2,6)". Isn't that an integer ?. Also, the title of the line is "Datentyp", sooo

                              Zitat von MarcNaroska Beitrag anzeigen
                              I'm sorry for my last post where I forgot the INT()
                              No problem . Thank you for the kind help, anyway.

                              Zitat von MarcNaroska Beitrag anzeigen
                              Nevertheless, as long as it works now, don't worry about the why...
                              Oh well, I've a strong tendency to worry a bit and I'm willing to gain some experience with this #@$& stuff.
                              Someone said:
                              Experience is the sum of all errors
                              Well, I'm collecting a terrific amount of experience these days

                              Kommentar

                              Lädt...
                              X