3.5 Modbus

3.5.1 @octave_modbus/get

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

Get the properties of modbus object.

Inputs

dev - instance of octave_modbus 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_modbus/set.

3.5.2 @octave_modbus/maskWrite

: data = maskWrite (dev, address, andmask, ormask)
: data = maskWrite (dev, address, andmask, ormask, serverid)

Read holding register at address from modbus device dev apply masking and write the change data.

writeregister value = (readregister value AND andMask) OR (orMask AND (NOT andMask))

Inputs

dev - connected modbus device

address - address to read from.

andmask - AND mask to apply to the register

ormask - OR mask to apply to the register

serverId - address to send to (0-247). Default of 1 is used if not specified.

Outputs

data - data read from the device

See also: modbus.

3.5.3 @octave_modbus/read

: data = read (dev, target, address)
: data = read (dev, target, address, count)
: data = read (dev, target, address, count, serverId, precision)

Read data from modbus device dev target target starting at address address.

Inputs

dev - connected modbus device

target - target type to read. One of ’coils’, ’inputs’, ’inputregs’ or ’holdingregs’

address - address to start reading from.

count - number of elements to read. If not provided, count is 1.

serverId - address to send to (0-247). Default of 1 is used if not specified.

precision - Optional precision for how to interpret the read data. Currently known precision values are uint16 (default), int16, uint32, int32, uint64, uint64, single, double.

Outputs

data - data read from the device

See also: modbus.

3.5.4 @octave_modbus/set

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

Set the properties of modbus object.

Inputs

obj - instance of octave_modbus 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 stored string name of the object.

’Timeout’

Set the timeout value.

’Numretries’

Set the numretries value.

’ByteOrder’

Set the byteorder value

’WordOrder’

Set the wordorder value

’UserData’

Set the userdata value

Outputs

None

See also: @octave_modbus/get.

3.5.5 @octave_modbus/write

: write (dev, target, address, values)
: read (dev, target, address, values, serverId, precision)

Write data data to modbus device dev target target starting at address address.

Inputs

dev - connected modbus device

target - target type to read. One of ’coils’ or ’holdingregs’

address - address to start reading from.

data - data to write.

serverId - address to send to (0-247). Default of 1 is used if not specified.

precision - Optional precision for how to interpret the write data. Currently known precision values are uint16 (default), int16, uint32, int32, uint64, uint64, single, double.

Outputs

None

See also: modbus.

3.5.6 @octave_modbus/writeRead

: data = writeRead (dev, writeAddress, values, readAddress, readcount)
: data = writeRead (dev, writeAddress, values, readAddress, readcount, serverId)
: data = writeRead (dev, writeAddress, values, writePrecision, readAddress, readCount, readPrecision)

Write data values to the modbus device dev holding registers starting at address writeAddress and then read readCount register values starting at address readAddress.

Inputs

dev - connected modbus device

writeAddress - address to start writing to.

values - data to write to the device.

readAddress - address to start reading from.

readCount - number of elements to read.

serverId - address to send to (0-247). Default of 1 is used if not specified.

precision - Optional precision for how to interpret the read data. Currently known precision values are uint16 (default), int16, uint32, int32, uint64, uint64, single, double.

Outputs

data - data read from the device

See also: modbus.

3.5.7 modbus

Loadable Function: dev = modbus ('tcpip', deviceaddress)
Loadable Function: dev = modbus ('tcpip', deviceaddress, remoteport)
Loadable Function: dev = modbus ('tcpip', deviceaddress, name, value)
Loadable Function: dev = modbus ('serialrtu', serialport)
Loadable Function: dev = modbus ('serialrtu', serialport, name, value)

Open modbus interface using a specified transport of ’tcpip’ or ’serialrtu’.

Inputs

deviceaddress - the device ip address of type String.
remoteport - the device remote port number. If not specified, a default of 502 will be used.
name, value - Optional name value pairs for setting properties of the object.
serialport - the name of the serial port to connect to. It must be specified when transport is ’serialrtu’.

Common Input Name, Value pairs

Timeout

timeout value used for waiting for data

NumRetries

number of retries after a timeout

UserData

Additional data to attach to the object

Serial RTU Input Name, Value pairs

BaudRate

Baudrate for the serial port

DataBits

number of databits for serial port

Parity

Parity for serial port (’odd’, ’even’ or ’none’)

StopBits

number of stopbits for serial port

Outputs

The modbus() shall return instance of octave_modbus class as the result modbus.

Properties

The modbus object has the following public properties:

Name

name assigned to the modbus object

Type

instrument type ’modbus’ (readonly)

Port

Remote port number or serial port name (readonly)

DeviceAddress

Device address if transport was ’tcpip’ (readonly)

Status

status of the object ’open’ or ’closed’ (readonly)

Timeout

timeout value used for waiting for data

NumRetries

number of retries after a timeout

UserData

Additional data to attach to the object