3.8 Serial Port

3.8.1 @octave_serialport/configureTerminator

Function File: configureTerminator (serial, term)
Function File: configureTerminator (serial, readterm, writeterm)

Set terminator for ASCII string manipulation

Inputs

serial - serialport object
term - terminal value for both read and write
readterm = terminal value type for read data
writeterm = terminal value for written data

The terminal can be either strings "cr", "lf" (default), "lf/cr" or an integer between 0 to 255.

Outputs

None

See also: serialport.

3.8.2 @octave_serialport/flush

: data = flush (dev)
: data = flush (dev, "input")
: data = flush (dev, "output")

Flush the serial port buffers

Inputs

dev - connected serialport device

If an additional parameter is provided of "input" or "output", then only the input or output buffer will be flushed

Outputs

None

See also: serialport.

3.8.3 @octave_serialport/fprintf

Function File: numbytes = fprintf (obj, template ...)

Writes formatted string template using optional parameters to serialport instrument

Inputs

obj is a serialport object.
template Format template string

Outputs

numbytes - number of bytes written to the serial device.

3.8.4 @octave_serialport/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 serial port instrument

Inputs

obj is a serialport object.
size Number of values to read.
precision precision of data.

Outputs

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

3.8.5 @octave_serialport/fwrite

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

Writes data to serial port instrument

Inputs

obj is a serial port object.
data data to write.
precision precision of data.

Outputs

returns number of bytes written.

3.8.6 @octave_serialport/get

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

Get the properties of serialport object.

Inputs

serial - instance of octave_serialport 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_serial/set.

3.8.7 @octave_serialport/getpinstatus

Function File: status getpinstatus (serial)

Get status of serial pins

Inputs

serial - serial object

Outputs

status - a structure with the logic names of ClearToSend, DataSetReady, CarrierDetect, and RingIndicator

See also: serialport.

3.8.8 @octave_serialport/read

: data = read (dev, count)
: data = read (dev, count, precision)

Read a specified number of values from a serialport using optional precision for valuesize.

Inputs

dev - connected serialport device

count - number of elements to read

precision - Optional precision for the output data read data. Currently known precision values are uint8 (default), int8, uint16, int16, uint32, int32, uint64, uint64

Outputs

data - data read from the device

See also: serialport.

3.8.9 @octave_serialport/serialbreak

Function File: serialbreak (serial)
Function File: serialbreak (serial, time)

Send a break to the serial port

Inputs

serial - serialport object
time - number of milliseconds to break for. If not specified a value of 10 will be used.

Outputs

None

See also: serial.

3.8.10 @octave_serialport/set

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

Set the properties of serialport object.

Inputs

serial - instance of octave_serialport 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

’baudrate’

Set the baudrate of serial port. Supported values by instrument-control: 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200 and 230400. The supported baudrate of your serial port may be different.

’bytesize’

Set the bytesize. Supported values: 5, 6, 7 and 8.

’name’

Set the stored string name of the serial object.

’parity’

Set the parity value. Supported values: Even/Odd/None. This Parameter must be of type string. It is case insensitive and can be abbreviated to the first letter only

’stopbits’

Set the number of stopbits. Supported values: 1, 2.

’timeout’

Set the timeout value in tenths of a second. Value of -1 means a blocking call. Maximum value of 255 (i.e. 25.5 seconds).

’requesttosend’

Set the requesttosend (RTS) line.

’dataterminalready’

Set the dataterminalready (DTR) line.

Outputs

None

See also: @octave_serialport/-get.

3.8.11 @octave_serialport/setDTR

: setDTR (dev, true_false)

Set the state of the DTR line

Inputs

dev - connected serial device.
true_false - state to set the line.

Outputs

None

See also: serialport, getpinstatus, setRTS.

3.8.12 @octave_serialport/setRTS

: setRTS (dev, true_false)

Set the state of the RTS line

Inputs

dev - connected serial device.
true_false - state to set the line.

Outputs

None

See also: serialport, getpinstatus.

3.8.13 @octave_serialport/write

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

Writes data to serialport instrument

Inputs

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

Outputs

returns number of bytes written.

3.8.14 serialport

Loadable Function: serial = serialport ([path], [baudrate])
Loadable Function: serial = serialport ([path], [propname, propvalue])

Open serial port interface.

Inputs

path - the interface path of type String.
baudrate - the baudrate of interface.
propname,propvalue - property name/value pairs.

Known input properties:

BaudRate

Numeric baudrate value

Timeout

Numeric timeout value in seconds or -1 to wait forever

StopBits

number of stopbits to use

Parity

Parity setting ’none’, ’even’, ’odd’

DataBits

Number of bits to a byte (5 to 8)

FlowControl

Number of bits to a byte ’none’, ’hardware’, ’software’

Outputs

The serialport() shall return an instance of octave_serialport class as the result serial.

Properties

The serial object has the following public properties:

Name

name assigned to the object

Type

instrument type ’serial’ (readonly)

Port

OS specific port name (readonly)

Status

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

Timeout

timeout value used for waiting for data

NumBytesAvailable

number of bytes currently available to read (readonly)

NumBytesWritten

number of bytes written (readonly)

StopBits

number of stopbits to use

Parity

Parity setting ’none’, ’even’, ’odd’

DataBits

Number of bits to a byte (5 to 8)

BaudRate

Baudrate setting

FlowControl

Number of bits to a byte ’none’, ’hardware’, ’software’

PinStatus

current state of pins (readonly)

UserData

user defined data

3.8.15 serialportlist

Function File: list = serialportlist ()
Function File: list = serialportlist ("all")
Function File: list = serialportlist ("available")

Returns a list of all serial ports detected in the system.

Inputs

’all’ - show all serial ports (same as providing no arguments) ’available’ - show only serial ports that are available for use

Outputs

list is a string cell array of serial ports names detected in the system.

See also: instrhwinfo("serialport").