Module¶
A module that provides base classes for BrainStem Modules and Entities.
The Module and Entity classes are designed to be extended for specific types of BraiStem Modules and Entities. For more information about Brainstem Modules and Entities, please see the Terminology section of the Acroname BrainStem Reference
- class brainstem.module.Entity(module, command, index)[source]¶
Base class for BrainStem Entity.
Provides the default implementation for a functional entity within the BrainStem. This can include IO like GPIOs, Analogs etc. For a more detailed description of Entities see the Terminology section of the brainstem reference for more information.
- bytes_to_string(result)[source]¶
Helper function for UEIBytes to convert byte array value to a string
- call_UEI(option)[source]¶
Result.error: Call a set UEI on this entity.
- Parameters:
option (int) – The command option.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- check_UEIBytes(result, valuesize)[source]¶
Helper function for UEIBytes get checks, specifically checking and fixing value sizes
- Parameters:
result (Result) – The Result object from a get_UEIBytes
valuesize (int) – The base value size of the elements in the set of bytes, 1 = uint8, 2 = uint16, 4 = uint32
- Returns:
- Returns a result object, whose value is set,
or with the requested value when the results error is set to NO_ERROR
- Return type:
- property command¶
Return the entitiy command.
- Type:
int
- drain_UEI(option)[source]¶
drain UEI packets matchin option.
- Parameters:
option (int) – The command option.
- Returns:
- Returns a result object, whose value is the number of
packets drained, and the error value set to NO_ERROR
- Return type:
- get_UEI(option)[source]¶
Result.error: Get a UEI value.
- Parameters:
option (int) – The command option.
- Returns:
- Returns a result object, whose value is set,
or with the requested value when the results error is set to NO_ERROR
- Return type:
- get_UEIBytes(option)[source]¶
Get a UEI Bytes 8 bit value.
- Parameters:
option (int) – The command option.
- Returns:
- Returns a result object, whose value is set,
or with the requested value when the results error is set to NO_ERROR
- Return type:
- get_UEI_with_param(option, param)[source]¶
Result.error: Get a UEI value based on a parameter.
- Parameters:
option (int) – The command option.
param (byte) – The command parameter
- Returns:
- Returns a result object, whose value is set,
on with the requested value when the results error is set to NO_ERROR
- Return type:
- property index¶
Return the entity index
- Type:
int
- prep_UEIBytes(buffer, valuesize)[source]¶
Helper function for UEIBytes set which converts base type to single byte tuple
- Parameters:
buffer (tuple) – An array of values to be converted to single bytes
valuesize (int) – The base value size of the elements in the set of bytes, 1 = uint8, 2 = uint16, 4 = uint32
- Returns:
Returns a tuple
- Return type:
- set_UEI16(option, value)[source]¶
Result.error: Call a set UEI with short param on this entity.
- Parameters:
option (int) – The command option.
value (short) – The short parameter to send.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- set_UEI32(option, value)[source]¶
Result.error: Call a set UEI with int param on this entity.
- Parameters:
option (int) – The command option.
value (int) – The int parameter to send.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- set_UEI32_with_subindex(option, subindex, value)[source]¶
Result.error: Call a set UEI with a subindex.
- Parameters:
option (int) – The command option.
subindex (byte) – The subindex of the entity.
param (byte) – The byte parameter to send.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- set_UEI8(option, value)[source]¶
Result.error: Call a set UEI with byte param on this entity.
- Parameters:
option (int) – The command option.
value (byte) – The byte parameter to send.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- set_UEI8_with_subindex(option, subindex, value)[source]¶
Result.error: Call a set UEI with a subindex.
- Parameters:
option (int) – The command option.
subindex (byte) – The subindex of the entity.
param (byte) – The byte parameter to send.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- set_UEIBytes(option, buffer)[source]¶
Result.error: Call a set UEI with buffer and length of buffer on this entity.
- Parameters:
option (int) – The command option.
buffer (byte array) – The buffer to be sent
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- class brainstem.module.Module(address, enable_auto_networking=True, model=0)[source]¶
Base class for BrainStem Modules.
Provides default implementations for connecting and disconnecting from BrainStem modules via the module’s serial number, a Spec object or through another module.
- property address¶
Return the Brainstem module address.
- Type:
int
- property bAutoNetworking¶
Return the current networking mode.
- Type:
bool
- connect(transport, serial_number)[source]¶
Result.error: Connect to a Module with a transport type and serial number.
- Parameters:
transport (Spec.transport) – The transport to connect over.
serial_number (int) – Serial number of the module.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- connectFromSpec(spec)[source]¶
Result.error: Connect to a BrainStem module with a Spec.
- Parameters:
spec (Spec) – The specifier for the connection.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- connectThroughLinkModule(module)[source]¶
Result.error: Connect to network module.
Connects to a Brainstem module on a BrainStem network, through the module given as an argument. The module passed in must have an active valid connection.
- Parameters:
module (Module) – The brainstem module to connec through.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- discoverAndConnect(transport, serial_number=None)[source]¶
Discover and connect from the Module level.
A disover-based connect. This member function will connect to the first available BrainStem found on the given transport. If the serial number is passed, it will only connect to the module with that serial number. Passing 0 or None as the serial number will create a link to the first link module found on the specified transport.
- Parameters:
transport (int) – The module address to switch to for this module instance.
serial_number (int) – The module serial_number to look for.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- getStatus()[source]¶
Returns the status of the BrainStem connection
See brainstem.link.Status for the possiable states.
- property link¶
return the current link or None.
- Type:
Link
- property model¶
returns the model number of the object.
- Type:
Model
- setModuleAddress(address)[source]¶
Set the address of the module object.
This method changes the local address of the module, not of the device. It is possible to set the module address of the device via system.setModuleSoftwareOffset().
- Parameters:
address (int) – The module address to switch to for this module instance.
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error
- setNetworkingMode(mode)[source]¶
Set the networking mode of the module object.
By default the module object is configured to automatically adjust its address based on the devices current module address. So that, if the device has a software or hardware offset it will still be able to communicate with the device. If advanced networking is required the auto networking mode can be turned off.
- Parameters:
mode (bool) – True or 1 = Auto networking False or 0 = Manual networking
- Returns:
Returns an error result from the list of defined error codes in brainstem.result
- Return type:
Result.error