3.4 I2C

3.4.1 @octave_i2c/fclose

Function File: res = fclose (obj)

Closes I2C connection obj

3.4.2 @octave_i2c/fopen

Function File: res = fopen (obj) (dummy)

Opens I2C connection obj

This currently is a dummy function to improve compatibility to MATLAB

3.4.3 @octave_i2c/fread

Function File: data = fread (obj)
Function File: data = fread (obj, size)
Function File: data = fread (obj, size, precision)
Function File: [data,count] = fread (obj, ...)
Function File: [data,count,errmsg] = fread (obj, ...)

Reads data from I2C instrument

Inputs

obj is a I2C object.
size Number of values to read. (Default: 100).
precision precision of data.

Outputs

data data values.
count number of values read.
errmsg read operation error message.

3.4.4 @octave_i2c/fwrite

Function File: numbytes = fwrite (obj, data)
Function File: numbytes = fwrite (obj, data, precision)

Writes data to I2C instrument

Inputs

obj is a I2C object.
data data to write.
precision precision of data.

Outputs

returns number of bytes written.

3.4.5 @octave_i2c/get

Function File: struct = get (i2c)
Function File: field = get (i2c, property)

Get the properties of i2c object.

Inputs

i2c - instance of octave_i2c class.

property - name of property.

Outputs

When property was specified, return the value of that property.
otherwise return the values of all properties as a structure.

See also: @octave_i2c/set.

3.4.6 @octave_i2c/set

Function File: set (obj, property,value)
Function File: set (obj, property,value,…)

Set the properties of i2c object.

Inputs

obj - instance of octave_i2c class.
property - name of property.

If property is a cell so must be value, it sets the values of all matching properties.

The function also accepts property-value pairs.

Properties

’name’

Set the name for the i2c socket.

’remoteaddress’

Set the remote address for the i2c socket.

Outputs

None

See also: @octave_i2c/get.

3.4.7 i2c

Loadable Function: i2c = i2c ([port_path], [address])

Open i2c interface.

Inputs

port_path - the interface device port/path of type String. If omitted defaults to ’/dev/i2c-0’.
address - the slave device address. If omitted must be set using i2c_addr() call.

Outputs

i2c - An instance of octave_i2c class.

Properties

The i2c object has the following properties:

name

Name of the object

remoteaddress

the slave device address

port

The interface driver port (readonly)

3.4.8 i2c_addr

Loadable Function: i2c_addr (i2c, address)
Loadable Function: addr = i2c_addr (i2c)

Set new or get existing i2c slave device address.

Inputs

i2c - instance of octave_i2c class.
address - i2c slave device address of type Integer. The address is passed in the 7 or 10 lower bits of the argument.

Outputs

addr - If address parameter is omitted, the i2c_addr() shall return current i2c slave device address.

3.4.9 i2c_close

Loadable Function: i2c_close (i2c)

Close the interface and release a file descriptor.

Inputs

i2c - instance of octave_i2c class.

Outputs

None

3.4.10 i2c_read

Loadable Function: [data, count] = i2c_read (i2c, n)

Read from i2c slave device.

Inputs

i2c - instance of octave_i2c class.
n - number of bytes to attempt to read of type Integer.

Outputs

The i2c_read() shall return number of bytes successfully read in count as Integer and the bytes themselves in data as uint8 array.

3.4.11 i2c_write

Loadable Function: n = i2c_write (i2c, data)

Write data to a i2c slave device.

Inputs

i2c - instance of octave_i2c class.
data - data, of type uint8, to be written to the slave device.

Outputs

Upon successful completion, i2c_write() shall return the number of bytes written as the result n.