Main Content

instrfind

(To be removed) Read serial port objects from memory to MATLAB workspace

This serial object function will be removed in a future release. Use serialport object functions instead. For more information on updating your code, see Compatibility Considerations.

Syntax

out = instrfind
out = instrfind('PropertyName',PropertyValue,...)
out = instrfind(S)
out = instrfind(obj,'PropertyName',PropertyValue,...)

Description

out = instrfind returns all valid serial port objects as an array to out.

out = instrfind('PropertyName',PropertyValue,...) returns an array of serial port objects whose property names and property values match those specified.

out = instrfind(S) returns an array of serial port objects whose property names and property values match those defined in the structure S. The field names of S are the property names, while the field values are the associated property values.

out = instrfind(obj,'PropertyName',PropertyValue,...) restricts the search for matching property name/property value pairs to the serial port objects listed in obj.

Examples

Suppose you create the following two serial port objects on a Windows® platform.

s1 = serial('COM1');
s2 = serial('COM2');
set(s2,'BaudRate',4800)
fopen([s1 s2])

You can use instrfind to return serial port objects based on property values.

out1 = instrfind('Port','COM1');
out2 = instrfind({'Port','BaudRate'},{'COM2',4800});

You can also use instrfind to return cleared serial port objects to the MATLAB® workspace.

clear s1 s2
newobjs = instrfind
   Instrument Object Array
   Index:   Type:          Status:     Name:  
   1        serial         open        Serial-COM1
   2        serial         open        Serial-COM2

To close both s1 and s2

fclose(newobjs)

Tips

You must specify property values using the same format as the get function returns. For example, if get returns the Name property value as MyObject, instrfind will not find an object with a Name property value of myobject. However, this is not the case for properties that have a finite set of string values. For example, instrfind will find an object with a Parity property value of Even or even.

You can use property name/property value string pairs, structures, and cell array pairs in the same call to instrfind.

Version History

Introduced before R2006a

collapse all

R2021a: serial object interface will be removed

Use of this function with a serial object will be removed. To access a serial port device, use a serialport object with its functions and properties instead.

The recommended functionality has additional capabilities and improved performance. See Transition Your Code to serialport Interface for more information about using the recommended functionality.