This documentation explains how to use the MitoCANdria Java API to control and monitor your MitoCANdria device. The example demonstrates basic channel operations including reading current/voltage, enabling/disabling channels, and setting voltage levels.
The MitoCANdria class implements AutoCloseable, allowing use of try-with-resources for automatic resource cleanup. The constructor parameter (1) represents the device ID.
Available Channels
The API provides several predefined channels:
MITOCANDRIA_CHANNEL_USB1: USB Port 1
MITOCANDRIA_CHANNEL_USB2: USB Port 2
MITOCANDRIA_CHANNEL_5VA: 5V Rail A
MITOCANDRIA_CHANNEL_5VB: 5V Rail B
MITOCANDRIA_CHANNEL_ADJ: Adjustable Voltage Channel
API Operations
1. Reading Current
mito.getChannelCurrent(MitoCANdria.MITOCANDRIA_CHANNEL_USB1).ifPresentOrElse( current ->System.out.println("USB1 current: "+ current +" A"), () ->System.out.println("Couldn't get USB1 current") );
Uses getChannelCurrent() to read current draw from a channel
Returns an Optional containing the current in amperes
Uses ifPresentOrElse() for handling both successful and failed readings
2. Reading Voltage
mito.getChannelVoltage(MitoCANdria.MITOCANDRIA_CHANNEL_5VA).ifPresentOrElse( voltage ->System.out.println("5VA voltage: "+ voltage +" V"), () ->System.out.println("Couldn't get 5VA voltage") );
Uses getChannelVoltage() to read voltage from a channel
Returns an Optional containing the voltage in volts