Module Class

class Module

The Module class provides a generic interface to a BrainStem hardware module. The Module class is the parent class for all BrainStem modules. Each module inherits from Module and implements its hardware specific features.

Subclassed by a40PinModule, aMTMDAQ1, aMTMDAQ2, aMTMIOSerial, aMTMLoad1, aMTMPM1, aMTMRelay, aMTMStemModule, aUSBCSwitch, aUSBHub2x4, aUSBHub3c, aUSBHub3p

Public Functions

Module(const uint8_t address, const uint8_t model = 0)

Constructor. Implicitly creates a link object with no specifier. Most often objects created with this constructor will use linkDiscoverAndConnect to find and connect to a module.

Parameters:
  • address – The BrainStem network address of the module. The default address (or base address for modules that support address offsets) is defined in each module’s “Defs.h” header.

  • model – Acroname model number.

virtual ~Module(void)

Destructor.

aErr connect(const linkType type, const uint32_t serialNum)

Connect using the current link specifier.

Parameters:
  • type – - Transport on which to search for available BrainStem link modules. See the transport enum for supported transports.

  • serialNum – - Specify a serial number to connect to a specific link module. Use 0 to connect to the first link module found.

Returns:

aErrBusy - if the module is already in use.

Returns:

aErrParam - if the type is incorrect or serialNum is not specified

Returns:

aErrNotFound - if the module cannot be found.

Returns:

aErrNone If the connect was successful.

aErr connectFromSpec(const linkSpec linkSpecifier)

Connect to a link with a fully defined specifier.

Parameters:

linkSpecifier – - Connect to module with specifier.

Returns:

aErrInitialization - If there is currently no link object.

Returns:

aErrBusy - If the link is currently connected.

Returns:

aErrParam - if the specifier is incorrect.

Returns:

aErrNotFound - if the module cannot be found.

Returns:

aErrNone If the connect was successful.

aErr discoverAndConnect(linkType type, const uint32_t serialNum = 0)

A discovery-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 as the serial number will create a link to the first link module found on the specified transport. If a link module is found on the specified transport, a connection will

Parameters:
  • type – - Transport on which to search for available BrainStem link modules. See the transport enum for supported transports.

  • serialNum – - Specify a serial number to connect to a specific link module. Use 0 to connect to the first link module found.

Returns:

aErrBusy - if the module is already in use.

Returns:

aErrParam - if the transport type is undefined.

Returns:

aErrNotFound - if the module cannot be found.

Returns:

aErrNone If the connect was successful.

aErr connectThroughLinkModule(Module *pModule)

Connect using link from another Module. This member function will connect to the same BrainStem used by given Module. If a link module is found on the specified transport, a connection will

Parameters:

pModule – - Pointer to a valid Module class object.

Returns:

aErrParam - if the module is undefined.

Returns:

aErrNone - if the connect was successful.

bool isConnected(void)

Is the link connected to the BrainStem Module.

linkStatus getStatus(void)

Check the status of the BrainStem module connection.

Returns:

linkStatus (see aLink.h for status values)

aErr disconnect(void)

Disconnect from the BrainStem module.

Returns:

aErrResource - If the there is no valid connection.

Returns:

aErrConnection - If the disconnect failed, due to a communication issue.

Returns:

aErrNone If the disconnect was successful.

aErr reconnect()

Reconnect using the current link specifier.

Returns:

aErrBusy - if the module is already in use.

Returns:

aErrParam - if the specifier is incorrect.

Returns:

aErrNotFound - if the module cannot be found.

Returns:

aErrNone If the connect was successful.

Link *getLink(void) const

Get the current link object.

Returns:

The link associated with the module.

uint8_t getModuleAddress(void) const

Accessor to get the address of the BrainStem module associated with the instance on the host machine. (Not to be confused with the System entity which effects the device hardware.)

Returns:

The module address.

void setModuleAddress(const uint8_t address)

Accessor to set the address of the BrainStem module associated with the instance on the host machine. (Not to be confused with the System entity which effects the device hardware.)

Parameters:

address – The module address.

aErr getLinkSpecifier(linkSpec *spec)

Get linkSpecifier

Parameters:

spec – - allocated linkspec struct will be filled with spec.

Returns:

aErrNone - If the module does not have a spec.

aErr hasUEI(const uint8_t command, const uint8_t option, const uint8_t index, const uint8_t flags)

Queries the module to determine if it implements a UEI. Each UEI has a command, option or variant, index and flag. The hasUEI method queries for a fully specified UEI. Returns aErrNone if the variation is supported and an appropriate error if not. This call is blocking for up to the nMSTimeout period.

Parameters:
  • command – One of the UEI commands (cmdXXX).

  • option – The option or variant of the command.

  • index – The entity index.

  • flags – The flags (ueiOPTION_SET or ueiOPTION_GET).

Returns:

aErrNone - The module supports this command and access flags.

Returns:

aErrMode - The module supports the command but not the access flag.

Returns:

aErrNotFound - The module does not support the command, option, or index.

Returns:

aErrTimeout - The request timed out without a response.

Returns:

aErrConnection - There is no active link

aErr classQuantity(const uint8_t command, uint8_t *count)

Queries the module to determine how many entities of the specified class are implemented by the module. Zero is a valid return value. For example, calling classQuantity with the command parameter of cmdANALOG would return the number of analog entities implemented by the module.

Parameters:
  • command – One of UEI commands (cmdXXX).

  • count – When the request is successful count is updated with the number of entities found.

Returns:

aErrNone - Success.

Returns:

aErrTimeout - The request timed out without a response.

Returns:

aErrConnection - There is no active link.

aErr subClassQuantity(const uint8_t command, const uint8_t index, uint8_t *count)

Queries the module to determine how many subclass entities of the specified class are implemented by the module for a given entity index. This is used for entities which may be 2-dimensional. E.g. cmdMUX subclasses are the number of channels supported by a particular mux type (index); as a specific example, a module may support 4 UART channels, so subClassQuantity(cmdMUX, aMUX_UART…) could return 4. Zero is a valid return value.

Parameters:
  • command – One of the UEI commands (cmdXXX).

  • index – The entity index.

  • count – The number of subclasses found.

Returns:

aErrNone - Success.

Returns:

aErrTimeout - The request timed out waiting for response.

Returns:

aErrConnection - There is no active link.

aErr entityGroup(const uint8_t command, const uint8_t index, uint8_t *group)

Queries the module the group assigned to an entity and index. Entities groups are used to specify when certain hardware features are fundamentally related. E.g. certain hardware modules may have some digital pins associated with an adjustable voltage rail; these digitals would be in the same group as the rail. Zero is the default group.

Parameters:
  • command – One of the UEI commands (cmdXXX).

  • index – The entity index.

  • group – Upon success, group is filled with the entities group value.

Returns:

aErrNone - Success.

Returns:

aErrTimeout - The request timed out without response.

Returns:

aErrConnection - There is no active link.

aErr debug(const uint8_t *pData, const uint8_t length)

Sends a debug packet to the module containing the provided data. Modules receiving debug packets simply echo the packet back to the sender. If the round-trip is successful, the reply data will match the data sent. This method returns aErrNone when successful, if not successful, an appropriate error is returned.

Parameters:
  • pData – A pointer to an array of data to be sent in the debug packet.

  • length – The length of the data array.

Returns:

aErrNone - Success.

Returns:

aErrTimeout - Timeout occured without response.

Returns:

aErrConnection - No active link exists.

void setNetworkingMode(const bool mode)

Sets the networking mode of the module object. By default the module object is configure 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 communication with the device. If advanced networking is required the auto networking mode can be turned off.

Parameters:

mode – True/1 for Auto Networking, False/0 for manual networking