///<summary> /// If Resolution is x then conversion time is y: ///<example>12Bits = 750ms; 11Bits = 375ms; 10Bits = 188ms; 9Bits = 94ms ///</example> ///</summary> ///<returns></returns> public async Task <float> ReadTemperature() { Task <float> tempRead = new Task <float>(() => { lock (_port) { if (this.ConvertT()) { if (this.AddressById()) { CRC8 ccc = new CRC8(); byte dupa = 0x00; int xCRC = 0x00; bool resul = ccc.CheckCrc(Id); this.WriteCommand(Command.ReadScratchPadFun); byte[] buf = this.Read(9); resul = ccc.CheckCrc(buf); float tmp = this.ConvertToTemperature(buf[1], buf[0]); if (_min == _max && _min == 130) { _min = _max = tmp; } if (_min > tmp) { _min = tmp; } if (_max < tmp) { _max = tmp; } return(tmp); } } } return(-999.999f); }); tempRead.Start(); return(await tempRead); }
///<summary> /// If Resolution is x then conversion time is y: ///<example>12Bits = 750ms; 11Bits = 375ms; 10Bits = 188ms; 9Bits = 94ms ///</example> ///</summary> ///<returns></returns> public async Task<float> ReadTemperature() { Task<float> tempRead = new Task<float>(() => { lock (_port) { if (this.ConvertT()) { if (this.AddressById()) { CRC8 ccc = new CRC8(); byte dupa = 0x00; int xCRC = 0x00; bool resul = ccc.CheckCrc(Id); this.WriteCommand(Command.ReadScratchPadFun); byte[] buf = this.Read(9); resul = ccc.CheckCrc(buf); float tmp = this.ConvertToTemperature(buf[1], buf[0]); if (_min == _max && _min == 130) _min = _max = tmp; if (_min > tmp) _min = tmp; if (_max < tmp) _max = tmp; return tmp; } } } return -999.999f; }); tempRead.Start(); return await tempRead; }