This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

getFreeResourceSlot

Get first free slot of resource

Syntax

slot = getFreeResourceSlot(arduinoObj, resourceName)

Description

example

slot = getFreeResourceSlot(arduinoObj, resourceName) returns the first available slot or index in a continuous array allocated for the given resource. The slot count starts from 1.

Examples

collapse all

Get the free resource slot allocated to a servo object on an Arduino® Uno. This function runs only in the MATLAB Add-On Class of a custom Arduino add-on library.

Create a servo object.

a = arduino();
s1 = servo(a,'D7');

Get free resource slot on the servo object. In this example, the add-on object of the Arduino object is defined as obj in the Constructor. The resource name for a servo object is 'Servo'.

arduinoObj = obj.Parent;
slot1 = getFreeResourceSlot(arduinoObj,'Servo')
slot1 = 
	1

Create a second servo object to see the free resource slot.

s2 = servo(a,'D5');
slot2 = getFreeResourceSlot(arduinoObj,'Servo')
slot2 = 
	2

Clear the first servo object and create a third servo object to see if the first slot is cleared. Make sure to release hardware resources in your Destructor.

clear('s1')
s3 = servo(a,'D4');
slot3 = getFreeResourceSlot(arduinoObj,'Servo')
slot3 = 
	1

Since the slot number is 1 instead of 3, the first slot has been cleared.

Input Arguments

collapse all

Arduino object, specified as an object that is an internal variable called from within classes that derive from matlabshared.addon.LibraryBase.

Name of resource, specified as a character vector.

Output Arguments

collapse all

Slot or index number of the next free resource, returned as a double.

Introduced in R2015b