Div_by_zero

best way to execute Modbus writes during continuous read cycle

4 posts in this topic

Working on a communications project where I will be continuously polling 4 different Modbus enabled devices.  By "continuous" I mean that every 25 ms (a parametric value) the PLC will be reading different coils, inputs, input registers, and holding registers.  There are approximately 10 reads per device, so 40 reads total in a single read cycle.

On command (random operator intervention), writes to certain holding registers will occur.

In order for a write to occur, the reading must temporarily stop, then, after a short delay (10 ms), a write may be attempted.

I'm trying to figure out the best, cleanest way to pause the reads so that a write can occur.

The "brute force" was would be to create, for each writable value, a pause bit, a write delay timer, and a break (unpause) bit.

However, this would start to add up to a lot of tags quickly, and I feel there must be a better way to do what I need to do.

Any ideas?

Thanks!

 

edit: the PLC is an Automation Direct Productivity 2000

 

Edited by Div_by_zero

Share this post


Link to post
Share on other sites

I would create an internal bit called "Write request Pending" and set it when the operator commands a write. Use that bit as a permissive (must be off) for any read requests. When there is a write request pending, and the most recent read command has been executed you can execute the write command. Upon successful completion clear the "Write request Pending" bit.

Share this post


Link to post
Share on other sites

Thanks Steve, that definitely helps.

Question: how do I identify and define the "most recent read command".

Thanks again.

 

Share this post


Link to post
Share on other sites

Without knowing the details of your specific application I can't answer that question. There must be something in your logic that sequences the read requests over the full range of addresses. I would start by looking there for a value that identifies when a read request is being processed. If the entire sequence is controlled by the 25 mS timer rather than by a bit that indicates completion of each read request,  wait for the timer to time out after the "write request pending" bit goes high.

Or, iIf there is a word that tells you which of the forty read requests is being executed, when that word hasn't changed its value for longer than 25 mS, you know the read sequence has been interrupted by the pending write request and it is safe to execute the write.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now