User`s manual

viii Contents
8
Serial Port I/O
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
What Is MATLAB’s Serial Port Interface? . . . . . . . . . . . . . . . . . 8-2
Supported Serial Port Interface Standards . . . . . . . . . . . . . . . . 8-2
Supported Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Using the Examples with Your Device . . . . . . . . . . . . . . . . . . . . 8-3
Overview of the Serial Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
What Is Serial Communication? . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
The Serial Port Interface Standard . . . . . . . . . . . . . . . . . . . . . . 8-4
Connecting Two Devices with a Serial Cable . . . . . . . . . . . . . . . 8-5
Serial Port Signals and Pin Assignments . . . . . . . . . . . . . . . . . . 8-6
Serial Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-11
Finding Serial Port Information for Your Platform . . . . . . . . . 8-15
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17
Getting Started with Serial I/O . . . . . . . . . . . . . . . . . . . . . . . . 8-18
Example: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-18
The Serial Port Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19
Configuring and Returning Properties . . . . . . . . . . . . . . . . . . . 8-20
Creating a Serial Port Object . . . . . . . . . . . . . . . . . . . . . . . . . 8-24
Configuring Properties During Object Creation . . . . . . . . . . . 8-25
The Serial Port Object Display . . . . . . . . . . . . . . . . . . . . . . . . . 8-25
Creating an Array of Serial Port Objects . . . . . . . . . . . . . . . . . 8-26
Connecting to the Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-27
Configuring Communication Settings . . . . . . . . . . . . . . . . . . 8-28
Writing and Reading Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-29
Example: Introduction to Writing and Reading Data . . . . . . . 8-29
Controlling Access to the MATLAB Command Line . . . . . . . . 8-29
Writing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-31
Reading Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36
Example: Writing and Reading Text Data . . . . . . . . . . . . . . . . 8-42
Example: Parsing Input Data Using strread . . . . . . . . . . . . . . 8-44
Example: Reading Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . 8-45