Basic ExampleΒΆ

#include <iostream>
#include "BrainStem2/BrainStem-all.h"

int main(int argc, const char * argv[]) {

    //Create an instance of a USBHub2x4 module.
    aUSBHub2x4 hub;

    //Connect to the hardware.
    err = hub.discoverAndConnect(USB);
    if (err != aErrNone) {
        printf("Error %d encountered connecting to BrainStem module\n", err);
       return 1;

    } else { printf("Connected to BrainStem module.\n"); }

    //Basic initialization (Get everything turned off).
    hub.usb.setPortDisable(0);
    hub.usb.setPortDisable(1);
    hub.usb.setPortDisable(2);
    hub.usb.setPortDisable(3);

    ////////////
    //Do Stuff: other test initialization
    ////////////

    //Ready for testing
    //Enable Port(s)
    hub.usb.setPortEnable(0);
    hub.usb.setPortDisable(1);
    hub.usb.setPortDisable(2);
    hub.usb.setPortDisable(3);

    ////////////
    //Do Stuff on Port 0
    ////////////

    hub.usb.setPortDisable(0);
    hub.usb.setPortEnable(1);
    hub.usb.setPortDisable(2);
    hub.usb.setPortDisable(3);

    ////////////
    //Do Stuff on Port 1
    ////////////

    hub.usb.setPortDisable(0);
    hub.usb.setPortDisable(1);
    hub.usb.setPortEnable(2);
    hub.usb.setPortDisable(3);

    ////////////
    //Do Stuff on Port 2
    ////////////

    hub.usb.setPortDisable(0);
    hub.usb.setPortDisable(1);
    hub.usb.setPortEnable(2);
    hub.usb.setPortDisable(3);

    ////////////
    //Do Stuff on Port 3
    ////////////

    //Finished with testing.
    //De-initialize.
    hub.usb.setPortDisable(0);
    hub.usb.setPortDisable(1);
    hub.usb.setPortDisable(2);
    hub.usb.setPortDisable(3);

    //Disconnect
    hub.disconnect();
}