Contents

  1. Introduction
  2. Step by step guide
    2.1  Obtaining the COM port identifier
    2.2  Creating a serial connection
    2.3  Sending commands and receiving responses
    2.4  Closing serial connection
  3. Example Script
  4. Download example

 

1. Introduction

This user guide aims to provide a starting point on how to communicate with the device using a serial connection and MATLAB on a host running Windows 10.

MATLAB is a multi-paradigm numerical computing environment and proprietary programming language developed by Mathworks.

Reader will benefit from previous experience in MATLAB, although no knowledge of MATLAB is required. The steps described in this guide could be easily applied to other operating systems.

This document includes a step by step guide and example script.

2. How To

2.1  Obtaining the COM port identifier

Ensure the device is plugged to one of the USB ports of the Windows host. On the host, open the Device Manager. One way of achieving this is using the search functionality of the taskbar as described in the image below:

Opening the Device Manager will show a window with the different peripherals connected to your machine, expand the Ports (COM & LPT) node and the COM port identifier for the device will appear:

The COM port identifier is not fixed by default and the device might enumerate on different COM ports on different machines, for this example, the COM port identifier is COM3.

This identifier will be used in the next section to create a serial connection to the device using MATLAB.

 

2.1 Creating a serial connection

Open MATLAB and create a new script by pressing the New Script button in the Home tab:

This creates a new window where to write the code to interact with the device. Switch to the Editor tab at this point as this tab provides controls to execute the code.

The following code creates a serial connection descriptor with the default settings for the device:

Once the descriptor is defined, it is possible to open the connection with the device as follows:

 

2.1 Sending commands and receiving responses

With an open connection to the device, now it is possible to send commands, which must also include the line terminator setup in the serial connection descriptor:

And immediately after the connection can be polled for responses from the device:

 

2.1 Closing serial connection

Once the communication with the device is finished, it is recommended to close the serial connection, for which the following statement can be used:

3.  Example Script

4.  Download files

Download matlab-script.zip (1 KB)