While chasing memory frag and alloc exception problems on my Panda II, I discovered the code I had copied from GHI’s OneWire old tutorial for SDK 4.1 reading a DS18B20 thermometer has a Thread.Sleep(750); after starting the temperature conversion in order to give the Dallas time to make the conversion. This length of time is wreaking havoc on my system which feeds timer callbacks through a prioritized work item queue. [The problems seem to arise because the sleep blocks a Dequeue thread (using only one at the moment) while Enqueue is on an unblocked thread. Not sure why it leads to fragmentation.]
So I want to get rid of that nap. GHI’s tutorial is now based on SDK 4.2 and uses while (ow.ReadByte() == 0) instead of the Sleep which I understand would work with the DS18B20’s sending 0 while converting and then 1 when finished. However, when I replace the Thread.Sleep(750) with the while loop, the thermometer works fine the first time it is used, then never exits the while loop the subsequent time the temperature is requested. I notice the 4.2 code uses ow.TouchReset() instead of 4.1’s ow.Reset(), but otherwise the two examples are identical.
Anyone have any suggestions as to why this doesn’t work for me and what might be used to get rid of the Thread.Sleep(750)?