News:

  • June 28, 2026, 08:26:19 PM

Login with username, password and session length

Author Topic: Per scan MRX  (Read 17111 times)

CReese

  • Hero Member
  • *****
  • Posts: 184
Per scan MRX
« on: September 11, 2013, 01:56:53 PM »
I've set up MRX in my normal per-scan sequences and noticed that unless I set the read frequency parameter, it only reads once on start.

1. Am I interpreting/reading this correctly?
2. Is this the best way to set a read frequency by variable or otherwise (by the block parater)? I have no problem with this, but want to be clear this is how the block operates.

Thanks,
c
« Last Edit: September 11, 2013, 02:15:16 PM by CReese »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Per scan MRX
« Reply #1 on: September 11, 2013, 02:18:50 PM »
Yes, you need to set up the "Enable" behavior (i.e. Once on Leading Edge vs. Continuous on Power Flow at Interval) as as Continuous with an Interval, otherwise it will ONLY execute when the input leg transition goes from OFF to ON (if it stays ON or if it stays OFF, it won't ever run again).

Some Input Legs on boxes are "edge triggered" (e.g. CNT'S UP input leg) where it is looking for the power-flow from one scan to the next to go from OFF to ON.  Most instructions are simple power-flow enabled (e.g. OUT coil, MATH box).  However, a few give you the option to set it one way or the other.  One of them is the MRX instruction.  This lets you do "polling" type comm (Continuous at Interval), or "event-triggered" type comm (on leading edge, where the leading edge of the input logic into the box is the "event").

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Per scan MRX
« Reply #2 on: September 11, 2013, 02:20:16 PM »
Oh, an Interval of 0 means "as fast as possible" (it will take at least Ladder 2 scans, regardless).

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Per scan MRX
« Reply #3 on: September 11, 2013, 05:16:03 PM »
Beauty. Thanks.


CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Per scan MRX
« Reply #4 on: September 11, 2013, 06:55:21 PM »
How will this asynch function work with loops? I have a bunch of read locations and addresses in an array that I'd like to read sequentially, but it does not seem to operate well within a For loop as I had intended. The values are only sporadically read, although the MRX does not register any error.

In other words, if I have an array of IP addresses, read addresses, and write addresses, what is the best way to process them? I realize that transactional overhead my result in doing this in blocks, but I will still be performing the same basic operations.

Thanks,
C

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Per scan MRX
« Reply #5 on: September 11, 2013, 07:47:56 PM »
Stick the array-referenced MRX a separate Stage Program code-block that you "RUN" from $Main (call the program DoCurrentMRX).  Every time it finishes, increment the index in $Main.  You use the EXIT instruction inside DoCurrentMRX and monitor its completion in $Main by looking at DoCurrentMRX.Done.

DoCurrentMRX requires multiple scans to finish, so you cannot use FOR/NEXT.  FOR/NEXT (or any other kind of looping) does not work very well with asynchronous/multi-scan instructions (those with colored triangles in the top left corner).  You will also get a bunch of Program Check warnings letting you know you have these type instructions inside a loop.

DoCurrentMRX would be a two (or three) Stage program.  The first Stage would have the MRX, which JMPs to either a Successful SG, which just EXITs, or an Error SG, which sets a flag and also EXITs.  You could just have both On Success and On Error JMP to the same SG if you do not need any special error handling.

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Per scan MRX
« Reply #6 on: September 12, 2013, 11:10:18 AM »
So more or less turn an asynch operation into a synch operation by using stages.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Per scan MRX
« Reply #7 on: September 12, 2013, 11:16:36 AM »
So more or less turn an asynch operation into a synch operation by using stages.
It's more...
encapsulate the asynch operation into an asynchronous "function call" where you monitor the function/program code-block's .Done bit at the "caller" level to know when the "function" is done.

Looping works great on synchronous operations - terrible with async, because you are literally looping PLC instructions, not "high level" async operations.  No comm.  No I/O.  Just looping instructions.  Even if the .TimeSlice was 65535 (yield every time through the loop), the comm is still async and can require (at least) 2 scans and possible 10,000 scans (think EMAIL or MRX over 2400 baud modem).

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Per scan MRX
« Reply #8 on: September 12, 2013, 11:18:38 AM »
So in the case of a two-stage scenario with a 'success' stage, is the stage just empty?

Edit -- reread to see EXIT.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Per scan MRX
« Reply #9 on: September 12, 2013, 11:21:02 AM »
So in the case of a two-stage scenario with a 'success' stage, is the stage just empty?
It contains one instruction, EXIT.  This "terminates" the code-block execution, turns on the code-block's .Done bit, which $Main monitors to know it can iterate to the NEXT MRX index and re-RUN the "function".

CReese

  • Hero Member
  • *****
  • Posts: 184
Re: Per scan MRX
« Reply #10 on: September 12, 2013, 11:51:44 AM »
Thanks. Works a charm.