mcsakoff / pydigitemp

Python implementation of 1-Wire protocol.
Other
16 stars 11 forks source link

Temperature sensor (XY) error Read/Write error #2

Closed slavkoja closed 7 years ago

slavkoja commented 7 years ago

Hi,

in my simple test program i have:

try:
    starttime = int(time.time())
    while True:
        for sensor in sensors:
            temp = sensor.get_temperature()
            print ("%5d" % getdelay(starttime), sensor.rom, end=":")
            if isinstance(temp, float):
                print ("%0.1f" % temp)
            else:
                errcnt[sensor.rom] += 1
                print (type(temp), "\aErr %s" % errcnt)
            sys.stdout.flush()
        print ("-"*50)
        time.sleep(4)
except termios.error:
    print ("Disconnected...")

The sensors list is list of DS18B20() objects...

I use it to test different UART <-> 1-wire circuits and i sometime get "Read/Write error", the problem is, that it is not an exception, but it appears as stdin (or perhaps stderr) output. Here is example two readings of two sensors, one without error and one with error:

--------------------------------------------------
 2543 282E12D50400005A:24.9
 2544 283DA9E104000021:23.0
--------------------------------------------------
 2548 282E12D50400005A:24.9
Temperature sensor (283DA9E104000021) error Read/Write error
 2552 283DA9E104000021:<class 'NoneType'> Err {'282E12D50400005A': 0, '283DA9E104000021': 1}
--------------------------------------------------

It seems, that the get_temperature() doesn't raise this exception, but only reports text and this is problem to catch. I try to find, where this printing happens, but i lost in code. Please, can you implement raising this error instead printing, to one can catch it in try .. except block?

mcsakoff commented 7 years ago

Sure, it is better to throw an exception out of the get_temperature() method. It is easy to fix but let me check the change doesn't break things in my projects.

If you need the fix right now -- in pydigitemp/digitemp/device/termometer.py just remove outer try...except block in get_temperature(). It is lines 68, 82-84.

slavkoja commented 7 years ago

Thanks for quick response, i don't need the fix immediately, but thanks for suggestion, i can test it ;-)

BTW, do want to include here schematics (UART <-> 1-wire) in SVG format? I can provide them.

mcsakoff commented 7 years ago

Sure, that would be great!