Treehopper C# API
|
The core class for communicating with Treehopper USB boards. More...
Main components | |
ObservableCollection< Pin > | Pins [get] |
This list contains all the pins that belong to the board. More... | |
HardwareSpi | Spi [get] |
SPI module More... | |
HardwareI2C | I2c [get] |
I2C module More... | |
HardwareUart | Uart [get] |
Hardware UART supporting RS-232 and OneWire-style communication. More... | |
HardwarePwm | Pwm1 [get] |
Hardware PWM #1 More... | |
HardwarePwm | Pwm2 [get] |
Hardware PWM #2 More... | |
HardwarePwm | Pwm3 [get] |
Hardware PWM #3 More... | |
bool | Led [get, set] |
Gets or sets the LED state More... | |
bool | IsConnected [get, set] |
Get whether or not the board is connected More... | |
Pin | this[int index] [get] |
Shorthand pin accessor property More... | |
PropertyChangedEventHandler | PropertyChanged |
Occurs whenever a property changes. More... | |
async Task< bool > | ConnectAsync () |
Open the TreehopperBoard. More... | |
void | Disconnect () |
Close device More... | |
Board identity & firmware management | |
string | Name [get] |
The name of the board More... | |
string | SerialNumber [get] |
The unique serial identification string for the board. More... | |
string | VersionString [get] |
Get a string representation of the firmware version number More... | |
int | Version [get] |
Get the firmware version number More... | |
Task | UpdateDeviceNameAsync (string deviceName) |
Update the name of the device. More... | |
Task | UpdateSerialNumberAsync (string serialNumber) |
Update the serial number on the device. More... | |
void | Reboot () |
Reboots the board. More... | |
void | RebootIntoBootloader () |
Reboot the board into bootloader mode More... | |
Other components | |
static Settings | Settings [get] |
Controls the global settings used by all Treehopper libraries for this session More... | |
ParallelInterface | ParallelInterface [get] |
8080-style parallel interface More... | |
HardwarePwmManager | HardwarePwmManager [get] |
Hardware PWM manager More... | |
int | NumberOfPins = 20 [get] |
Get the number of pins of this board More... | |
IConnection | Connection [get] |
Get the Connection used by this board More... | |
PinValuesUpdatedHandler | OnPinValuesUpdated |
Event fires whenever a new pin data report comes in (i.e., when all input pins are updated) More... | |
Task | AwaitPinUpdateAsync () |
Awaits a pin update report from the board More... | |
void | Reinitialize () |
Reinitialize the board, setting all pins as high-impedance More... | |
void | Dispose () |
Close device connection and free memory. More... | |
int | CompareTo (object obj) |
Compares another Treehopper to this one. More... | |
bool | Equals (TreehopperUsb x, TreehopperUsb y) |
Determines if two Treehopper boards are the same More... | |
int | GetHashCode (TreehopperUsb board) |
Hash, obtained from the device path. More... | |
bool | Equals (TreehopperUsb other) |
Determines if another Treehopper board is the same as this one More... | |
override string | ToString () |
A human-readable string describing this instance. More... | |
override int | GetHashCode () |
Get the hash code of this board More... | |
override bool | Equals (object obj) |
Determines if another object is the same as this Treehopper board More... | |
The core class for communicating with Treehopper USB boards.
Treehopper is a USB 2.0 Full Speed device with 20 Pins — each of which can be used as an analog input, digital input, digital output, or soft-PWM output. Many of these pins also have dedicated peripheral functions for SPI, I2C, UART, and PWM.
You'll access all the pins, peripherals, and board functions through this class, which will automatically create all peripheral instances for you.
To obtain a reference to the board, use the ConnectionService.Instance.GetFirstDeviceAsync() method:
Or the ConnectionService.Instance.Boards ObservableCollection, which fires events useful for hot-plug reactions:
Before you use the board, you must explicitly connect to it by calling the ConnectAsync() method
To learn about accessing different Treehopper peripherals, visit the doc links to the relevant classes:
async Task<bool> ConnectAsync | ( | ) |
Open the TreehopperBoard.
The board must be opened before any other methods are called.
void Disconnect | ( | ) |
Close device
This will reset all pins to inputs and then disconnect from the device. It will not free memory associated with this device.
Task UpdateDeviceNameAsync | ( | string | deviceName | ) |
Update the name of the device.
deviceName | A 60-character (or fewer) string containing the new name of the device. |
While the name is immediately written to the device and the Name property is updated immediately, the changes will not take effect to other applications until the device is reset. This can be done by calling Reboot()
Task UpdateSerialNumberAsync | ( | string | serialNumber | ) |
Update the serial number on the device.
serialNumber | A 60-character (or fewer) string containing the new serial number |
While the new serial number is immediately available from the SerialNumber property, the changes will not take effect in other applications until the device is reset. This can be done by calling Reboot()
void Reboot | ( | ) |
Reboots the board.
Calling this method will automatically call the Disconnect() method, and no further communication will be possible until the board is reopened.
void RebootIntoBootloader | ( | ) |
Reboot the board into bootloader mode
Task AwaitPinUpdateAsync | ( | ) |
Awaits a pin update report from the board
void Reinitialize | ( | ) |
Reinitialize the board, setting all pins as high-impedance
void Dispose | ( | ) |
Close device connection and free memory.
int CompareTo | ( | object | obj | ) |
bool Equals | ( | TreehopperUsb | x, |
TreehopperUsb | y | ||
) |
Determines if two Treehopper boards are the same
x | The first board |
y | The second board |
int GetHashCode | ( | TreehopperUsb | board | ) |
Hash, obtained from the device path.
board | the Treehopper board to calculate the hash for |
Object.GetHashCode
bool Equals | ( | TreehopperUsb | other | ) |
Determines if another Treehopper board is the same as this one
other | The other Treehopper board to compare |
override string ToString | ( | ) |
A human-readable string describing this instance.
This is formed from the name and serial number of the device.
override int GetHashCode | ( | ) |
Get the hash code of this board
override bool Equals | ( | object | obj | ) |
Determines if another object is the same as this Treehopper board
obj | The other Treehopper board to compare |
|
get |
This list contains all the pins that belong to the board.
|
get |
SPI module
|
get |
I2C module
|
get |
Hardware UART supporting RS-232 and OneWire-style communication.
|
get |
Hardware PWM #1
|
get |
Hardware PWM #2
|
get |
Hardware PWM #3
|
getset |
Gets or sets the LED state
|
getset |
Get whether or not the board is connected
|
get |
Shorthand pin accessor property
index | The pin index to access |
This property gives you shorthand access to pins. Instead of typing
using this accessor, you can type:
We provide both accessors, because while this one is briefer, it is less intuitive.
|
get |
The name of the board
This property is set by a USB string descriptor read when the device is attached to the computer. It is available even if the device is not open.
You can set this string to whichever value you want by using the Treehopper Firmware Manager software. Once set, this property will persist, even if the device is removed from power or connected to a different computer.
This property is useful for identifying a particular Treehopper board when you have multiple boards connected to your computer, or you don't want a program communicating with the incorrect board.
|
get |
The unique serial identification string for the board.
This property is available even if the device is not opened (though on Linux, the device will be implicitly opened and then closed to read this property).
Consequently, you can use this property, or the TreehopperUsb.Name property, to screen the devices your application attempts to connect to, without interfereing with other applications.
You can write a new serial number to the board by calling UpdateSerialNumber().
|
get |
Get a string representation of the firmware version number
|
get |
Get the firmware version number
Controls the global settings used by all Treehopper libraries for this session
This is a static property. Access it through the TreehopperUsb class. As an example:
8080-style parallel interface
Hardware PWM manager
|
get |
Get the number of pins of this board
|
get |
Get the Connection used by this board
PropertyChangedEventHandler PropertyChanged |
Occurs whenever a property changes.
PinValuesUpdatedHandler OnPinValuesUpdated |
Event fires whenever a new pin data report comes in (i.e., when all input pins are updated)
While each pin can be configured to fire events when it changes, if you're dealing with a large number of input pins, you may get better performance by subscribing to this event alone.