Skip to content

Stopwatch is never started in DS2482_100 #10

@crates-barrels

Description

@crates-barrels

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions