private async Task <byte> OneWireBitAsync(byte b) { var bit = b > 0 ? 0xFF : 0x00; DataWriteObject.WriteByte((byte)bit); await DataWriteObject.StoreAsync(); await DataReaderObject.LoadAsync(1); var data = DataReaderObject.ReadByte(); return((byte)(data & 0xFF)); }
private async Task <bool> TryOneWireResetAsync(string deviceId) { try { SerialPort?.Dispose(); SerialPort = await GetNewSerialPortAsync(deviceId, BaudRate.Low); DataWriteObject = DataWriterFactory(SerialPort.OutputStream); DataWriteObject.WriteByte(StartByte); await DataWriteObject.StoreAsync(); DataReaderObject = new DataReader(SerialPort.InputStream); await DataReaderObject.LoadAsync(1); var resp = DataReaderObject.ReadByte(); if (resp == (int)ResponseCode.UartNotConnected) { Debug.WriteLine("Nothing connected to UART"); return(false); } if (resp == (int)ResponseCode.NonOneWireDevice) { Debug.WriteLine("No 1-wire devices are present"); return(false); } Debug.WriteLine($"Response: {resp}"); SerialPort.Dispose(); SerialPort = await GetNewSerialPortAsync(deviceId, BaudRate.High); DataWriteObject = DataWriterFactory(SerialPort.OutputStream); DataReaderObject = DataReaderFactory(SerialPort.InputStream); return(true); } catch (Exception ex) { Debug.WriteLine($"Exception: {ex.Message}"); return(false); } }