Main Content

Configure and Return Properties

Establish the desired instrument object behavior by configuring property values. You can configure property values using dot notation or by specifying name-value arguments during object creation. You can return property values using dot notation.

Set Property Values During Object Creation and View Properties

You can set certain property values using name-value arguments during instrument object creation. For example, set the serialport object property Timeout during object creation.

s = serialport("COM4",9600,Timeout=20)
s = 

  Serialport with properties:

                 Port: "COM4"
             BaudRate: 9600
    NumBytesAvailable: 0

  Show all properties, functions

You can set multiple property values during object creation using the name-value argument syntax.

Once the instrument object is created, you can return properties. For example, the properties for the serialport object s are shown as follows. Click Show all properties to view all properties of s and their values.

s = 

  Serialport with properties:

                 Port: "COM4"
             BaudRate: 9600
    NumBytesAvailable: 0

  Show all properties, all methods

                      Port: "COM4"
                  BaudRate: 9600
         NumBytesAvailable: 0

                 ByteOrder: "little-endian"
                  DataBits: 8
                  StopBits: 1
                    Parity: "none"
               FlowControl: "none"
                   Timeout: 20
                Terminator: "LF"

     BytesAvailableFcnMode: "off"
    BytesAvailableFcnCount: 64
         BytesAvailableFcn: []
           NumBytesWritten: 0

          ErrorOccurredFcn: []
                  UserData: []

You can find a full list of properties, which ones you can configure, and how to configure them in the respective interface object documentation:

Set Property Values

To display the current value for one property, use dot notation with the property name.

s.Timeout
ans =

    20

Configure property values using dot notation.

device.ByteOrder = "big-endian"

You can also configure certain properties during object creation using optional name-value arguments.

device = serialport("COM4",9600,DataBits=5);

Use configureTerminator to set the Terminator property. This property cannot be set using name-value arguments or dot notation.

configureTerminator(device,"CR/LF")

Callback properties must be configured using the configureCallback function. Use configureCallback to set the BytesAvailableFcnMode, BytesAvailableFcn, and BytesAvailableFcnCount properties. These properties cannot be set using name-value arguments or dot notation.

configureCallback(device,"terminator",@callbackFcn)
configureCallback(device,"byte",50,@callbackFcn)

See Also

| | | |

Related Topics