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