diff --git a/examples/basic/main.rs b/examples/basic/main.rs index f396bb2..fb83144 100644 --- a/examples/basic/main.rs +++ b/examples/basic/main.rs @@ -2,15 +2,19 @@ use obd2::commands::Obd2DataRetrieval; use std::time; -fn main() { +fn main() -> Result<(), obd2::Error> { env_logger::init(); - let mut device: obd2::Obd2 = obd2::Obd2::default(); + let mut device: obd2::Obd2> = obd2::Obd2::new( + obd2::device::Elm327::new( + obd2::device::FTDIDevice::new()? + )? + )?; println!("VIN: {:?}", device.get_vin()); - for s in device.get_service_1_pid_support_1().unwrap().iter() { + for s in device.get_service_1_pid_support_1()?.iter() { println!("PID support ($01-$20): {:08X}", s); } - for s in device.get_service_1_pid_support_2().unwrap().iter() { + for s in device.get_service_1_pid_support_2()?.iter() { println!("PID support ($21-$40): {:08X}", s); } @@ -47,4 +51,6 @@ fn main() { device.get_throttle_position() ); } + + Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 7fc066a..10bc301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,14 +6,20 @@ //! //! # Usage //! ``` -//! use obd2::{commands::Obd2DataRetrieval, device::Elm327, Obd2}; +//! use obd2::{commands::Obd2DataRetrieval, device::{Elm327, FTDIDevice}, Obd2}; //! //! fn main() -> Result<(), obd2::Error> { -//! let mut device = Obd2::::default(); +//! let mut device = Obd2::>::new(Elm327::new(FTDIDevice::new()?)?)?; //! println!("VIN: {}", device.get_vin()?); //! Ok(()) //! } //! ``` +//! +//! alternatively, you could use a serial port provided by your operating system such as +//! /dev/ttyUSB0 on unix-like systems +//! ``` +//! let mut device = Obd2::>::new(Elm327::new(SerialPort::new("/dev/ttyUSB0")?)?)?; +//! ``` #![forbid(unsafe_code)] #![warn(missing_docs)]