http://datasheets.ma.../ds/DS18B20.pdf
static float getOWTempByAddress(OneWire owBus) { ArrayList deviceList = owBus.FindAllDevices(); foreach (byte[] device in deviceList) { Debug.Print("Found ID: " + bytesToHexString(device, true)); } byte[] deviceToCheck = (byte[])deviceList[0]; //lets just look at the first device as a test float TemperatureC = 0; int tempLow = 0; int tempHigh = 0; int temptemp; owBus.TouchReset(); owBus.WriteByte(0x55); //match rom foreach (byte theByte in deviceToCheck) { owBus.WriteByte(theByte); } owBus.WriteByte(0x44); //start temp conversion while (owBus.ReadByte() == 0) ; //wait while busy owBus.TouchReset(); owBus.WriteByte(0x55); //match rom foreach (byte theByte in deviceToCheck) { owBus.WriteByte(theByte); } owBus.WriteByte(0xBE); //read scratchpad tempLow = owBus.ReadByte(); //LSB tempHigh = owBus.ReadByte(); //MSB temptemp = (((int)(tempHigh) << 8) | tempLow); TemperatureC = temptemp * 0.0625f; } return (float)((TemperatureC * 9.00 / 5.00) + 32.00); }
Edited by Chris Walker, 11 November 2012 - 05:19 PM.
added [code][/code] tags