Basic ExampleΒΆ
#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 USBHub3p
aUSBHub3p hub;
//Connect to USBHub3p
aErr err = hub.discoverAndConnect(USB);
if(err == aErrNone) {
printf("Connected\r\n");
}
else {
printf("Unable to discover device\r\n");
return 1;
}
//Disable PORT
hub.usb.setPortEnable(PORT);
////////////
//Do Stuff
////////////
//Enable PORT
hub.usb.setPortDisable(PORT);
//Disconnect
hub.disconnect();
return 0
}
import brainstem
from brainstem.result import Result
import sys
PORT = 5
#Create an instance of the USBHub3p
hub = brainstem.stem.USBHub3p()
#Connect to USBHub3p
result = hub.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)
hub.usb.setPortEnable(PORT)
###########
#Do Stuff
###########
hub.usb.setPortDisable(PORT)
#Close the connection
hub.disconnect()