krolikbest Posted June 17, 2020 Report Share Posted June 17, 2020 Hi, hardware : V700, 4x servo Liteon, communication 485, modbus. Servos are switched on. when I don't use subroutine (named ResetHomOK) and directly in the ladder 14 put what is on the second photo then I can read Modbus frames, but if i use subroutine then can't. There is some picture below describing my problem: In ladder 14 I use subroutine and this subroutine "Reset HomOK" looks like: Return from this subroutine is ater all frames are read (or should be). So I expected to get values in MI830 and MI831, but didn't (have zero as a default).. I'm little lost, want to use subroutines because I find it very useful. Quote Link to comment Share on other sites More sharing options...
AlexUT Posted June 17, 2020 Report Share Posted June 17, 2020 You cannot call subroutine by POSITIVE (or NEGATIVE) transition contact and suppose that subroutine return you data. You have to call subroutine as long as you receive all required data, or until all timeouts and retries ends. Data transfer require time. Time to call routine is much less than scan time. So you have no data. B.R. Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted June 17, 2020 MVP 2022 Report Share Posted June 17, 2020 Do NOT perform conditional calls of subroutines. It is BAD practice. In this situation, I think you're under the mistaken impression that since you've SET MB 2012 in the rung where you're calling the subroutine, that the subroutine will be called as long as MB 2012 remains SET. That is NOT the case. Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted June 17, 2020 MVP 2022 Report Share Posted June 17, 2020 And to expand a bit for anyone unfamiliar with Ladder Logic. In normal computer programming, subroutines are typically used to execute some code under certain specific conditions (e.g. a print subroutine would only be executed when the operator issued a print command). This should not be done in Ladder Logic - subroutines should only be used to organize your code into manageable chunks, but every subroutine should be executed on every scan. You have to have a bit of a different mindset when creating proper code in Ladder Logic. Quote Link to comment Share on other sites More sharing options...
krolikbest Posted June 17, 2020 Author Report Share Posted June 17, 2020 Thanks for explanation. My thinking was like a pc-programmer (I took it like calling subprocedure/function) hence misunderstandnis. Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted June 17, 2020 MVP 2022 Report Share Posted June 17, 2020 1 hour ago, krolikbest said: My thinking was like a pc-programmer That's extremely common - probably the most difficult thing for computer programmers to overcome when programming PLCs. I also come from a computer programming background and it took me awhile to get my mind right for PLCs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.