Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopwatch is never started in DS2482_100 #10

Open
crates-barrels opened this issue Sep 25, 2018 · 1 comment
Open

Stopwatch is never started in DS2482_100 #10

crates-barrels opened this issue Sep 25, 2018 · 1 comment
Labels

Comments

@crates-barrels
Copy link

In WaitForOneWireReady(), a new Stopwatch() is created, but never started. As a result, the if-test (stopWatch.ElapsedMilliseconds > 5000) will never evaluate to true:

var stopWatch = new Stopwatch();
do
{
if (stopWatch.ElapsedMilliseconds > 5000)
{
throw new InvalidOperationException("One Wire bus busy for too long");
}
_i2cDevice.WriteRead(new byte[] { FunctionCommand.SET_READ_POINTER, RegisterSelection.STATUS }, status);
} while (status[0].GetBit(StatusBit.OneWireBusy));

This can easily be fixed by changing line 329 to var stopWatch = Stopwatch.StartNew();

The same issue can be found in this piece of code in ReadStatus(bool setReadPointerToStatus = false):

var stopWatch = new Stopwatch();
do
{
if (stopWatch.ElapsedMilliseconds > 1)
{
throw new InvalidOperationException("One Wire bus busy for too long");
}
_i2cDevice.Read(statusBuffer);
} while (statusBuffer[0].GetBit(StatusBit.OneWireBusy));

Also, is the 1 millisecond time-out here not way too short? Or is there a specific reason for this?

Regards

@Rinsen
Copy link
Owner

Rinsen commented Oct 5, 2018

There are some fundamental issues with the error handling that should be addressed and this is for sure one of them, thanks for the report!

Also the status handling in the chip is not handled in a good way. As long as I find the time I am planning a new release later this year or in the beginning of next.

@Rinsen Rinsen added the bug label Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants