Basic ExampleΒΆ
This simple example shows briefly how instantiate, connect to, disable and re-enable a port on the USBHub3c. There are multiple examples shipped with the BrainStem Development Kit (BDK) download.
#include <iostream>
#include "BrainStem2/BrainStem-all.h"
static const uint8_t PORT = 5;
int main(int argc, const char * argv[]) {
//Create an instance of the USBHub3c
aUSBHub3c device;
//Connect to USBHub3c
aErr err = device.discoverAndConnect(USB);
if(err == aErrNone) {
printf("Connected\r\n");
}
else {
printf("Unable to discover device\r\n");
return 1;
}
//Disable PORT
device.hub.port[PORT].setEnabled(0);
////////////
//Do Stuff
////////////
//Enable PORT
device.hub.port[PORT].setEnabled(1);
//Disconnect
device.disconnect();
return 0
}
import brainstem
from brainstem.result import Result
import sys
PORT = 5
#Create an instance of the USBHub3c
device = brainstem.stem.USBHub3c()
#Connect to USBHub3c
result = device.discoverAndConnect(brainstem.link.Spec.USB)
if result == Result.NO_ERROR:
print("Connected\r\n");
else:
print("Unable to discover device\r\n");
sys.exit(1)
# Disable Port
device.hub.port[PORT].setEnabled(0)
###########
# Do Stuff
###########
# Enable Port
device.hub.port[PORT].setEnabled(1)
#Close the connection
device.disconnect()