Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Problem with Modbusmaster in Subscan


MatthewBoyd Nov 18, 2013 06:26 PM

I'm trying to use Modbusmaster (for TCP/IP connections) inside a Subscan with the main program running in Pipeline mode. However, the Modbusmaster functions are executing 'count' times in a row without pausing between Subscan intervals.

Is there a way to execute Modbusmaster functions inside a Subscan properly? I would rather not do this in a SlowSequence because I want it to have higher priority than my other SlowSequences so I don't miss scans due to my high scan rate.

Thanks.


GTProdMgr Nov 25, 2013 05:51 PM

The syntax of SubScan is this:
SubScan (SubInterval, Units, SubRatio)

If "Subinterval" is set to zero, then the subscan will execute as fast as it can go. That sounds like what you are experiencing. Use a non-zero subinterval to control the timing of how often the SubScan will execute. The product of the SubInterval and SubRatio may not exceed the interval of the main scan in which the subscan is placed.


Sam Nov 26, 2013 06:17 AM

Can you explain in more detail what you are attempting to accomplish?

ModbusMaster operates as a processing task, not a measurement task. When running in pipeline mode, the logger will slice it's processing time between the main scan and slowsequences. Basically, I'm trying to say I don't think going through great lengths to place Modbusmaster in the main scan or in a subscan is going to gain you more than putting it in a slowsequence.

I think you would experience very similar behavior from the following two setups:

Scan()
for i = 1 to 10
handle(i) = tcpopen(ip(i),port(i),255,500,handle(i),10)
modbusmaster(... handle(i)...)
next i
NextScan


or......


Scan()
NextScan

SlowSequence
Scan()
for i = 1 to 10
handle(i) = tcpopen(ip(i),port(i),255,500,handle(i),10)
modbusmaster(... handle(i)...)
Next i
NextScan()
EndSequence


MatthewBoyd Nov 26, 2013 05:06 PM

Thank you both for the replies. Responding to the first suggestion, the SubScan does have a non-zero interval and the other AM25T measurement commands in the Subscan appear to working correctly.

What I would like to achieve is the following:


TCPhandle = TCPOpen(...) 'via NL115 Ethernet port
SerialOpen(RTUhandle,...) 'via SDM-SIO1

Scan(10,sec,0,0) '10s interval, 0 buffer, repeat forever)

'Measure instruments here every 10s

SubScan(1,sec,10) '1s interval, repeat 10 times

'Measure instruments here every 1s
ModBusMaster(...,TCPhandle,...)
ModBusMaster(...,RTUhandle,...)

NextSubScan
NextScan


The reason I want the Modbus measurements in the main scan and not a SlowSequence is because I would like to give them precedence over the other SlowSequences in the code as sometimes the SlowSequences are skipped due to the rapid sampling. Regardless, I think this could be a problem with the OS, as the above code structure results in the ModBusMaster commands executing 10 times in rapid succession. The compiler will also throw the error "No Measurements in SubScan." if there are no measurement tasks in the Subscan (e.g., AM25T()).


Sam Nov 27, 2013 05:26 PM

From Art ... note his comment about this applying specifically to PipelineMode.

Something to remember about PipeLine Mode: the processing sequence in the main scan does not start out until all of the measurements in the main scan are complete. Once the processing sequence starts, it goes as fast as it can until complete. If the Scan/NextScan sequence has SubScan/Next SubScan within, it is no exception; the rule still applies. All the measurements must complete, including looping through the subscans, before the processing instructions can start up. Then, the processing instructions go as fast as they can, including looping through the subscan loop as fast as they can, until they get to the NextScan instruction.

Since ModBusMaster() is a processing instruction, not a measurement instruction, then they will indeed, as the user observed, loop through the sub scan loop as fast as they can. Note further, in the users example, where the scan interval is 10 seconds, the sub scan interval is 1 second, with 10 loops through, that the last loop through the sub scan measurements won’t start until 9 seconds into the 10 second interval, so the last measurement in the scan will finish with less than 1 second remaining to loop 10 times through the processing within the sub scans, including 10 ModBusMasters(). In other words, all the processing, including 10 times through the subscan loop, will have less than 1 second to do their work (1 second minus the measurement time of the measurements within the sub scan.

It seems like the user could simply have a 1 second Main Scan and a 10 second Scan within a SlowSequence or a 10 second Main Scan and a 1 second Scan within a Slow Sequence, or simply a 1 second where he does all the measurements though he might not use some of them except every 10 seconds and use TimeIntoInterval(0,10,sec) to do the ModBus and to process to use the “10 second” measurement results.


MatthewBoyd Nov 27, 2013 05:52 PM

Thank you. So it appears that SlowSequences are the best method for using ModBusMaster at different intervals than that of the Main Scan.

You may want to consider alerting the user via a compiler error if they have a ModBusMaster command in a Subscan as the behavior described above may not be obvious, as it wasn't to myself.


Sam Nov 27, 2013 06:01 PM

** I agree that SubScan() documentation can and should be expanded to discuss this type of behavior **

If not obvious, the behavior and usage is valid. It is the double edge sword of Pipeline mode. Great for precision timed, fast, measurements. But we have to understand the differences between Pipeline and Sequential mode sometimes when doing things like this.

Here is documentation by example for this thread.

---------
Example 1, Program Compiles in Pipeline Mode.
Logger executes all measurements first, including the Panel temperature measurements spaced 1 second apart. Then it processes the processing instructions as quickly as possible.

When watching the output of the datalogger I can see that the Modbus queries go out very soon after the 4 second mark PTemps are taken at 0,1,2,3, and 4 seconds into the interval and then 5 back to back modbus queries go out.


Public Result1
Public RegOne(4)
Public BattV,Ptemp
BeginProg
Scan (10,Sec,0,0)
Battery (BattV)
SubScan (1,Sec,5)
PanelTemp (Ptemp,250)
ModbusMaster (Result1,COMRS232,9600,1,4,RegOne(),1,4,1,100,0)
NextSubScan
NextScan
EndProg


---------
Example 2, Program Compiles in Sequential Mode.
Logger executes instructions sequentially as they appear in the program.

When watching the output of the datalogger I can see that the Modbus queries are spaced apart by 1 second. They go out after the PTemp measurement is made 0,1,2,3, and then 4 seconds into the interval.

SequentialMode
Public Result1
Public RegOne(4)
Public BattV,Ptemp
BeginProg
Scan (10,Sec,0,0)
Battery (BattV)
SubScan (1,Sec,5)
PanelTemp (Ptemp,250)
ModbusMaster (Result1,COMRS232,9600,1,4,RegOne(),1,4,1,100,0)
NextSubScan
NextScan
EndProg

* Last updated by: Sam on 11/27/2013 @ 11:02 AM *

Log in or register to post/reply in the forum.