# B15F in b15f::b15f - Rust
Structure representing the driver for the board 15
Keywords: rust, rustlang, rust-lang, B15F

# Struct b15f::b15f::B15F

source · [−]

    pub struct B15F { /* private fields */ }

Expand description

Structure representing the driver for the board 15

## Implementations

source

### impl B15F

source

#### pub fn new() -> Result<B15F, Error>

Creates a new instance of the B15

This function will establish a connection to a connected B15 and return a handle to interact with it. Only one such instance should exist per program; calling `B15F::new()` more than once might lead to unexpected behaviour.

##### Returns

A new B15F object is returned. It contains an already active USART connection, so calling this function multiple times will create an Error

##### Errors

An `error::Error` is generated if the connection to the board cannot be established, or if testing of that connection fails.

##### Examples

    use b15f::B15F;

    let drv = B15F::new().unwrap();

source

#### pub fn reconnect(&mut self) -> Result<(), Error>

Tries to reestablish a connection to the B15

source

#### pub fn self_test(&mut self) -> Result<(), Error>

Enables the self test mode of the B15

IMPORTANT: Nothing must be connected to the B15 during this self check routine.

##### Errors

This function returns an `error::Error` when communication with the board or the self check fails.

source

#### pub fn digital_write<const PORT: usize>(
&mut self,
value: u8
) -> Result<(), Error>

Sets the value of the specified port

##### Errors

`PORT` can either be 0 or 1, other values will cause a compile-time error. Otherwise an `error::Error` is generated if communication with the B15 fails.

##### Examples

    use b15f::B15F;

    fn main() -> Result<(), String> {
    	let mut drv = B15F::new()?;

    	drv.digital_write::<0>(0xFF)?;		// Turn on all bits of port 0
    	drv.digital_write::<1>(0x0F)?;		// Turn on bits 0-4 of port 1

    	// drv.digital_write::<2>(0xFF);	// Compiler error

    	Ok(())
    }

source

#### pub fn digital_read<const PORT: usize>(&mut self) -> Result<u8, Error>

Reads the value of the specified port

##### Errors

`PORT` can either be 0 or 1, other values will cause a compile-time error. Otherwise an `error::Error` is generated if communication with the B15 fails.

##### Examples

    use b15f::B15F;

    fn main() -> Result<(), String> {
    	let mut drv = B15F::new()?;

    	let _ = drv.digital_read::<0>()?;		// Read inputs of port 0
    	let _ = drv.digital_read::<1>()?;		// Read inputs of port 1

    	// drv.digital_read::<2>();				// Compiler error

    	Ok(())
    }

source

#### pub fn read_dip_switch(&mut self) -> Result<u8, Error>

Reads the value of the DIP switch (S7)

##### Returns

A bitfield representing the value of all 8 DIP switches. The least significant bit represents switch 1.

##### Errors

When communication with the board fails an `error::Error` is returned.

##### Example

    use b15f::B15F;

    fn main() -> Result<(), String> {
    	let mut drv = B15F::new()?;

    	println!("{}", drv.read_dip_switch()?);

    	Ok(())
    }

source

#### pub fn get_board_info(&mut self) -> Result<Vec<String>, Error>

Yields information about the installed firmware on the B15

Returns an array of strings, where each string contains a piece of information stored on the B15

##### Returns

A list of strings where each string contains a piece of information about the board. What string contains what information is determined, but not explicitly listed.

##### Errors

An `error::Error` is generated if the communication with the board fails.

##### Examples

    use b15f::B15F;

    let mut drv = B15F::new().unwrap();

    // Print each bit of information on a new line
    drv.get_board_info()
    	.unwrap()
    	.iter()
    	.for_each(|info| println!("{info}"));

source

#### pub fn discard(&mut self) -> Result<(), Error>

Clears data in the USART buffers on this device and on the B15

source

#### pub fn test_int_conv(&mut self) -> Result<(), Error>

Test the integer conversion of the USART connection

##### Errors

If an error occurs in the conversion or the communication with the board, an `error::Error` will be returned.

source

#### pub fn test_connection(&mut self) -> Result<(), Error>

Tests the connetion to the B15

To test the connection a `Request::Test` request will be sent to the board together with a randomly generated value. If the board returns that value the connection is working correctly.

##### Errors

An `error::Error` is returned if the test fails, or if the communication itself fails.

##### Examples

    use b15f::B15F;

    fn main() {
    	let mut drv = B15F::new().unwrap();

    	if let Err(err) = drv.test_connection() {
    		panic!("Connection is not working: {err}");
    	}
    }

## Trait Implementations

source

### impl Debug for B15F

source

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

## Auto Trait Implementations

### impl !RefUnwindSafe for B15F

### impl Send for B15F

### impl !Sync for B15F

### impl Unpin for B15F

### impl !UnwindSafe for B15F

## Blanket Implementations

source

### impl<T> Any for Twhere
T: 'static + ?Sized,

source

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source

### impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source

### impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

### impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source

### impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source

### impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

### impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,

#### fn vzip(self) -> V