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 Can I Implement the API to Write an Array of Bytes in a Single PMBus Transaction?
Rena Ayeras

Writing code on a laptop to implement API for a single PMBus transaction

Image by StockSnap via Pixabay

Question from the Customer:

I am using the Promira Serial Platform to write an array of 4 bytes of data for a single PMBus transaction. I could use some help with this. I cannot figure out how to add the length of the packet to the ps_i2c_write.

I am writing the API script in Python. The write function is part of a read operation using the PMBus protocol. Here is my code:

ps_i2c_write(channel, device, PS_I2C_NO_STOP, array('B', [pagePlusCmdCode, blockCount, pageCode, cmdCode]))

(ret, data_in, count) = ps_i2c_read(channel, device, PS_I2C_NO_FLAGS, length)

Response from Technical Support:

Thank you for your question! There are attributes about Promira Python API we will discuss. In addition, we will go over functional software examples that could be used as is, or modified as needed for your project.

Promira Python API and Arrays

There are two main differences between the Promira API documented in the user manual and the Promira Python API:

  • The "array" type is used for passing data to and from the Promira Python API.
  • Promira Python API functions can return multiple arguments on the left-hand side. This reduces the need to pass pointers to output arguments on the right-hand side of API functions.

There are a variety of ways to call API functions that have array arguments:

  • All arrays can be passed into the API as an ArrayType object or as a tuple (array, length), where array is an ArrayType object and length is an integer. The user-specified length would then serve as the length argument to the API function. If only the array is provided, the array's intrinsic length is used as the argument to the underlying API function.
  • The ability to pass in a pre-allocated array along with a separate length allows the performance-minded programmer to use a single array for repeated calls to the API, simply changing the contents of the array and/or the specified length as needed.
  • Additionally, for arrays that are filled by the API function, an integer can be passed in place of the array argument and the API will automatically create an array of that length. All output arrays, whether passed in or generated, are passed back in the returned tuple.
  • The calling convention for each API function is documented in the comments of the py and promact_is_py.py files. We recommend reviewing the examples within the API package to see their specific implementations.

Functional API Examples

The Promira Software API supports three platforms (Windows, Linux, and Mac) several languages (C, Python, C#, and VB) and examples are free for downloading. For more information about each function, refer to  API Documentation.

The i2c_eeprom and spi_eeprom scripts could be helpful for your project:

  • i2c_eeprom - read from or write to an I2C serial EEPROM
  • spi_eeprom - read from or write to an SPI serial EEPROM

Note – both examples were designed to read/write to the Atmel AT25080A found on the I2C/SPI Activity Board.

Examples of the usage of i2c_eeprom.py:


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.