Basic ExampleΒΆ

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

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

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

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

    //Prep USBCSwitch for testing
    cswitch.usb.setPortDisable(0);
    cswitch.mux.setEnable(false);
    cswitch.mux.setChannel(0);

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

    //Ready for testing
    //Enable Port AND Mux
    cswitch.usb.setPortEnable(0);
    cswitch.mux.setEnable(true);

    ////////////
    //Do Stuff on Mux Channel 0
    ////////////

    cswitch.mux.setChannel(1);

    ////////////
    //Do Stuff on Mux Channel 1
    ////////////

    cswitch.mux.setChannel(2);

    ////////////
    //Do Stuff on Mux Channel 2
    ////////////

    cswitch.mux.setChannel(3);

    ////////////
    //Do Stuff on Mux Channel 3
    ////////////

    //Finished with testing.
    //De-initialize.
    cswitch.usb.setPortDisable(0);
    cswitch.mux.setEnable(false);

    //Disconnect
    cswitch.disconnect();
 }