Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Am i using triggers wrong?

HLCN
2018-07-26
2018-07-27
  • HLCN - 2018-07-26

    So i'm writing an application where i need to do a HTTP Post request everytime a tag changes status, so i'm using rising and falling triggers to call the program that has the HTTP.Post function block. Every call to the program has different arguments (WString). But i can't get the program to execute ONCE on a status change, so it executes on every scan, or it doesn't execute at all. I feel like i'm missing somethin g very simple, can anyone help?

    The program from the images doesn't get called at all...

    Any help is appreciated,

    -Hector

    IMG: webreqprg.png

    IMG: ladder.png

     
  • Lo5tNet - 2018-07-26

    So it looks like you have at least two problems with this:
    1. POSTWebReq2 only gets called ONCE after an R_TRIG or F_TRIG event. POSTWebReq2 is a function block that takes more than one cycle of the PLC to execute. This means that you should always be calling the POSTWebReq2 and not only after the trigger events.
    2. In your POSTWebReq2 you set xExecute to true for the HttpClient. xExecute is what starts the process of sending the message. If this is always true it will only send the message once, if you fix issue 1. What you want to do is use the TRIGGERS to set the xExecute to true and when there is either xDone or xError then you need to set xExecute to false. Every time xExecute gets set to true it will go through it's process of sending the message. This means you need to allow enough time for HttpClient to finish before trying to send another message.

     
  • HLCN - 2018-07-26

    Thanks for your response ComingBack4u...

    I do want for the POSTWebReq2 to execute only once there is a trigger event, to notify my server that the tag changed status.

    POSTWebReq2 is a program, should i be using a function or function block instead? Because the POSTWebReq2 program always has the arguments from the last rung on the program, so maybe programs are not designed to be taking different arguments.

    So before this version, i tried creating an instance of the function/FB that calls that does the request, but since i have 29 slaves (one program for each) i was creating too many instances of it and the PLC was throwing an exception.

    I also tried adding a WString (argument) to a FIFO (Element collections) every time an event trigger happened, then i had a task that processed the FIFO, but i ran into exceptions also. I think 2 different tasks were trying to access the same FIFO...

    I will take your advice and modify my program, hopefully i'll have a working version soon...

    Thanks!

     
  • HLCN - 2018-07-27

    So ended up switching to a function block, it works as i need it to, but creating so many instances of it will use more memory than what i have available...
    I'll try some other way around this.

     

Log in to post a comment.