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.

Save and Load

Using save and load

Save serial port objects to a file, just as you would any workspace variable, using the save command. For example, suppose you create the serial port object s associated with the serial port COM1, configure several property values, and perform a write and read operation.

s = serial('COM1');
s.BaudRate = 19200;
s.Tag = 'My serial object';
fprintf(s, '*IDN?')
out = fscanf(s);

To save the serial port object and the data read from the device to the file myserial.mat:

save myserial s out


To save data and event information as text to a disk file, use the record function.

You can recreate s and out in the workspace using the load command.

load myserial

Values for read only properties are restored to their default values upon loading. For example, the Status property is restored to closed. Therefore, to use s, you must connect it to the device with the fopen function. To determine if a property is read only, examine its reference pages.

Using Serial Port Objects on Different Platforms

If you save a serial port object from one platform, and then load that object on a different platform having different serial port names, you need to modify the Port property value. For example, suppose you create the serial port object s associated with the serial port COM1 on a Microsoft® Windows® platform. If you want to save s for eventual use on a Linux® platform, configure Port to an appropriate value such as ttyS0 after the object is loaded.