Jump to content

Modbus-why can't read this


Recommended Posts

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

2020-06-17_145815.png.adb629f691c3ad8224ac5461b491f749.png

 

and this subroutine "Reset HomOK" looks like:

2020-06-17_150104.png.28bf54773d964e4678634923966a7f0a.png

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • MVP 2023

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.

Link to comment
Share on other sites

  • MVP 2023

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.

Link to comment
Share on other sites

  • MVP 2023
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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...