• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    REGEX with Serial Input Data Point

    User help
    2
    9
    2.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thutchisT
      thutchis
      last edited by

      In my lab I periodically run a moisture test on the germination and kilning of the malt. I use a moisture balance that outputs the test results as ASCII text on a RS232 serial port. I need some help extracting the moisture value from the output strings to enter as a data point.

      The output looks like this:

      ***** AUTO STOP *****
      LAST TEMP: 131 C
      FINAL MASS: 12.215 g
      TEST TIME: 56:15
      MASS LOST: 8.531 g
      RESULT: 41.12 %M
      ----------------------------- (the dashes are mine)
      I need to extract just the value (in this case 41.12) from the "RESULT:" line using REGEX. I am NOT very good with regular expressions and have been pulling my hair out all morning. The best I have come up with is: "/RESULT:\s*([\d][\d].[\d][\d])\s%M*/g" but that selects the entire line, not just the value. Any help would be very appreciated.

      Craft Malt from the Ground Up

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by phildunlap

        Hi thutchis,

        You are using a serial data source?

        It sounds like if you used a value index of 1 instead of 0 you should be extracting your value, currently. You don't need to use the /.../g type format to input the regex, you can enter what would come between the slashes for the serial data source fields.

        I always encourage people to do their troubleshooting using a setup that will catch all the values, for your data, that might mean something like...

        DATA SOURCE:
        Use terminator: No
        Message Regex: ()[^;]+
        Point Identifier Group: 1
        Configuration in Hex: No

        DATA POINT:
        Data Type: Alphanumeric
        Point Identifier:
        Value Group: 0
        Value Regex [^;]+

        I am using [^;]+ because you do not have any semicolons in your example data, so it will match everything. You could probably get the specific value you're looking for with a serial data point setup on that data source like,

        DATA POINT:
        Data Type: Alphanumeric
        Point Identifier:
        Value Group: 1
        Value Regex [^;]+RESULT: (\d+\.?\d*) %M.*
        
        1 Reply Last reply Reply Quote 0
        • thutchisT
          thutchis
          last edited by

          Thanks Phil,
          Yes, I plan to use a Serial Data Source.

          I am using a Regex tester at: https://regexr.com/ to work out the correct syntax for getting my desired value into a data point. If I put your suggestion, " [^;]+RESULT: (\d+.?\d*) %M.* " in the tester it shows "no match". I would assume the Mango REGEX parser would perform the same.

          Craft Malt from the Ground Up

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            Hmm, that is not my experience with that website:
            0_1515014650954_myRegexWorks.png

            Perhaps it is from the extra spaces inside your quote marks?

            1 Reply Last reply Reply Quote 0
            • thutchisT
              thutchis
              last edited by

              @phildunlap said in REGEX with Serial Input Data Point:

              [^;]+

              Strange, I didn't use the spaces after/before the double quotes, they was only to indicate the quotes were not included in the expression I was trying to convey to the reader. But I still don't get a match. Your screen shot shows the entire message was matched, not just the value between "RESULT:" and "%M".

              Craft Malt from the Ground Up

              1 Reply Last reply Reply Quote 0
              • phildunlapP
                phildunlap
                last edited by phildunlap

                It shows that value was extracted as group #1, which would be the value group index in Mango.

                It looks like I was supposed to have written (\d+\.?\d*) but the \ before the dot was removed the forum's formatting, and so I didn't copy it into the image. But, it would work either way.

                1 Reply Last reply Reply Quote 0
                • thutchisT
                  thutchis
                  last edited by thutchis

                  I was able to get the REGEX tester to duplicate your results and got the value as group 1.

                  Thanks for your help today, I learned a lot. I plan to connect the serial data source to the Mango server tomorrow. I'll see what happens then.

                  Tom

                  Craft Malt from the Ground Up

                  1 Reply Last reply Reply Quote 0
                  • thutchisT
                    thutchis
                    last edited by thutchis

                    I connected the moisture balance as a serial data source and it works. I get the percent moisture value as an alpha-numeric which is fine for logging. I don't need any charting. I changed the Regex to include "%M" so a unit is displayed when looking at point details.

                    The data source (moisture balance RS232) sends a 0x04 (EOT End Of Transmission) at the end of each message. If I try to use a terminator string of 0x04 it won't work. If I ignore the terminator it does work, so no big deal. Just curious why I cant use the hex value 0x04 as a terminator. Is there another encoding that would work?

                    Now I need to figure out how to have the result emailed to me when the data point is logged.
                    Tom

                    Craft Malt from the Ground Up

                    1 Reply Last reply Reply Quote 0
                    • phildunlapP
                      phildunlap
                      last edited by

                      Hi Tom,

                      At the bottom of the edit point page is a section for event detectors. You're either looking for a Change or Update detector. After the event detector is created, you will need to create an Email event handler on the /event_handlers.shtm page for the event, and you will need to configure your SMTP server in the system settings.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post