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();
}
import brainstem
# For easy access to error constants
from brainstem.result import Result
from time import sleep
import sys
# Create an instance of a USBCSwitch module.
cswitch = brainstem.stem.USBCSwitch()
# Locate and connect to the first object you find on USB
result = cswitch.discoverAndConnect(brainstem.link.Spec.USB)
if result != Result.NO_ERROR:
print ("Error %d encountered connecting to BrainStem Module.\n" % (result))
sys.exit(1)
else:
print ("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 from device.
cswitch.disconnect()