Jump to content

Few Modbus frames-one by one


Recommended Posts

Hi,

I need to send for few devices modbus rtu frames -strictly saying  for every device two modbus frames.  All frames should be sent by pressing one button , so for first and second modbus frames I use :

steps 1,2 for 1-st device

1. if [MB_positive transition] then send first MBS_frame

2. if [MB_negative transition] then send second MBS_frame and set MB_sent_frame

and then for the other I use timer and one MB element as a semaphore:

steps 3,4 for 2-nd device

3. if MB_sent_frame then set Timer1 and reset MB_sent_frame

4. if Timer1 then send next MBS_frame and set MB_sent_frame and reset Timer1

steps 5,6 for 3-rd device

5. step 3

6. step 4

and so on

As you see, it looks "a bit" complicated, maybe.. Or do you have some patents to make it simpler or better looking? The best imho would be something like "time sequencer" function block, in which I could set time interval and tasks to go. Maybe already is something similar I don't know?

Regards,

Martin

Link to comment
Share on other sites

  • MVP 2023

You are pretty much talking about setting an automatic sequence going that starts on a button push.

How many stars are in the universe?  Well....that's almost the number of  ways you could do this......not really.   😉

But one thing you need to keep in mind is the inherent delays in doing modbus rtu.....it is fairly slow.  If you register the positive of a button push and also the negative, you will likely get into send conflicts if the button is just quickly tapped.

In your case I'd seriously consider using a counter based on incrementing using   SB15 --> Increment.  Then do a series of compares that step you through your various modbus actions by triggering the next one when the counter rolls up to the given number.   eg when the count is 21 do the next one, 28 the next and so on.   Once the sequence finishes you stop the count by using a compare that the count is larger than your maximum count needed, and the button push starts it again by resetting the count to 0.

Another method would be similar to state machine action, which Joe T has discussed at length.   A link to the forum page:  http://forum.unitronics.com/topic/5609-advice-on-main-routine-structure/?tab=comments#comment-21891

Whatever way you decide to do this, you need to accommodate the length of time the comms are set at, how long it actually takes, and also allow a little bit of time for the buffer to fully clear after the system says it has finished the communication process.  Also remember that if you have a number of retries set, you have to allow for their longer time to process if one of the addresses doesn't respond properly.  If speed is of the essence, I generally don't do any retries at all.  If the device doesn't respond consistently then you should have some logic that would pick this up after doing it for X times.

Stand by for all the other methods to appear......!!

cheers, Aus

 

Link to comment
Share on other sites

Thank for reply,

I'm aware of modbus rtu disadvantages but fortunately it's not crucial process. My solution is already tested  and workable but always maybe is sometnig better.. I've downloaded example project of Mr. Tauser and as I understand after every operation is set some value to specific MI, which says which condition/state it's in. So this is the difference to my solution that now I would know which operation is after. Ok, take into consideration for future. Idea of incrementing based on SB7/SB15 also is interesting. I'll test it. Thank you.

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...