Showing results 1 to 9 of 9

Thread: Need some help for two simple things

  1. #1
    Join Date
    11.10.2017
    Posts
    5

    Frage Need some help for two simple things

    Hi,

    I inherited a Zenon project and have to add a new PLC and some new functionality to it.
    System is Zenon Supervizor Version 7.60 SP0 Build39532, PLC is Festo CPX-CEC-C1-V3 (Codesys 3), so I'm using the Codesys driver (3S v3 driver for PLC handler).

    What I can't figure out is the following:

    1. How to set a PLC variable by clicking a button?
    Say I have the variable PLC1.word1
    I want to have several buttons which set this variable to different hardcoded values - for example when Button1 is click, PLC1.word1 becomes 105, when Button2 is clicked PLC1.word1 becomes 1001 etc. The user should not see the variable value, nor any dialogs.
    Can't find any way to do that. In the buttons Properties, the Variable field is grey(Inactive).

    2. How to change the color of a screen object, e.g. a circle, depending on the value of a specific bit from an integer variable?
    For example if bit#5 of PLC1.word1 is False - the circle should be green. If bit#5 of PLC1.word1 is True - the circle should be red.

    Thanks for any suggestions.
    Best regards,
    Peter
    Last edited by peternn : 25th September 2018 at 13:55

  2. #
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    801
    Best Answer

    Default Re: Need some help for two simple things

    and in your macro you have forgotten to call the event at the end, last line shall be: obElem.LeftClickDown

  3. #2
    Join Date
    02.05.2017
    Posts
    26

    Default Re: Need some help for two simple things

    Hello,

    1.
    • Create a new function of the type "Write/modify set value"
    • Select the corresponding variable and the desired value in the creation dialog
    • Check "Direct to hardware"
    • Confirm and link the function to the button

    2.
    • Easiest way is to create a reaction matrix and inside of the rema configuration to set the corresponding limit value color for the desired bits
    • Link the reaction matrix to a variable (under LimitValue Properties) and link the "Dynamic fill color" of the circle (or whatever) to that variable


    Regards
    Lukas
    Last edited by LukasRotter : 25th September 2018 at 14:26

  4. #3
    Join Date
    11.10.2017
    Posts
    5

    Default Re: Need some help for two simple things

    Thank you for the reply Lukas.

    About 1 - it works this way, but when defining a function of type WriteSetValue, it seems that I have to hardcode both the variable and the value.
    Do you mean that to be able to set a WORD variable to any possible value, I have to define 65536 different functions? And then for another variable - another 65536 functions?
    This way I'm effectively creating 65536 variables(functions) out of a single WORD.
    Is it really so, or I'm missing something?
    If it's really so, isn't there an easier way, through C# or VB scripting or something? I did some tests with that too, but it seems that I can't define a function callable from a button that accepts a parameter.

    About 2 - I have yet to figure how reaction matrices work, but in the configuration dialog I don't see how to link a matrix to a variable. I can link it to a function, but it's again the same function where both the variable and the value must be hardcoded. What kind of reaction matrix to use (binary, multi binary ...) and how to link a single bit status to a variable that can be used to control the color?

    Thanks

  5. #4
    Join Date
    02.05.2017
    Posts
    26

    Default Re: Need some help for two simple things

    Hello,

    Do you mean that to be able to set a WORD variable to any possible value, I have to define 65536 different functions?
    Theoretically yes, as far as I know. Unfortunately, neither the variable nor the value property of such a zenon function can be parsed as a parameter. What's the most efficient solution depends on your goal. If you just want a few buttons to set one variable to specific values, I think creating multiple functions is still the best solution. I can't think of straightforward workarounds in e.g. VSTA, because as you said, you can't directly parse a parameter. Such an approach would only pay off if you really had a huge number of desired functions.

    I have yet to figure how reaction matrices work, but in the configuration dialog I don't see how to link a matrix to a variable. I can link it to a function, but it's again the same function where both the variable and the value must be hardcoded. What kind of reaction matrix to use (binary, multi binary ...) and how to link a single bit status to a variable that can be used to control the color?
    I think a Binary Reaction Matrix would fit your use case best. I hope I can explain it well, otherwise please visit the help chapter 'Manual -> Variables -> Reaction matrices'.
    • Create a new binary reaction matrix. The configuration dialog should appear
    • Press the button "New Condition"
    • Toggle the box of the 5th value bit until it displays '1'
    • On the right hand side of the dialog, select your desired limit value color (red)
    • Repeat the last 3 steps, but with the 5th bit value set to '0' and the color to green (or whatever)
    • (Alternatively, you could also configure a default state with a color)
    • Press OK
    • Select your 'PLC.word1' variable in the variables view
    • In the property view, go to 'Limit Values -> Reaction Matrix (...)' and select your created reaction matrix in the dialog and press OK
    • Select your circle object
    • In the property view, go to 'Fill -> Fill color dynamic -> Fill color (...)' and select your word variable
    • Note: If you have a numeric value element of this variable in a screen and don't want the limit value color to be present there, you'd have to disable the 'Use limit value color' checkbox in the 'Text' properties of that element.
    • Now the circle will be green if the 5th bit of the variable is 0, and red otherwise. I hope I understood correctly that this is what you want to achieve.


    Click image for larger version

Name:	Capture.PNG
Views:	15
Size:	36.0 KB
ID:	2416

    Regards
    Lukas
    Last edited by LukasRotter : 25th September 2018 at 17:24

  6. #5
    Join Date
    13.08.2013
    Posts
    57

    Default Re: Need some help for two simple things

    Hi,
    could you elaborate on this point "1. How to set a PLC variable by clicking a button?"
    What is your usecase here? Where would the parameter for the C# Function come from?
    I can imagine multiple usecases.

    Maybe you want to check out recipes. Here you can set a set of variables to specific values, you can allow some user to define this recipes and some others to execute.

    Or you want to allocate the value of an internal variable to your PLC variable=>Use allocations (the also have triggers, to combine it with your button)

    The value should be result of a calculation? Mathvariables would be the way to go, these also can be turned on/of with a Bool.

    You also could use various button click events in VBA/VSTA to if to code needs to know from which button the command came from.
    Please make your case more clear, than we can help you with a more specific answer

    Best regards
    Sigi

  7. #6
    Join Date
    11.10.2017
    Posts
    5

    Default Re: Need some help for two simple things

    Hello Sigi,

    thank you for the reply.

    could you elaborate on this point "1. How to set a PLC variable by clicking a button?"
    What is your usecase here? Where would the parameter for the C# Function come from?
    I can imagine multiple usecases.
    I want to have buttons that send commands to the PLC to execute different actions.
    For example clicking Button1 makes the PLC toggle the coil for Valve1. Button2 makes it toggle Valve2. Button3 makes it move Motor1 to position5. And so on....
    For this, I want each button to set the same PLC variable (command code) to a fixed value.
    Like clicking Button1 sets PLC1.cmd to 1001. Button2 sets PLC1.cmd to 1002 and so on.
    I can't directly set PLC outputs because that's unsafe, the PLC has to receive a command and check if it's safe to execute it first.

    So that's what I want. What do you think is the best way to achieve it?

    About your suggestions:
    - Functions: As there are many possible actions that should be triggered from buttons, defining a separate function for each and then linking it to a button would be a nightmare.
    Also, functions are simply not applicable in many cases - you can't toggle a BOOL or increment/decrement an integer from a function.
    Basically, functions deal with constants, not with variables.

    - Recipes: I don't think they would work, because I'll need a separate recipe for each value, and then a separate function to load each recipe - this is even more complicated than the above.

    - Allocations - the only possible scenario I may think of is defining and internal array1 of integer constants and use them as source variables, define PLC1.cmd as a target for all allocations, and define an internal array2 (same size as array1) of BOOLs to be set from buttons and used as triggers. But this seems very complicated too, not to mention that the triggering BOOL has to be reset somehow after the transaction is executed.
    And as allocations are just copy operations, stuff like toggle a BOOL or increment an integer var is not possible.

    - Math - I need each button to send a fixed value, calculations are not needed, so it's probably not suitable either.

    So VBA/VSTA seems the only way. I created a VBA macro

    Public Sub LeftClickDown_Default(obElem As Element)
    Dim btnName
    Debug.Print "test"
    btnName = obElem.Name
    Debug.Print obElem.Name
    End Sub
    and attached that macro to the LeftClickDown mouse event for a couple of buttons. However, the macro is not executed when a button is clicked. If I set a breakpoint, it's never hit.
    What's the proper way of doing this and can it be done from C#? Or, can I write to onlineVariable defined in VSTA ThisProject_Startup from VBA, or I have to define a separate onlineVariables container in VBA?

    Thanks
    Last edited by peternn : 26th September 2018 at 10:33

  8. #7
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    801

    Default Re: Need some help for two simple things

    you can also project buttons to set values of linked variable without functions. This is possible with 'combi-element' instead button.
    steps:
    1. create combined-element and link with variable PLC1.cmd; following combi-element settings:
    2. activate check-box '3D' (in Representation)
    3. configure write set value 'without dialog', deactivate 'propose current value' and 'set value/change by' - value to write to variable: 1001 or 1002 etc.
    4. in representation configure to display a graphic (symbol from the library) or a text
    Last edited by ursulak : 27th September 2018 at 08:51 Reason: format

  9. #8
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    801
    Best Answer

    Default Re: Need some help for two simple things

    and in your macro you have forgotten to call the event at the end, last line shall be: obElem.LeftClickDown

  10. #9
    Join Date
    11.10.2017
    Posts
    5

    Lächeln Re: Need some help for two simple things

    Thank you very much Ursula!

    Quote Originally Posted by ursulak View Post
    you can also project buttons to set values of linked variable without functions. This is possible with 'combi-element' instead button.

    I wonder how I missed the combi-element.

    What you suggest works, but the combi-element seems to have some disadvantages (unless I miss something again)
     - when the element is clicked, there is no visual feedback of any kind. The button doesn't change at all. Although the value is written to the PLC variable,  you have the feeling that nothing happened.
     - It seems not possible to make the color of the button depend on another variable, not the one it modifies.

    and in your macro you have forgotten to call the event at the end, last line shall be: obElem.LeftClickDown
    I would have never guessed I should call the event from the event handler for that same event, it's quite counter -intuitive
    I saw it noted in the help file after reading your reply.
    This works too.
    I can name my buttons like btn101, btn102 etc. and in the VB procedure read the name, remove btn prefix, convert the remaining part to Int and set the PLC variable to that Int. And I can make the color of a classic button depend on another variable. So I think I'll go that way.

    Thanks again for your help.

    Best regards,
    Peter

Similar Threads

  1. Simple VB in Zenon
    By mjackson in forum VBA
    Replies: 5
    Last Post: 1st December 2014, 10:33
  2. Simple Project, no idea
    By matholton in forum zenon Supervisor
    Replies: 1
    Last Post: 24th September 2008, 12:01

Tags for this Thread

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •