Showing results 1 to 5 of 5

Thread: Thread Sleep

  1. #1
    Join Date
    02.02.2022
    Posts
    11

    Default Thread Sleep

    I am finding that if I do:

    context.VariableCollection["PLC!G_HMI.Recipes.WorkHmi"].SetValue(0, true);
    Thread.Sleep(10000);

    The variable goes true past the 10 secs and not before. Is there anyway I can do this before?
    I need to wait the 10 Secs for a timeout response of the PLC.

    Thnks

  2. #2
    Join Date
    03.11.2015
    Posts
    47

    Default Re: Thread Sleep

    Thread.sleep is awfully bad coding. It would block the service engine for 10 seconds. 
    Rather think of something where you react on an event on a certain variable instead of using thread.sleep(..)

     

  3. #3
    Join Date
    02.02.2022
    Posts
    11

    Default Re: Thread Sleep

    Hmmm ok, I understand.
    We will have to change procedure on PLC then because if I use trigger variable I will be able to know if the PLC has acknowledged but If it doesn't I can't do a timeout this way...
    Its seems rather strange that there is no timmer function (Zenon embeded) so I can delay two funcions execution on the same script.
    Thnks

  4. #4
    Join Date
    03.11.2015
    Posts
    47

    Default Re: Thread Sleep

    For .NET there are such things as timers:
    https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer?view=net-6.0&viewFallbackFrom=net-4.5

    this would require an Add-In Service which hosts the timer. 
    in the timer event, you can operate on the API. E.g. start a function which starts an Add-In Wizard. 

    maybe I'm overthinking this.

    For timing functions in zenon you could use zenon logic along with internal variables. On the internal variables you hook a Reaction Matrix which executes the according functions
    (which could also be executing different  Add-In Wizards)

     

  5. #5
    Join Date
    18.12.2017
    Posts
    52

    Default Re: Thread Sleep

    Hi!

    Since I don't know what you want to accomplish this might be a stupid suggestion, but if you want to set a variable true and wait 10 seconds for it to change back to false, maybe to check for a timeout, you could use a Reaction Matrix or even a limit value.

    For variable "PLC!G_HMI.Recipes.WorkHmi", create a REMA or limit value, with a 10 second delay for 1(true). This could trigger another function or write to alarms or events.
    Use "write set value" to set the variable to true.
    After 10 seconds, the REMA or limit value, will trigger something if it hasn't been set back to 0(false).

    Best regards

    Fredrik

Similar Threads

  1. Verschwundener Thread
    By zero in forum Forum Issues
    Replies: 2
    Last Post: 13th February 2020, 13:09
  2. Multithreading Thread safety
    By Ruebezaehler in forum Add-In Framework
    Replies: 3
    Last Post: 14th December 2017, 12:39
  3. Start a thread in VBA
    By mrk in forum VBA
    Replies: 1
    Last Post: 19th March 2008, 10:12

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
  •