Ankündigung

Einklappen
Keine Ankündigung bisher.

Python

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

    HS/FS Python

    Hello all.
    I'm using a Gira HS3 for which I've made some logic modules.
    They all work well but one of them is creating exceptions in the debug list.
    It's a module I use to output temperatures sent by Mobotix cameras as a Float and as a string.
    The temperature is a string with a fixed length of 5 characters starting with the + or - sign.
    If the absolute value of the temperature is smaller than 10 the second character is a space.
    For example:
    +13.4
    + 4.7
    -12.7
    - 2.3
    28.03.2018 22:15:42 (1)
    File "./../hssrc/hs_logik.py", line 232, in calc
    File "formula", line 1, in [module]
    ValueError: invalid literal for float(): ----
    [5012L, 10032L, 0L, "(EN[2][:1])=='-'", 'float(EN[2][-4:])', '', 0L, 0L, 1L, 0L]
    28.03.2018 22:15:42 (2)
    File "./../hssrc/hs_logik.py", line 232, in calc
    File "formula", line 1, in [module]
    ValueError: invalid literal for float(): ----
    [5012L, 10032L, 0L, "(EN[3][:1])=='-'", 'float(EN[3][-4:])', '', 0L, 0L, 2L, 0L]
    The formula looks like this:
    5012|0|"(EN[2][:1])=='+'" |"float(EN[2][-4:])" |""|0|0|1|0 # temp postive and >= +10
    5012|0|"(EN[2][:1])=='+ '"|"float(EN[2][-3:])" |""|0|0|1|0 # temp postive and < +10
    5012|0|"(EN[2][:1])=='-'" |"0-float(EN[2][-4:])"|""|0|0|1|0 # temp negative and <= -10
    5012|0|"(EN[2][:1])=='- '"|"0-float(EN[2][-3:])"|""|0|0|1|0 # temp negative and > -10
    Anybody who could tell me what's wrong with my formula?
    Danke!
    Zuletzt geändert von 747driver; 29.03.2018, 10:30. Grund: Changed 12.7 into -12.7

    #2
    The quotes seem to be unbalanced (? -- I'm not a python expert)

    5012|0|"(EN[2][:1])=='+'" |"float(EN[2][-4:])" |""|0|0|1|0 # temp postive and >= +10
    5012|0|"(EN[2][:1])=='+ '"|"float(EN[2][-3:])" |""|0|0|1|0 # temp postive and < +10
    5012|0|"(EN[2][:1])=='-'" |"0-float(EN[2][-4:])"|""|0|0|1|0 # temp negative and <= -10
    5012|0|"(EN[2][:1])=='- '"|"0-float(EN[2][-3:])"|""|0|0|1|0 # temp negative and > -10
    Zuletzt geändert von EIBaer; 29.03.2018, 07:03.
    Doch, das ist lösbar :-)
    Die Mutter ist 21 Jahre älter als ihre Tochter und wird in 6 Jahren fünfmal so alt sein. Wo ist der Vater?

    Kommentar


      #3
      Thanks EIBaer but I think you forgot the first quote.
      Zitat von EIBaer Beitrag anzeigen
      5012|0|"(EN[2][:1])=='+'" |"float(EN[2][-4:])" |""|0|0|1|0 # temp postive and >= +10
      When I change the minus sign into a plus sign (in the condition) the outcome is incorrect but the debug list does not show any exceptions anymore...

      Kommentar


        #4
        Could you avoid the problem by stripping the blank of your input value before you convert the string to a float? I would think that you then only need a single conversion to float formula line.
        Although I use python, I have not used it to build these custom modules. What looks odd to me is the '1:' in all lines, I would think that the second and fourth formula lines would need a '2:', as you are looking at two positions. Also, is the 0-float a custom instruction?
        Bram

        Kommentar


          #5
          I think you are right Bram, I will strip the blank in the string first.
          The :1 in the 2nd and 4th is incorrect indeed, should be 2:
          With "0-float(EN[2][-4:])" I substract the float from 0 (zero) to get a negative value.
          The idea was to output each temperature as a number and as a string.
          In case the temperature is positive the string should not start with a plus sign.
          When the temperature is negative it should start with the minus sogn of course.
          Will change the module, test and report back.

          Kommentar


            #6
            Ah, OK, now I understand the 0-float part.
            If you make the change you likely do not need to worry about this, but I cannot figure out the logic of the formula lines. The first (and third) line looks at the first character. It would find a match both for '+12.5' and for '+ 2.5'. So by just testing the first line you cannot guarantee that the outcome is >10. Or will the module always calculate all four lines and therefore the last match always counts?

            Kommentar


              #7
              Correct, the last match will count.

              Kommentar


                #8
                Thanks to your input I managed to reduce the code per temperature from 4 to just 1 line.
                Code:
                5012|0|""|"float((EN[2]).replace(' ',''))"        |""|0|0|1|0
                As I can change the temperature offset on the admin page of the Mobotix camera I could test positive/negative and single/double digit temperatures and they all show correct.
                For some reason I still get an exeption:
                Code:
                 [TABLE="align: center, border: 0, cellpadding: 3, cellspacing: 1"]
                [TR="bgcolor: #CCCCFF"]
                [TD][B]29.03.2018 12:55:41 (1)[/B]
                			File "./../hssrc/hs_logik.py", line 232, in calc
                			File "formula", line 1, in [module]
                			ValueError: invalid literal for float(): ----
                			[5012L, 10032L, 0L, '', "float((EN[2]).replace(' ',''))", '', 0L, 0L, 1L, 0L][/TD]
                 		[/TR]
                [/TABLE]
                Zuletzt geändert von 747driver; 29.03.2018, 12:20.

                Kommentar


                  #9
                  Based on what you saw earlier, the exception probably showed up with a minus temperature value. You may want to clear the debug page by rebooting, and then send a temperature value, check the exception list, send the next type, etc so that you know exactly which type of string triggers the error. To allow more troubleshooting you can add an internal KO so you can send different string values using EIB-Monitor.
                  The python error indicates there is an unrecognized character in the string to be converted. I would first look at EIBMON to see what the Mobotix really sends. If that looks right, I would let the Mobotix send to a 'normal' python script, running on a Raspberry, PC or whatever. Then let it print out the ascii code of each character received (and are there only 5?). Keep in mind that when you see the Mobotix input directly on a screen, it may show as a minus sign or a blank, but it could well be that another ascii code is used than 32 or 45.

                  Kommentar


                    #10
                    Every time I change something in the module I have to restart HS Expert so it will load the changed module.
                    Then I upload the project to the HS3 and it will restart after about 4 minutes clearing the exception in the hslist debug page.
                    Wish there was a possibility to test logic modules with a separate program...
                    Anyway, to be honest I do not even know anymore what I changed but right now the HS3 has been running for some time without any exceptions!
                    These are the 2 lines per temperature I have outputting the temperature as a float and as a string.

                    Code:
                    5012|0|"EC[2]"|"float((EN[2]).replace(' ',''))"         |""|1|0|1|0    # Temp1 as float
                    5012|0|"EC[2]"|"('%.1f' % SN[1]).replace('.',',')+EN[1]"|""|2|0|0|0    # Temp1 as string/text including unit
                    Thanks!!

                    Kommentar


                      #11
                      747driver you know this? https://knx-user-forum.de/forum/öffe...r-und-debugger

                      Kommentar


                        #12
                        Thanks, interesting.
                        I'll have a look at it.

                        Kommentar

                        Lädt...
                        X