Skip to content
This repository was archived by the owner on Jul 24, 2022. It is now read-only.

Retry receiving response if response is behind request#41

Merged
Maxwe11 merged 1 commit intoNModbus4:masterfrom
richardlawley:RetryOnResponseBehindRequest
Jul 29, 2015
Merged

Retry receiving response if response is behind request#41
Maxwe11 merged 1 commit intoNModbus4:masterfrom
richardlawley:RetryOnResponseBehindRequest

Conversation

@richardlawley
Copy link
Contributor

This introduces the ability for a master to retry receiving a response if the one it picked up was from an earlier request (which timed out according to us). We use this when communicating with a device which sometimes responds slowly. Without it, it is possible for a master to be unable to recover - once one response arrives late, there is always one queued until the connection is closed.

The default behaviour is unaffected by this PR (default is off). To enable it:

ModbusIpMaster master = ModbusIpMaster.CreateIp(client);
master.Transport.RetryOnOldResponseThreshold = 3;

Tests have been added to cover the provided functionality.

This is a function I've had in my own fork and been using in production for a couple of years now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OnShouldRetryResponse is internal what means it's implementation detail, we should on debug stage determine that we pass wrong arguments here.
I think we should replace

if (request is IModbusRequest)

with

Debug.Assert(request is IModbusRequest, "Expected IModbusRequest")

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I didn't noticed that we have ModbusMaster.ExecuteCustomMessage so we could
a) assert
b) throw
c) nothing
Interesting your opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used the style of the existing code so that the change would be minimal, rather than doing things how I would normally do. I dislike Debug.Assert, especially when in this case since things are internal you would be better off changing the data type of the request parameter to be IModbusRequest.

I'm not sure what purpose ExecuteCustomMessage serves - it's not referenced within the codebase, covered by a test, documented or covered by a sample. Personally I would either change the signature so it takes IModbusRequest, or remove it altogether. Probably changing it is better.

Let me know what your opinion is, and you can either do this as a separate task since it's unrelated to this PR, or I can bundle it up in here too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, remove this check.

@Maxwe11
Copy link
Member

Maxwe11 commented Jul 28, 2015

@richardlawley I've left a couple comments but otherwise LGTM.
Nice API addition, thanks.

@richardlawley richardlawley force-pushed the RetryOnResponseBehindRequest branch from b6b2246 to d0a60ed Compare July 29, 2015 14:28
@richardlawley
Copy link
Contributor Author

Updated to reflect your comments, and so the tests point at the correct methods.

Maxwe11 added a commit that referenced this pull request Jul 29, 2015
Retry receiving response if response is behind request
@Maxwe11 Maxwe11 merged commit 44d27b1 into NModbus4:master Jul 29, 2015
@Maxwe11
Copy link
Member

Maxwe11 commented Jul 29, 2015

Thanks, merged.

@richardlawley richardlawley deleted the RetryOnResponseBehindRequest branch July 29, 2015 15:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants