I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Do I Quickly Resume Using the Aardvark I2C/SPI Host Adapter when the Application is Restarted?
Rena Ayeras

Question from the Customer:

I am writing a program to detect multiple Aardvark I2C/SPI Host Adapters and connect to them.

I want to ensure that when the application fails and is restarted, it can connect to the Aardvark adapters that were open and working. This is where I am having issues:

  • If I write some buggy application code that quits and I rerun it to find the Aardvark adapters, I get an error that the ports are wrong.

aa_find_devices_ext(16, 16)

Out[39]: (2, array('H', [32768, 32769]), array('I', [2238942396, 2238944444]))

  • If I unplug and replug the Aardvark adapters via USB, the correct ports are identified and the Aardvark adapters function again.

aa_find_devices_ext(16, 16)

Out[40]: (2, array('H', [0, 1]), array('I', [2238942396, 2238944444]))

Here are some details about my setup:

  • I leave the I2C ports open so that any function that wants to transmit and receive over I2C does not need the operations of aa_open and aa_close.
  • The problem that I am having only occurs when I have a coding bug that results in a failed transmit or receive.

How can I guard against incorrect ports being returned? Several workstations are involved in this project. It would really save me time to not have to physically connect and reconnect every host adapter on the floor.

Response from Technical Support:

Thanks for your question! The Aardvark Software API is provided with functional examples that you can use as-is or modified as needed.  The example aadetect should be a good starting point for your project. The API function aa_find_devices_ext searches for Aardvark adapters in use and the ports to which they are connected. Here is what the code looks like in Python (other programing languages are supported):

# Find all the attached devices

(num, ports, unique_ids) = aa_find_devices_ext(16, 16)

if num > 0:

print("%d device(s) found:" % num)

# Print the information on each device

for i in range(num):

port      = ports[i]

unique_id = unique_ids[i]

# Determine if the device is in-use

inuse = "(avail)"

if (port & AA_PORT_NOT_FREE):

inuse = "(in-use)"

port  = port & ~AA_PORT_NOT_FREE

# Display device port number, in-use status, and serial number

print("    port = %d   %s  (%04d-%06d)" %  (port, inuse, unique_id // 1000000, unique_id % 1000000))

else:

print("No devices found.")

 

For more information about API code, please refer to the API Documentation section of the Aardvark I2C/SPI Host Adapter User Manual.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.

Request a Demo