void ResetOneWireAndMatchDeviceRomAddress() { DS2482Channel.OneWireReset(); DS2482Channel.OneWireWriteByte(RomCommand.MATCH); foreach (var item in OneWireAddress) { DS2482Channel.OneWireWriteByte(item); } }
protected byte[] GetTemperatureScratchpad() { ResetOneWireAndMatchDeviceRomAddress(); DS2482Channel.EnableStrongPullup(); StartTemperatureConversion(); ResetOneWireAndMatchDeviceRomAddress(); var scratchpad = ReadScratchpad(); return(scratchpad); }
byte[] ReadScratchpad() { DS2482Channel.OneWireWriteByte(FunctionCommand.READ_SCRATCHPAD); var scratchpadData = new byte[9]; for (int i = 0; i < scratchpadData.Length; i++) { scratchpadData[i] = DS2482Channel.OneWireReadByte(); } return(scratchpadData); }
public void Initialize(DS2482Channel ds2482Channel, byte[] oneWireAddress) { DS2482Channel = ds2482Channel; OneWireAddress = oneWireAddress; }
void StartTemperatureConversion() { DS2482Channel.OneWireWriteByte(FunctionCommand.CONVERT_T); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); }
public UndefinedOneWireDevice(DS2482Channel ds2482Channel, byte[] oneWireAddress) { DS2482Channel = ds2482Channel; OneWireAddress = oneWireAddress; }
public void Initialize(DS2482Channel ds2482, byte[] oneWireAddress) { throw new NotImplementedException(); }
/// <summary> /// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing search state. /// </summary> /// <returns>true : device found, ROM number in ROM_NO buffer, false : device not found, end of search</returns> public bool OneWireSearch() { int id_bit_number; int last_zero, rom_byte_number; bool id_bit, cmp_id_bit, search_direction, search_result; byte rom_byte_mask; // initialize for search id_bit_number = 1; last_zero = 0; rom_byte_number = 0; rom_byte_mask = 1; search_result = false; _crc8 = 0; // if the last call was not the last one if (!_lastDeviceFlag) { // 1-Wire reset if (!_oneWireMaster.Reset()) { // reset the search _lastDiscrepancy = 0; _lastDeviceFlag = false; _lastFamilyDiscrepancy = 0; return(false); } // issue the search command _oneWireMaster.WriteByte(0xF0); // loop to do the search do { // read a bit and its complement id_bit = _oneWireMaster.ReadBit(); cmp_id_bit = _oneWireMaster.ReadBit(); // check for no devices on 1-wire if (id_bit && cmp_id_bit) { break; } else { // all devices coupled have 0 or 1 if (id_bit != cmp_id_bit) { search_direction = id_bit; // bit write value for search } else { // if this discrepancy if before the Last Discrepancy // on a previous next then pick the same as last time if (id_bit_number < _lastDiscrepancy) { search_direction = ((_deviceAddress[rom_byte_number] & rom_byte_mask) > 0); } else { // if equal to last pick 1, if not then pick 0 search_direction = (id_bit_number == _lastDiscrepancy); } // if 0 was picked then record its position in LastZero if (!search_direction) { last_zero = id_bit_number; // check for Last discrepancy in family if (last_zero < 9) { _lastFamilyDiscrepancy = last_zero; } } } // set or clear the bit in the ROM byte rom_byte_number // with mask rom_byte_mask if (search_direction) { _deviceAddress[rom_byte_number] |= rom_byte_mask; } else { var result = (byte)~rom_byte_mask; _deviceAddress[rom_byte_number] &= result; } // serial number search direction write bit _oneWireMaster.WriteBit(search_direction); // increment the byte counter id_bit_number // and shift the mask rom_byte_mask id_bit_number++; rom_byte_mask <<= 1; // if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask if (rom_byte_mask == 0) { DS2482Channel.CalculateGlobalCrc8(_deviceAddress[rom_byte_number], _crc8); // accumulate the CRC rom_byte_number++; rom_byte_mask = 1; } } }while (rom_byte_number < 8); // loop until through all ROM bytes 0-7 // if the search was successful then if (!((id_bit_number < 65) || (_crc8 != 0))) { // search successful so set LastDiscrepancy,LastDeviceFlag,search_result _lastDiscrepancy = last_zero; // check for last device if (_lastDiscrepancy == 0) { _lastDeviceFlag = true; } search_result = true; } } // if no device found then reset counters so next 'search' will be like a first if (!search_result || _deviceAddress[0] == 0) { _lastDiscrepancy = 0; _lastDeviceFlag = false; _lastFamilyDiscrepancy = 0; search_result = false; } return(search_result); }