This topic contains 3 replies, has 2 voices, and was last updated by  John 6 years, 6 months ago. This post has been viewed 1483 times

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #20043

    John
    Keymaster

      There’s been a long time since I emailed you guys with a technical question. Our program has been working really well, but now that we are trying to add a couple of things, we got stuck with a couple of issues.

      - Is it possible to do a ‘Case Switch’ or something similar, that isn’t an IF STATEMENT or a TERNARY OPERATOR??

      - Is there a way to do a FOR LOOP???

      I’m dealing with ASCII characters, I would like to write the word “HELLO”, and in one variable store its ASCII equivalent, “72,101,108,108,111″, so I know that ‘str[n]‘, gives you the unicode value or the ASCII 7-Bit equivalent of ‘n’ indexed position of that particular string, but I would like to get the whole word, not only one character, and store it in one variable.

      Thanks for your help!!

      #20044

      John
      Keymaster

        With a ternary operator you can chain conditions as it they were a switch statement, like this:

        condition1?result1:condition2?result2:condition3?result3:defaultResult

        This works because the associativity on this operator is right to left. Of course on each condition expression you must include an explicit comparison operator (as opposed to a switch statement)

        Loops are not currently supported for the expressions engine.

        Depending on what you need to do there may be still a way to obtain what you want. With the ‘split’ method you can obtain an array where each element is a character, for example if you do

        “HELLO”.split(“”)

        you will obtain the following array in a single variable

        ["H","E","L","L","O"]

        The opposite is also possible with the ‘join’ method, so maybe you can use these methods to the effect of what you want.

        Said that, I certainly do not understand well what your requirement is, so if you could elaborate a bit further I may be able to help a bit more, or propose a solution if available.

        Thanks.

        #20045

        admin
        Keymaster

          Thanks a lot for your help. Knowing that about the ternary operator is really helpful, I’ll give it a go.

          What I am trying to do is saving a name into a PLC, but as far as I know, PLC’s don’t support strings or something similar to that, so suppose I have a normal line in ScadaMobile, where you enter a name:

          Name………… TEST

          I want to split this and get “T”,”E”,”S”,”T”, which I already did, then I want to assign every character an HR number, then get the ASCII conversion of those letters and send it to the PLC for storing or saving purposes, then bring it back, and get the letters again and display it through several pages in ScadaMobile…this might be a little confusing, it is one of those things that requires you to know the whole process and the system we use, but I believe with this help, I’m able to play around with it, and see if I can get the output I want.

          Thanks a lot for your help…whenever I’m done with this assignment, I’ll let you know what I did, or maybe ask something else!!

          Thanks again,

          Have a great weekend,

          #20046

          John
          Keymaster

            What you want to do is indeed far easier than you think. Some PLCs may not explicitly support strings but we can still store anything in registers provided we are consistent across reads and writes. So in this case you can just use a raw char representation (see “Representation of Character Strings in PLCs” in the manual).

            Basically you use CHAR(n) for the data type (Column B). ScadaMobile will use the required registers to store the characters. ‘n’ must be a explicit number indicating the number of bytes (or characters if they are ascii) allocated in the PLC. For example CHAR(10) will allocate a 10 character string and will use 5 HR registers because each register is 2 bytes. For the purposes of the expressions engine the variable name you use on column A will be a string, so you can use it as such in your expressions. If you really need each character in a single PLC register then maybe you can do operations in the PLC program to pack/unpack them.

            I hope this helps.

            Thanks,

          Viewing 4 posts - 1 through 4 (of 4 total)

          You must be logged in to reply to this topic.

          Copyright © SweetWilliam, S.L 2009-2013. All rights reserved.
          Science and Technology Park of the University of Girona, Emili Grahit, 91 (NarcĂ­s Monturiol building, Office P3-B03) 17003-Girona. Phone +34972183244