Transition Your Code to aardvark
or ni845x
Interface
The i2c
function, its object functions, and its properties will be
removed. Use the device
function with an aardvark
or ni845x
object instead.
i2c Interface | Example | |
---|---|---|
instrhwinfo | aardvarklist or ni845xlist | Discover I2C Controllers |
i2c and
fopen | aardvark and device | Connect to I2C Controller and Peripheral Device |
ni845x and device | ||
fwrite | write | Write and Read Binary or String Data |
fread | read |
Discover I2C Controllers
This example shows how to discover I2C controllers physically connected to your machine using the recommended functionality.
Functionality | Use This Instead |
---|---|
aaInfo = instrhwinfo("i2c","Aardvark"); |
aaList = aardvarklist; |
niInfo = instrhwinfo("i2c","NI845x"); |
niList = ni845xlist; |
For more information, see aardvarklist
and ni845xlist
.
Connect to I2C Controller and Peripheral Device
This example shows how to connect to an I2C controller and peripheral device and disconnect from it using the recommended functionality.
Functionality | Use This Instead |
---|---|
a = i2c("Aardvark",0,80);
fopen(a) |
a = aardvark(aaList.SerialNumber(1)); d = device(a,I2CAddress=80); |
n = i2c("NI845x",0,80);
fopen(n) |
n = ni845x(niList.SerialNumber(1)); d = device(n,I2CAddress=80); |
fclose(a)
delete(a)
clear a Same
for object | clear d clear a Same
for object |
The fopen
function is not available in the updated interface.
The object creation functions aardvark
,
ni845x
, and device
create the object
and connect the object to the I2C controller or peripheral device.
The fclose
function is not available in the updated
interface. The clear
function disconnects the objects from the
I2C controller or peripheral device when it removes the objects from the
workspace.
Write and Read Binary or String Data
These examples show how to perform a binary write and read, how to write nonterminated string data, and how to write and read fixed-length string data, using the recommended functionality.
Functionality | Use This Instead |
---|---|
% a is an i2c object fwrite(a,0:8,"uint8"); data = fread(a,8,"uint8") data = 1 2 3 4 5 6 7 8 Same
for object |
% d is a device object write(d,0:8,"uint8"); data = read(d,8,"uint8") data = 1 2 3 4 5 6 7 8 |
% a is an i2c object fwrite(a,[0 'hello'],"char"); Same
for object |
% d is a device object write(d,[0 'hello'],"char"); |
% a is an i2c object fwrite(a,0,"char"); data = fread(a,5,"char"); data = char(data)' data = 'hello' Same
for object |
% d is a device object write(d,0,"char"); data = read(d,5,"char") data = 'hello' |