# Lua Manual

<p class="callout warning">**Disclaimer**  
The EMSISO d.o.o. scripting functionality, based on the Lua programming language, is provided to enable flexibility and customization for motor control applications. However, EMSISO d.o.o. assumes no responsibility or liability for any damages, malfunctions, injuries, or losses resulting from the use of scripts provided by EMSISO d.o.o. or scripts created, modified, or executed by users.  
Users are fully responsible for testing and verifying all scripts in a controlled and safe environment before deployment. Any script used in conjunction with EMSISO d.o.o. products is done at the user’s own risk.  
By using the scripting feature, you acknowledge and agree to release EMSISO d.o.o. from all claims, demands, or liability for any incidents that may arise from its use.</p>

## 1. General

### 1.1 Purpose

- This manual helps you create and run Lua scripts on emDrive.
- It also informs you about any warnings and known issues.

### 1.2 Scope

- The manual covers Lua scripting features, including how to: 
    - Download scripts
    - Control scripts
    - Debug scripts
    - Use functions provided by the emDrive library
- It also lists known issues and limitations of the scripting functionality.

### 1.3 Important Note

- This manual assumes you already know Lua and emDrive Configurator software.
- It is valid for Lua version 5.4. For more details on Lua, visit: 
    - [Lua 5.4 Manual](https://www.lua.org/manual/5.4/)
    - [Programming in Lua](https://www.lua.org/pil/contents.html)

## 2. emDrive library

### 2.1 General

The emDrive library is used instead of the standard Lua libraries. This library includes some functions that are identical to those in the standard Lua library, some that have been modified, and others that are unique to emDrive.

<p class="callout warning">Do not overwrite the emDrive library functions and variables.</p>

The emDrive library is organized into different sets, each focused on a specific group of functionalities. This section will describe these sets and their functions and variables in detail.

Here is an example of how to use a library function. This example will show a legend that explains how to read the prototypes of library functions. Words in blue represent variable types, such as arguments or return values. These types follow standard Lua conventions, with the addition of the "integer" type, which represents whole numbers.

When your script calls a function from the emDrive library, the arguments you provide must match the prototype exactly, including the type and, for tables, their structure. If they do not, an error will occur.

<span style="color: rgb(53, 152, 219);">number</span> | <span style="color: rgb(53, 152, 219);">nil</span> ret1, <span style="color: rgb(53, 152, 219);">boolean</span> ret2 = Namespace.FunctionName({<span style="color: rgb(53, 152, 219);">integer </span>arg1Field1, <span style="color: rgb(53, 152, 219);">string </span>arg1Field2} arg1,   
{<span style="color: rgb(53, 152, 219);">integer</span>, <span style="color: rgb(53, 152, 219);">integer</span>, <span style="color: rgb(53, 152, 219);">integer </span>\[5:5-11\], <span style="color: rgb(53, 152, 219);">integer </span>\[13\]} arg2, \[, <span style="color: rgb(53, 152, 219);">string </span>arg3\], arg4…)

This is an example of a function named `Namespace.FunctionName`. It takes in: 2 fixed arguments, 1 optional   
argument and a variable number of arguments. It also returns 2 values where the first can also be <span style="color: rgb(53, 152, 219);">nil</span>.

<div align="center" id="bkmrk-%C2%A0-name-description-a"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; width: 54.9383%; height: 235.6px;"><tbody><tr style="height: 29.2px;"><td style="width: 23.4234%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 29.2px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 13.964%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 29.2px;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 62.6126%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 29.2px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 45.6px;"><td rowspan="4" style="width: 23.4234%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 137.6px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">arg1</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Table with two named fields arg1Field1 of type integer and arg1Field2 of type string.</span>

</td></tr><tr style="height: 45.6px;"><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">arg2</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Table with unnamed fields with all integer types at index 1, 2, 5 with size 1 to 7 and 13.</span>

</td></tr><tr style="height: 23.2px;"><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">arg3</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Optional string argument.</span>

</td></tr><tr style="height: 23.2px;"><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">arg4</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Variable number of arguments of any type.</span>

</td></tr><tr style="height: 45.6px;"><td rowspan="2" style="width: 23.4234%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 68.8px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">ret1</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.6px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">First returned value which can be either a number type or nil.</span>

</td></tr><tr style="height: 23.2px;"><td style="width: 13.964%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">ret2</span>

</td><td style="width: 62.6126%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Second returned value which is of boolean type.</span>

</td></tr></tbody></table>

</div><p class="callout info">Functions can be called with more arguments then expected in which case excess arguments are ignored.</p>

The emDrive library can raise errors in addition to those raised by the Lua kernel, such as accessing nil values. These library errors usually occur when the type or value of an argument does not match what is expected.

For each function in the emDrive library, the possible errors (exceptions) and the conditions that cause them will be listed.

### 2.2 Functions

#### 2.2.1 Base

This library provides base script functionality that is not specific to any part of the emDrive hardware (HW) or firmware (FW).

Error(<span style="color: rgb(53, 152, 219);">string </span>message \[, <span style="color: rgb(53, 152, 219);">integer </span>level\])

The `Error` function raises an error with a custom message and specifies the level of the error position. It is useful for throwing exceptions, such as for debugging purposes. This function is equivalent to the standard `error()` function in Lua and never returns.

<div align="center" id="bkmrk-table-1%3A-error%28%29-pro"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 54.9383%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">1</span></span><span lang="SL">: Error() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 18.9189%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 14.6892%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 66.3918%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td rowspan="2" style="width: 18.9189%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 14.6892%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">message</span>

</td><td style="width: 66.3918%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Error message shown.</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 14.6892%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">level</span>

</td><td style="width: 66.3918%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Specify how to get the error position:</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="EN-US" style="font-size: 9.0pt;">0, error position is not added,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="EN-US" style="font-size: 9.0pt;">1 (default), the error position is where the </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">error()</span></span><span lang="EN-US" style="font-size: 9.0pt;"> function was called,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="EN-US" style="font-size: 9.0pt;">2 points the error to where the function that called </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">error()</span></span><span lang="EN-US" style="font-size: 9.0pt;"> was called,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="EN-US" style="font-size: 9.0pt;">and so on…</span>

</td></tr></tbody></table>

</div>#### 2.2.2 I/O

This library works with two main objects: `Lua__IO_Input` and `Lua__IO_Output`. These objects facilitate communication between the script and the external world, such as displaying messages or providing debugging arguments to the script.

- **Access**: These objects can be accessed via the CANopen index `0x2040`.
- **Purpose**: 
    - `Lua__IO_Input`: Used to input data into the script.
    - `Lua__IO_Output`: Used to output data from the script.

By using these objects, the script can efficiently exchange information with external systems.

![I/O library objects](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-xvqpbqaq.png)

<span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span style="color: rgb(53, 152, 219);">number </span>| <span style="color: rgb(53, 152, 219);">string </span>| <span style="color: rgb(53, 152, 219);">nil </span>value = IO.Read(\[option…\])

You can read values from the input object using specified options.

**Options**:

- When the 'n' option is selected, if the value cannot be converted to a number, `nil` is returned.
- By passing an integer, you can read that many number of characters.

This function is equivalent to the standard `io.read()` function in Lua.

<div align="center" id="bkmrk-table-2%3A-io.read%28%29-p"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 54.9383%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">2</span></span><span lang="SL">: IO.Read() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 17.7928%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 12.6693%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 69.5379%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 17.7928%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 12.6693%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">option</span>

</td><td style="width: 69.5379%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">How to interpret the input string:</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>*<span lang="EN-US" style="font-size: 9.0pt;">‘n’</span>*<span lang="EN-US" style="font-size: 9.0pt;"> as a number,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>*<span lang="EN-US" style="font-size: 9.0pt;">‘l’</span>*<span lang="EN-US" style="font-size: 9.0pt;"> (default) as one line string without newline,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>*<span lang="EN-US" style="font-size: 9.0pt;">‘L’</span>*<span lang="EN-US" style="font-size: 9.0pt;"> as one line string with newline if exists,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>*<span lang="EN-US" style="font-size: 9.0pt;">‘a’</span>*<span lang="EN-US" style="font-size: 9.0pt;"> as string of all text,</span>

<span lang="EN-US" style="font-size: 9.0pt; font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span>*<span lang="EN-US" style="font-size: 9.0pt;">0, 1, 2, … as number of characters.</span>*

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 17.7928%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 12.6693%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">value</span>

</td><td style="width: 69.5379%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Interpreted input.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table%C2%A03%3A-io.read%28%29-e"><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">3</span></span><span lang="SL">: IO.Read() exceptions</span><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">option is not an integer nor a string.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">option is a string longer than 1 character.</span>

</td></tr><tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">option is a string but not one of the valid values.</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US">IO.Write(</span><span lang="EN-US" style="color: #0070c0;">string</span><span lang="EN-US"> text…)</span>

You can write text to the output object using this function.

- **Behavior**: 
    - If the text is short enough, it is appended to the existing output string.
    - If the text is too long, the existing output string is overwritten.

This function is equivalent to the standard `io.write()` function in Lua.

<div align="center" id="bkmrk-table-4%3A-io.write%28%29-"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 54.9383%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">4</span></span><span lang="SL">: IO.Write() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 18.9189%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 13.5656%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 67.5154%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 18.9189%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 13.5656%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">text</span>

</td><td style="width: 67.5154%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Text to write to output object.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-5%3A-io.write%28%29-"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 36.2963%; height: 46.7812px; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">5</span></span><span lang="SL">: IO.Write() exceptions</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 0%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">text is not a string.</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US">IO.Print(object…)</span>

This function converts an object to a string and then writes the result to the output object.

This function is equivalent to the standard `print()` function in Lua.

<div align="center" id="bkmrk-table-6%3A-io.print%28%29-"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 54.9383%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">6</span></span><span lang="SL">: IO.Print() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 19.5946%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 12.2158%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 68.1896%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 19.5946%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 12.2158%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">object</span>

</td><td style="width: 68.1896%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Objects to convert to string and write to output object.</span>

</td></tr></tbody></table>

</div>#### 2.2.3 Time

This library provides functions for time keeping and inserting delays in your scripts.

<span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> time = Time.GetMs()</span>

<span style="color: rgb(0, 0, 0);">This function retrieves the current time in milliseconds since the device was powered on. The maximum value is limited to 2³² – 1.</span>

<div align="center" id="bkmrk-table-7%3A-time.getms%28"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 54.9383%; height: 69.1718px; border-spacing: 0px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">7</span></span><span lang="SL">: Time.GetMs() prototype description</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 15.0901%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 12.0012%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 72.9087%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 45.7812px;"><td style="width: 15.0901%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 12.0012%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">time</span>

</td><td style="width: 72.9087%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Elapsed milliseconds since power on.</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US">Time.WaitMs(</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> time)</span>

<span lang="EN-US">This function halts the script execution for a specified amount of time using this function.</span>

<div align="center" id="bkmrk-table-8%3A-time.waitms"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">8</span></span><span lang="SL">: Time.WaitMs() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 2.0cm; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="76">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 2.0cm; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="76"><span lang="EN-US" style="font-size: 9.0pt;">time</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Milliseconds to wait.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-9%3A-time.waitms"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">9</span></span><span lang="SL">: Time.WaitMs() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">time is negative or 0.</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> newStartTime = Time.WaitMsUntil(</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> startTime, i</span><span lang="EN-US" style="color: #0070c0;">nteger</span><span lang="EN-US"> waitTime)</span>

<span lang="EN-US">This function h</span><span lang="EN-US">alts script execution for specified time from the provided starting time. This function can be used to implement periodic execution independent of logic execution duration.</span>

<div align="center" id="bkmrk-table-10%3A-time.waitm"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 55.8025%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">10</span></span><span lang="SL">: Time.WaitMsUntil() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 18.6253%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 21.3204%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="83">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 59.8326%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td rowspan="2" style="width: 18.6253%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 21.3204%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="83"><span lang="EN-US" style="font-size: 9.0pt;">startTime</span>

</td><td style="width: 59.8326%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Time (milliseconds) from which waiting time is measured.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 21.3204%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="83"><span lang="EN-US" style="font-size: 9.0pt;">waitTime</span>

</td><td style="width: 59.8326%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Milliseconds to wait.</span>

</td></tr><tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes;"><td style="width: 18.6253%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 21.3204%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="83"><span lang="EN-US" style="font-size: 9.0pt;">newStartTime</span>

</td><td style="width: 59.8326%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Time (milliseconds) at which script was halted.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-11%3A-time.waitm"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">11</span></span><span lang="SL">: Time.WaitMsUntil() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">startTime is negative or 0.</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">waitTime is negative or 0.</span>

</td></tr></tbody></table>

</div>#### 2.2.3 CAN

This library is used to establish communication and transfer data over CAN. It provides functionality to send and receive CAN messages.

<p class="callout info">**Note**: This library does not support CAN FD (Flexible Data-rate).</p>

<span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span style="color: rgb(0, 0, 0);">This library supports two modes of operation for CAN communication. The mode is selected during the initialization of CAN.</span>

<div align="center" id="bkmrk-table-12%3A-can-modes-"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 52.5926%; height: 159.734px; border-spacing: 0px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">12</span></span><span lang="SL">: CAN modes of operation</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 24.7655%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="86">**<span lang="EN-US" style="font-size: 9.0pt;">Mode</span>**

</td><td style="width: 75.4698%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 90.5625px;"><td style="width: 24.7655%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 90.5625px;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CAN\_RX\_TX</span>

</td><td style="width: 75.4698%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 90.5625px;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">CAN shall be used to send and receive messages (user is required to implement </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">CAN.Received(message)</span></span><span lang="EN-US" style="font-size: 9.0pt;"> function).</span>

</td></tr><tr style="height: 45.7812px;"><td style="width: 24.7655%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CAN\_TX\_ONLY</span>

</td><td style="width: 75.4698%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">CAN shall be used only to send messages.</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US">CAN.Initialize(mode, </span><span lang="EN-US" style="color: #0070c0;">boolean</span><span lang="EN-US"> useExtendedFrame \[, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> rxID, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> rxIDMask\])</span>

To use CAN communication, initialize CAN with this function. It can be called multiple times with different arguments, but only the last configuration will be used.

- **rxIDMask Argument**: Required only when the operating mode is set to `CAN_RX_TX`.

<div align="center" id="bkmrk-table-13%3A-can.initia"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">13</span></span><span lang="SL">: CAN.Initialize() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 16.3522%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 28.1155%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 55.5323%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td rowspan="4" style="width: 16.3522%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 28.1155%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">mode</span>

</td><td style="width: 55.5323%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">CAN mode of operation (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">12</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 28.1155%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">useExtendedFrame</span>

</td><td style="width: 55.5323%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Will extended frames be transferred?</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 28.1155%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">rxID</span>

</td><td style="width: 55.5323%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Frame ID to receive.</span>

</td></tr><tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;"><td style="width: 28.1155%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">rxIDMask</span>

</td><td style="width: 55.5323%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Receive filter ID mask.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-14%3A-can.initia"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">14</span></span><span lang="SL">: CAN.Initialize() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">mode is not one of the valid values.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">useExtendedFrame is not boolean.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">rxID is not an integer.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">mode is set to CAN\_RX\_TX and rxIDMask is not an integer.</span>

</td></tr><tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">CAN initialization failed (should never happen).</span>

</td></tr></tbody></table>

</div><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span>

<span lang="EN-US">CAN.Send(</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> id, {</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> \[1:1-8\]} data)</span>

<span lang="EN-US">Use this function to send a CAN frame with a specified ID and data.</span>

<div align="center" id="bkmrk-table-15%3A-can.send%28%29"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; height: 70.1718px; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">15</span></span><span lang="SL">: CAN.Send() prototype description</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 16.8096%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 38.7459%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 23.3906px;"><td rowspan="2" style="width: 16.8096%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 46.7812px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 38.7459%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">id</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Sent frame ID.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 38.7459%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">data</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">1 to 8 bytes of data.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-16%3A-can.send%28%29"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">16</span></span><span lang="SL">: CAN.Send() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">id is not an integer.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">data is not a table.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Length of data is more than 8.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value of data is not an integer.</span>

</td></tr><tr style="mso-yfti-irow: 5;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value of data is more than 0xFF.</span>

</td></tr><tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">CAN send failed (should never happen).</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">CAN.Received({</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> ID, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> Length, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US"> Data\[1:1-8\]} message)</span>

This function is called whenever a CAN message is received.

- **User Implementation Required**: You must implement this function if CAN is initialized in `CAN_RX_TX` operating mode.

<div align="center" id="bkmrk-table-17%3A-can.receiv"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">17</span></span><span lang="SL">: CAN.Received() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 17.2346%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 38.3209%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 17.2346%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 38.3209%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">message</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Received message.</span>

</td></tr></tbody></table>

</div>#### 2.2.4 CANopen

This library is used to interact with the CANopen protocol stack.

- **CANopen Object Representation**: Internally, a CANopen object is represented as a table with two values: `index` and `subindex`.

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">The CANopen stack includes a network management state machine that defines the communication behavior of a CANopen device. While there are multiple possible states, only a few are regularly used and available to the user.</span>

<div align="center" id="bkmrk-table-18%3A-canopen-nm"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 52.5926%;"><caption>Table 18: CANopen NMT states</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 31.5769%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="86">**<span lang="EN-US" style="font-size: 9.0pt;">NMT state</span>**

</td><td style="width: 68.4231%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_UNKNOWN</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">NMT in unknown state (unreachable).</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state cannot be set by user.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_OPERATIONAL</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Device can use all supported communication objects.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state can be set by user.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_STOPPED</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Device operation is stopped.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state cannot be set by user.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_PREOPERATIONAL</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">First state after initialization indicating that device is ready to work. Limited message transfer support.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state can be set by user.</span>

</td></tr><tr style="mso-yfti-irow: 5;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_RESET\_NODE</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Application reset. Application objects set to their power-on or default values.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state cannot be set by user.</span>

</td></tr><tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes;"><td style="width: 31.5769%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="86"><span lang="EN-US" style="font-size: 9.0pt;">CO\_RESET\_COMM</span>

</td><td style="width: 68.4231%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Communication reset. Communication objects are set to their power-on or default values.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This state cannot be set by user.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">state = CANopen.GetNMTState()</span>

<span lang="EN-US">Use this function to retrieve the currently set Network Management (NMT) state of the CANopen device.</span>

<div align="center" id="bkmrk-table%C2%A019%3A-canopen.ge"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 67.284%; height: 93px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">19</span></span><span lang="SL">: CANopen.GetNMTState() prototype description</span>

</caption><tbody><tr style="height: 23.3906px;"><td style="width: 19.8801%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75"></td><td style="width: 13.0526%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 67.2712%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 45.7812px;"><td style="width: 19.8801%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 45.7812px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 13.0526%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">state</span>

</td><td style="width: 67.2712%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 45.7812px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Currently set NMT state (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">18</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">CANopen.SetNMTState(state)</span>

<span lang="EN-US">Use this function to request the CANopen stack to change the Network Management (NMT) state of the device.</span>

<div align="center" id="bkmrk-table-20%3A-canopen.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">20</span></span><span lang="SL">: CANopen.SetNMTState() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 17.1908%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 10.5405%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 72.2687%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 17.1908%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 10.5405%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">state</span>

</td><td style="width: 72.2687%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Next NMT state (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">18</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-21%3A-canopen.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">21</span></span><span lang="SL">: CANopen.SetNMTState() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">state is not one of the valid values.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> value = CANopen.GetObjectValue({</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US">, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US">} object)</span>

Use this function to retrieve the value of a specified object.

<div align="center" id="bkmrk-table-22%3A-canopen.ge"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; height: 70.1718px; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">22</span></span><span lang="SL">: CANopen.GetObjectValue() prototype description</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 0%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 0%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 0%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">object</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">CANopen object.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">value</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Object value.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-23%3A-canopen.ge"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; height: 140.344px; width: 38.3951%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">23</span></span><span lang="SL">: CANopen.GetObjectValue() exceptions</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 0%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">object is not a table.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Length of object is not 2.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value at first index of object is not an integer.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value at second index of object is not an integer.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Invalid object index and/or subindex.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">CANopen.SetObjectValue({</span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US">, </span><span lang="EN-US" style="color: #0070c0;">integer</span><span lang="EN-US">} object, </span><span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> value)</span>

Use this function to set the value of a specified object.

<div align="center" id="bkmrk-table-24%3A-canopen.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; height: 70.1718px; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">24</span></span><span lang="SL">: CANopen.SetObjectValue() prototype description</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 17.8522%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 37.7034%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 23.3906px;"><td rowspan="2" style="width: 17.8522%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 46.7812px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 37.7034%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">object</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">CANopen object.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 37.7034%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">value</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Object value.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-25%3A-canopen.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 44.5679%; height: 140.344px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">25</span></span><span lang="SL">: CANopen.SetObjectValue() exceptions</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">object is not a table.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Length of object is not 2.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value at first index of object is not an integer.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value at second index of object is not an integer.</span>

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Invalid object index and/or subindex.</span>

</td></tr><tr><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;"><span lang="EN-US" style="font-size: 9.0pt;">Value is not a number</span>

</td></tr></tbody></table>

</div>#### 2.2.5 Motor

This library is used to operate the motor. You can set operating parameters and retrieve the motor's current state and status.

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">The motor can be controlled in three distinct modes. Depending on the chosen mode, the related reference will be used by the motor control algorithm.</span></span>

<div align="center" id="bkmrk-table-26%3A-motor-cont"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 57.1605%;"><caption>Table 26: Motor control modes</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 29.7074%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="123">**<span lang="EN-US" style="font-size: 9.0pt;">Motor control mode</span>**

</td><td style="width: 70.2926%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 29.7074%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">TORQUE\_MODE</span>

</td><td style="width: 70.2926%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor is torque controlled.</span>

<span lang="EN-US" style="font-size: 9.0pt;">Set requested torque with </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">Motor.SetReferenceTorque()</span></span><span lang="EN-US" style="font-size: 9.0pt;">.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 29.7074%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">VELOCITY\_MODE</span>

</td><td style="width: 70.2926%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor is velocity controlled.</span>

<span lang="EN-US" style="font-size: 9.0pt;">Set requested velocity with </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">Motor.SetReferenceVelocity()</span></span><span lang="EN-US" style="font-size: 9.0pt;">.</span>

</td></tr><tr style="mso-yfti-irow: 3; mso-yfti-lastrow: yes;"><td style="width: 29.7074%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">POSITION\_MODE</span>

</td><td style="width: 70.2926%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor is position controlled.</span>

<span lang="EN-US" style="font-size: 9.0pt;">Set requested torque with </span><span class="codeChar"><span lang="EN-US" style="font-size: 9.0pt; mso-bidi-font-size: 12.0pt;">Motor.SetReferencePosition()</span></span><span lang="EN-US" style="font-size: 9.0pt;">.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

Motor control operates with a state machine that can be in one of multiple states. This state machine is responsible for top-level motor control functions such as initialization, execution, calibration, and error handling.

- **State Execution**: Some states are executed before the script runs and will not be visible to the user.

<div align="center" id="bkmrk-table-27%3A-motor-cont"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 58.5185%;"><caption>Table 27: Motor control states</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 31.1184%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="134">**<span lang="EN-US" style="font-size: 9.0pt;">Motor control state</span>**

</td><td style="width: 69.0931%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_UNDEFINED</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control in undefined state (internal error).</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_INITIALIZATION</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control is initializing.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_SELF\_TEST</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control is performing start-up self-tests.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_OFF</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control is initialized and disabled. Controlling the motor is not possible. Reference values have no effect.</span>

</td></tr><tr style="mso-yfti-irow: 5;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_ON</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control is initialized and enabled. Motor is controlled according to mode and reference value such that the operating conditions are always within defined limits.</span>

</td></tr><tr style="mso-yfti-irow: 6;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_ERROR</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control detected an error and was disabled. This state can be entered in multiple ways: limits overreached, failed calibration and other.</span>

</td></tr><tr style="mso-yfti-irow: 7; mso-yfti-lastrow: yes;"><td style="width: 31.1184%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="134"><span lang="EN-US" style="font-size: 9.0pt;">MOTOR\_CALIBRATION</span>

</td><td style="width: 69.0931%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Motor control is being calibrated. In this state characteristics of the motor and angle sensor are being measured.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.Enable()</span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">Enable motor control to have the motor operate according to the set mode and the corresponding reference value.</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.Disable()</span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">Disable motor control to stop the motor.</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.Recover()</span>

Use this function to attempt recovery from a motor control error.

<p class="callout info">**Note**: This function is only applicable when the motor control is in an error state.</p>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.SetControlMode(mode)</span>

<span lang="EN-US">Use this function to set the motor control mode.</span>

<div align="center" id="bkmrk-table-28%3A-motor.setc"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; border-spacing: 0px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">28</span></span><span lang="SL">: Motor.SetControlMode() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 17.8626%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 37.6948%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4459%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 17.8626%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 37.6948%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">mode</span>

</td><td style="width: 44.4459%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Motor control mode (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">26</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-29%3A-motor.setc"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 40.3704%; height: 46.7812px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">29</span></span><span lang="SL">: Motor.SetControlMode() exceptions</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">mode is not one of the valid values.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">state = Motor.GetState()</span>

Retrieve the current state of the motor control.

<div align="center" id="bkmrk-table-30%3A-motor.gets"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">30</span></span><span lang="SL">: Motor.GetState() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">state</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Motor control state (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">27</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Calibri',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; color: #0070c0; mso-ansi-language: SL; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">integer</span><span lang="SL" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Calibri',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: SL; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"> warnings = Motor.GetWarnings()</span></span></span>

Retrieve the currently active motor control warnings.

<div class="mt-1 flex gap-3 empty:hidden juice:-ml-3" id="bkmrk--2"><div class="items-center justify-start rounded-xl p-1 flex">  
</div></div><div align="center" id="bkmrk-table-31%3A-motor.getw"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">31</span></span><span lang="SL">: Motor.GetWarnings()</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">warnings</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Active warnings.</span>

<span lang="EN-US" style="font-size: 9.0pt;">Refer to emDrive manual or related CANopen object for value meaning.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif; color: rgb(0, 112, 192);">integer</span><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif;"> protectionsLow = Motor.GetProtectionsLow()</span></span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif;">Retrieve the currently active motor control protections (first 32 bits).</span></span></span>

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid align-center" id="bkmrk-table-32%3A-motor.getp" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">32</span></span><span lang="SL">: Motor.GetProtectionsLow()</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9pt;">protectionsLow</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9pt;">Active protections (first 32bits).</span>

<span lang="EN-US" style="font-size: 9pt;">Refer to emDrive manual or related CANopen object for value meaning.</span>

</td></tr></tbody></table>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif; color: rgb(0, 112, 192);">integer</span><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif;"> protectionsHigh = Motor.GetProtectionsHigh()</span></span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12pt; line-height: 107%; font-family: Calibri, sans-serif;">Retrieve the currently active motor control protections (last 32 bits).</span></span></span>

<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid align-center" id="bkmrk-table-33%3A-motor.getp" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">33</span></span><span lang="SL">: Motor.GetProtectionsHigh()</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9pt;">protectionsHigh</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9pt;">Active protections (second 32 bits - currently empty meant for future FW releases).</span>

<span lang="EN-US" style="font-size: 9pt;">Refer to emDrive manual or related CANopen object for value meaning.</span>

</td></tr></tbody></table>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> velocity = Motor.GetReferenceVelocity()</span>

Retrieve the currently set reference velocity.

<div align="center" id="bkmrk-table-32%3A-motor.getr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">34</span></span><span lang="SL">: Motor.GetReferenceVelocity()</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 38.5722%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 16.9979%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4561%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 38.5722%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 16.9979%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">velocity</span>

</td><td style="width: 44.4561%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Velocity \[RPM\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.SetReferenceVelocity(</span><span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> velocity)</span>

Set the reference velocity.

<div align="center" id="bkmrk-table-33%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">35</span></span><span lang="SL">: Motor.SetReferenceVelocity() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 23.5007%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 32.0549%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 23.5007%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 32.0549%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">velocity</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Velocity \[RPM\].</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-34%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 47.284%; height: 46.7812px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">34</span></span><span lang="SL">: Motor.SetReferenceVelocity() exceptions</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">velocity is not a number.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> torque = Motor.GetReferenceTorque()</span>

Retrieve the currently set reference torque.

<div align="center" id="bkmrk-table-35%3A-motor.getr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">36</span></span><span lang="SL">: Motor.GetReferenceTorque() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">torque</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Torque \[Nm\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.SetReferenceTorque(</span><span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> torque)</span>

Set the reference torque.

<div align="center" id="bkmrk-table-36%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">37</span></span><span lang="SL">: Motor.SetReferenceTorque() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 33.3333%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 22.2222%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 33.3333%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 22.2222%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">torque</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Torque \[Nm\].</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-37%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 40.3704%;"><caption>Table 38: Motor.SetReferenceTorque() exceptions</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">torque is not a number.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> position = Motor.GetReferencePosition()</span>

Retrieve the currently set reference position.

<div align="center" id="bkmrk-table-38%3A-motor.getr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%; height: 46.7812px;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">39</span></span><span lang="SL">: Motor.GetReferencePosition() prototype description</span></caption><tbody><tr style="height: 23.3906px;"><td style="width: 0%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 0%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 0%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 23.3906px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.3906px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">position</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.3906px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Position \[°\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US"><span style="color: rgb(0, 0, 0);"><span lang="SL" style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; line-height: 107%; font-family: 'Calibri',sans-serif; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: SL; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Motor.SetReferencePosition(<span style="color: #0070c0;">number</span> position)</span></span></span>

Set the reference position.

<div align="center" id="bkmrk-table-39%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table 40</span><span lang="SL">: Motor.SetReferencePosition() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 33.3333%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 22.2222%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 33.3333%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 22.2222%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">position</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Position \[°C\].</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-40%3A-motor.setr"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 44.321%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">41</span></span><span lang="SL">: Motor.SetReferencePosition() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">position is not a number.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> velocity = Motor.GetVelocity()</span>

Retrieve the current motor velocity.

<div align="center" id="bkmrk-table-41%3A-motor.getv"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">42</span></span><span lang="SL">: Motor.GetVelocity() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">velocity</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Velocity \[RPM\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> torque = Motor.GetTorque()</span>

Retrieve the current motor torque.

<div align="center" id="bkmrk-table-42%3A-motor.gett"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table 43</span><span lang="SL">: Motor.GetTorque() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">torque</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Torque \[Nm\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> position = Motor.GetPosition()</span>

Retrieve the current motor position.

<div align="center" id="bkmrk-table-43%3A-motor.getp"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">44</span></span><span lang="SL">: Motor.GetPosition() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 81.25pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 56.45pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 81.25pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">position</span>

</td><td style="width: 219.75pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Position \[°C\].</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Motor.TriggerProtection(</span><span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> ErrorCode, </span><span lang="EN-US"><span lang="EN-US" style="color: #0070c0;">string <span style="color: rgb(0, 0, 0);">ErrorMessage</span></span>)</span>

Raise inverter protection from Lua

<div align="center" id="bkmrk-table-45%3A-motor.trig"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%; height: 81.0278px;"><caption><span lang="SL">Table 45</span><span lang="SL">: Motor.<span lang="EN-US">TriggerProtection</span>() prototype description</span></caption><tbody><tr style="height: 23.2778px;"><td style="width: 33.3265%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.2778px;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 29.9583%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.2778px;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 36.6948%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.2778px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="height: 34.4722px;"><td style="width: 33.3265%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 34.4722px;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 29.9583%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 34.4722px;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">ErrorCode</span>

</td><td style="width: 36.6948%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 34.4722px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Create custom value for error code</span></td></tr><tr style="height: 23.2778px;"><td style="width: 33.3265%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.2778px;">**<span lang="EN-US" style="font-size: 9.0pt;">  
</span>**

</td><td style="width: 29.9583%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2778px;"><span lang="EN-US" style="font-size: 9.0pt;">ErrorMessage</span>

</td><td style="width: 36.6948%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt; height: 23.2778px;"><span lang="EN-US" style="font-size: 9.0pt;">Custom error description</span></td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-45%3A-motor.trig-1"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 40.3704%; height: 46.5556px;"><caption>Table 45: <span lang="EN-US">Motor.TriggerProtection</span>() exceptions</caption><tbody><tr style="height: 23.2778px;"><td style="width: 100%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt; height: 23.2778px;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="height: 23.2778px;"><td style="width: 100%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt; height: 23.2778px;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">ErrorCode is not a number  
ErrorMessage is not a string or empty - Must be defined</span>

</td></tr></tbody></table>

</div>#### 2.2.6 Digital

This library is used to manipulate digital I/Os (ports). It enables writing to and reading from digital ports.

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

Every emDrive contains a set of digital ports that can be freely used by the user application. Some of these ports are writable, while others are read-only. Note that some ports might not be available on all emDrives. To see which ports are available, refer to the manual or the EDS of your emDrive

<div align="center" id="bkmrk-table-44%3A-digital-po"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption>Table 45: Digital ports</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123">**<span lang="EN-US" style="font-size: 9.0pt;">Digital port</span>**

</td><td style="width: 254.1pt; border: solid windowtext 1.0pt; border-left: none; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_1</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 1.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_2</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 2.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_3</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 3.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_4</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 4.</span>

</td></tr><tr style="mso-yfti-irow: 5;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">HIGH\_SIDE\_1</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">High-side switch 1.</span>

</td></tr><tr style="mso-yfti-irow: 6;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_1</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 1.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 7;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_2</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 2.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 8;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_3</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 3.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 9;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_4</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 4.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 10;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_5</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 5.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 11;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_6</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 6.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr><tr style="mso-yfti-irow: 12; mso-yfti-lastrow: yes;"><td style="width: 92.5pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_7</span>

</td><td style="width: 254.1pt; border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 7.</span>

<span lang="EN-US" style="font-size: 9.0pt;">This port is read-only.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> state = Digital.Get(port)</span>

Retrieve the digital state of the port.

<div align="center" id="bkmrk-table-45%3A-digital.ge"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">46</span></span><span lang="SL">: Digital.Get() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 18.4798%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 37.0758%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4444%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 18.4798%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 37.0758%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">port</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Digital port (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">44</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 18.4798%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 37.0758%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">state</span>

</td><td style="width: 44.4444%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value of 0 – 1 representing signal’s duty cycle.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-46%3A-digital.ge"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption>T<span lang="SL">able </span><span lang="SL"><span style="mso-no-proof: yes;">47</span></span><span lang="SL">: Digital.Get() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">port is not one of the valid values.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US">Digital.Set(port, </span><span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> state)</span>

Set the digital state of the port.

<div align="center" id="bkmrk-table-47%3A-digital.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; width: 59.0123%; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">48</span></span><span lang="SL">: Digital.Set() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 17.8197%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 15.1417%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 67.0386%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td rowspan="2" style="width: 17.8197%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 15.1417%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">port</span>

</td><td style="width: 67.0386%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Digital port (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">44</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 15.1417%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">state</span>

</td><td style="width: 67.0386%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Value of 0 – 1 representing signal’s duty cycle.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-48%3A-digital.se"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">49</span></span><span lang="SL">: Digital.Set() exceptions</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">port is not one of the valid values.</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">state is not a number between 0 and 1.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

#### 2.2.7 Analog

This library is used to retrieve values from analog inputs (ports).

<span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

Every emDrive contains a set of analog ports that can be freely used by the user application. All of these ports are read-only. Note that some ports might not be available on all emDrives. To see which ports are available, refer to the manual or the EDS of your emDrive.

<div align="center" id="bkmrk-table-49%3A-analog-por"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 57.1605%;"><caption>Table 50: Analog ports</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 33.1622%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="123">**<span lang="EN-US" style="font-size: 9.0pt;">Analog port</span>**

</td><td style="width: 66.8378%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="339">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">ANALOG\_IN\_1</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Analog input 1.</span>

</td></tr><tr style="mso-yfti-irow: 2;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">ANALOG\_IN\_2</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Analog input 2.</span>

</td></tr><tr style="mso-yfti-irow: 3;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">ANALOG\_IN\_3</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Analog input 3.</span>

</td></tr><tr style="mso-yfti-irow: 4;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">ANALOG\_IN\_4</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Analog input 4.</span>

</td></tr><tr style="mso-yfti-irow: 5;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_1\_VOLTAGE</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 1 voltage measurement.</span>

</td></tr><tr style="mso-yfti-irow: 6;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_1\_CURRENT</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 1 current measurement.</span>

</td></tr><tr style="mso-yfti-irow: 7;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_2\_VOLTAGE</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 2 voltage measurement.</span>

</td></tr><tr style="mso-yfti-irow: 8;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_3\_VOLTAGE</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 3 voltage measurement.</span>

</td></tr><tr style="mso-yfti-irow: 9;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">LOW\_SIDE\_4\_VOLTAGE</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Low-side switch 4 voltage measurement.</span>

</td></tr><tr style="mso-yfti-irow: 10;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">HIGH\_SIDE\_1\_VOLTAGE</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">High-side switch 1 voltage measurement.</span>

</td></tr><tr style="mso-yfti-irow: 11;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_1</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 1.</span>

</td></tr><tr style="mso-yfti-irow: 12;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_2</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 2.</span>

</td></tr><tr style="mso-yfti-irow: 13;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_3</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 3.</span>

</td></tr><tr style="mso-yfti-irow: 14;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_4</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 4.</span>

</td></tr><tr style="mso-yfti-irow: 15;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_5</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 5.</span>

</td></tr><tr style="mso-yfti-irow: 16;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_6</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 6.</span>

</td></tr><tr style="mso-yfti-irow: 17; mso-yfti-lastrow: yes;"><td style="width: 33.1622%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 5.4pt;" valign="top" width="123"><span lang="EN-US" style="font-size: 9.0pt;">DIGITAL\_IN\_7</span>

</td><td style="width: 66.8378%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="339"><span lang="EN-US" style="font-size: 9.0pt;">Digital input 7.</span>

</td></tr></tbody></table>

</div><span lang="EN-US"><span style="color: rgb(0, 0, 0);">\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_</span></span>

<span lang="EN-US" style="color: #0070c0;">number</span><span lang="EN-US"> value = Analog.Get(port)</span>

<span lang="EN-US">Retrieve the analog value on the port.</span>

<div align="center" id="bkmrk-table-50%3A-analog.get"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; width: 59.0123%;"><caption><span lang="SL">Table </span><span lang="SL"><span style="mso-no-proof: yes;">51</span></span><span lang="SL">: Analog.Get() prototype description</span></caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 33.3421%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;"> </span>**

</td><td style="width: 22.228%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="108">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 44.4561%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr><tr style="mso-yfti-irow: 1;"><td style="width: 33.3421%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" valign="top" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Arguments</span>**

</td><td style="width: 22.228%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">port</span>

</td><td style="width: 44.4561%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Analog port (see </span><span lang="EN-US" style="font-size: 9.0pt;">Table <span style="mso-no-proof: yes;">49</span></span><span lang="EN-US" style="font-size: 9.0pt;">).</span>

</td></tr><tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes;"><td style="width: 33.3421%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; background: rgb(168, 208, 141); padding: 0cm 5.4pt;" width="75">**<span lang="EN-US" style="font-size: 9.0pt;">Returns</span>**

</td><td style="width: 22.228%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="108"><span lang="EN-US" style="font-size: 9.0pt;">value</span>

</td><td style="width: 44.4561%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">Analog value.</span>

</td></tr></tbody></table>

</div><div align="center" id="bkmrk-table-51%3A-analog.get"><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border-spacing: 0px; border: initial none initial;"><caption>Table 52: Analog.Get() exceptions</caption><tbody><tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; background: #A8D08D; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293">**<span lang="EN-US" style="font-size: 9.0pt;">Exception</span>**

</td></tr><tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="width: 219.75pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .5pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="293"><span lang="EN-US" style="font-size: 9.0pt;">port is not one of the valid values.</span>

</td></tr></tbody></table>

</div>## 3. Scripting

### 3.1 Setting Up Lua Scripting with Visual Studio Code

To make Lua scripting easier, follow these steps to set up Visual Studio Code with the Lua extension:

1. **Install Visual Studio Code**
    
    
    - If you don't have it yet, download and install Visual Studio Code.
2. **Add the Lua Extension**
    
    
    - Open Visual Studio Code.
    - Go to the Extensions view (click on the square icon on the sidebar or press `Ctrl+Shift+X`).
    - Search for "Lua" and install the Lua extension by sumneko.  
        [![image.png](http://help.emsiso.com/uploads/images/gallery/2024-04/scaled-1680-/0MXimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-04/0MXimage.png)
3. **Create a Folder for Libraries**
    
    
    - Make a new folder on your computer to store the emdrive library. For example, you can name it `D:\LuaLibraries`.
    - Inside the folder extract the emdrive.7z which you get directly from us.  
        `D:\LuaLibraries\emdrive`
4. **Configure Developer Mode and Add Library Path**
    
    
    - Open Visual Studio Code.
    - Press `Ctrl+P` to open the search bar.
    - Type `>settings` or `>Open User Settings (JSON)` and select "Open User Settings (JSON)" from the list.  
        [![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/Cjjimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/Cjjimage.png)
5. **Edit User Settings (JSON)**
    
    
    - In the opened `settings.json` file, add the following code.  
        ```lua
        "Lua.misc.parameters": [
            "--develop=true"
        ],
        "Lua.workspace.checkThirdParty": true,
        "Lua.workspace.userThirdParty": ["path_to_our_library"]
        ```
    - Make sure to keep any existing code intact. Add a comma at the end of the last line of the existing code, then paste the new code below it. Update the path to match your folder (`D:/LuaLibraries`). Use forward slashes instead of backslashes.
6. **Save and Close**
    
    
    - Save the changes to `settings.json`.
    - Close Visual Studio Code.

Example of "settings.json":

[![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/mdximage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/mdximage.png)

<div id="bkmrk-in-the-opened-file-y"></div><div id="bkmrk-for-example-i-had-th"></div>### 3.2 Getting Started with Lua Scripting

#### 3.2.1 Create "firstscript.lua"

1. **Create a New Folder**
    
    
    - Make a new folder for your project.
2. **Open the Folder with Visual Studio Code**
    
    
    - Right-click the folder and select "Open with Code."  
        [![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/RvZimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/RvZimage.png)
    - This will open Visual Studio Code with your new folder as the workspace.
3. **Create a New Lua Script**
    
    
    - In the Explorer window of Visual Studio Code, right-click and select "New File."  
        [![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/3fOimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/3fOimage.png)
    - Name the file `firstscript.lua` (valid files are also "firstscript.txt", "firstscript". But it is better to use .lua which can use our emdrive Library in VS-code).

<p class="callout info">**Note:** Only the content of the script is transferred, not the file name.</p>

<p class="callout warning">**Limitation:** You can store only one script at a time on the emDrive.</p>

#### 3.2.2 Structure

##### Initialization Routine

- **Function Requirement:** Your script must include a function named `Initialize()`.
- **Execution:** This function is the first to run when the script is executed and runs only once.
- **Purpose:** Use this function to initialize hardware and firmware, such as: 
    - Setting up CAN
    - Enabling the motor
    - Setting outputs
    - Setting global variables

##### Loop Routine

- **Function Requirement:** Your script must include a function named `Loop()`.
- **Periodic Execution:** This function runs periodically based on the `LoopPeriodMs` variable, which represents the period in milliseconds. 
    - **Setting the Period:** `LoopPeriodMs` can be set globally or within the `Initialize()` function.
- **Purpose:** Use the `Loop()` function for tasks that need regular updates, such as: 
    - Setting motor velocity
    - Parsing CAN frames
    - Reading inputs and setting output ports

####   


<p class="callout warning">**Minimum Loop Period:** The minimum allowed loop period is 10 milliseconds.  
**Execution Time:** Ensure the `Loop()` function completes within the set period to maintain deterministic execution. If the loop takes longer, it can cause unpredictable behavior.</p>

<p class="callout info">**Priority Consideration:** The firmware on the emDrive has higher priority than the script, which means script execution may be interrupted by higher priority tasks.  
Use the resource monitor (see the Resource Monitor section) to measure loop duration and determine the minimum possible loop period.  
The resource monitor can also show the maximum loop duration when interrupted by higher priority tasks.</p>

<p class="callout warning">**Data Transfer:** Transferring large data over CAN/CANopen will completely block script execution.</p>

### 3.3 Executing script

After you've created your script, it is time to download it to emDrive and execute it. For these purposes, a few CANopen objects are provided, as seen in Figure 3. They are grouped together and are accessible at index 0x2040.

[![image.png](https://help.emsiso.com/uploads/images/gallery/2025-04/scaled-1680-/zKCimage.png)](https://help.emsiso.com/uploads/images/gallery/2025-04/zKCimage.png)

Table 52 provides a short description of objects related to script execution. More detailed meanings and use cases will be presented in the following sections.

<div align="center" id="bkmrk-table-52%3A-script-exe"><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; width: 67.7778%; border-spacing: 0px; height: 522.055px;"><caption>Table 53: Script execution objects description</caption><thead><tr style="height: 23.2778px;"><td style="width: 20.2514%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="247">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 79.7284%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="301">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr></thead><tbody><tr style="height: 68.0556px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 68.0556px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">IsEnabled</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 68.0556px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Defines if Lua feature is enabled on particular emDrive:</span>

<span lang="EN-US" style="font-size: 9.0pt;">0: Lua feature disabled</span>

<span lang="EN-US" style="font-size: 9.0pt;">1: Lua feature enabled</span>

</td></tr><tr style="height: 180px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 180px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Status</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 180px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Lua status:</span>

<span lang="EN-US" style="font-size: 9.0pt;">0: File is non-existent or corrupted,</span>

<span lang="EN-US" style="font-size: 9.0pt;">1: Compilation failed (see Output),</span>

<span lang="EN-US" style="font-size: 9.0pt;">2: Execution failed (see Output),</span>

<span lang="EN-US" style="font-size: 9.0pt;">3: Downloaded file is valid,</span>

<span lang="EN-US" style="font-size: 9.0pt;">4: Script execution is paused,</span>

<span lang="EN-US" style="font-size: 9.0pt;">5: Script is executing,</span>

<span lang="EN-US" style="font-size: 9.0pt;">6: Script timed out and was stopped.</span>

</td></tr><tr style="height: 112.833px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 112.833px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Control</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 112.833px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Lua script control:</span>

<span lang="EN-US" style="font-size: 9.0pt;">0: Do nothing,</span>

<span lang="EN-US" style="font-size: 9.0pt;">1: Pause,</span>

<span lang="EN-US" style="font-size: 9.0pt;">2: Run,</span>

<span lang="EN-US" style="font-size: 9.0pt;">3: Restart.</span>

</td></tr><tr style="height: 23.2778px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">IsAutoStart</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Should script be started automatically after device powers on?</span>

</td></tr><tr style="height: 23.2778px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Script</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 23.2778px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Download or upload Lua script.</span>

</td></tr><tr style="height: 45.6667px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 45.6667px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">IO\_Input</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 45.6667px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Script input object. This object can be used to pass values/arguments to the script during runtime.</span>

</td></tr><tr style="height: 45.6667px;"><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 45.6667px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">IO\_Output</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 45.6667px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Script output object. This object is used to display error messages and can be used by script to print arbitrary text messages.</span>

</td></tr><tr><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt;"><span lang="EN-US" style="font-size: 9.0pt;">Error\_Code</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt;"><span lang="EN-US" style="font-size: 9.0pt;">Used to show the value of error raised inside lua script. If this object is not 0, the inverter will go into error state.</span>

</td></tr><tr><td style="width: 20.2514%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt;"><span lang="EN-US" style="font-size: 9.0pt;">Error\_Message</span>

</td><td style="width: 79.7284%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt;"><span lang="EN-US" style="font-size: 9.0pt;">Used to show the appropriate error description for the specific error code.</span>

</td></tr></tbody></table>

</div>#### 3.3.1 Download/Upload

- **To download the script to emDrive**

1. click on Script object (0x2040, 0x5),
2. check “Write from file”,
3. click the “…” button which brings up an open file dialog where you select your script,
4. click “Write” button which will download the script to emDrive,
5. after successful download you should see a green progress bar with “Successful” label.

<div drawio-diagram="136"><img src="http://help.emsiso.com/uploads/images/drawio/2024-07/drawing-12-1720596860.png" alt=""/></div>

- **<span lang="EN-US" style="mso-ansi-language: EN-US;">To upload the script – this reads back the script currently stored on emDrive</span><span lang="EN-US" style="mso-ansi-language: EN-US;">:</span>**

1. <span lang="EN-US" style="mso-ansi-language: EN-US;">click on Script object (0x2040, 0x5),</span>
2. <span lang="EN-US" style="mso-ansi-language: EN-US;">click the “Read” button which will upload the script from emDrive and display it in the “Description” text box.  
    </span>

<div drawio-diagram="137"><img src="http://help.emsiso.com/uploads/images/drawio/2024-07/drawing-12-1720596967.png" alt=""/></div>

#### 3.3.2 Control

Once the script has been successfully downloaded and verified, three control options become available through the Control object (0x2040, 0x3).

<div class="flex flex-grow flex-col max-w-full" id="bkmrk-pause-%28control-%3D-1%29%3A"><div class="min-h-[20px] text-message flex flex-col items-start whitespace-pre-wrap break-words [.text-message+&]:mt-5 juice:w-full juice:items-end overflow-x-auto gap-2" data-message-author-role="assistant" data-message-id="6619852d-f322-4550-8073-6a88327bd56c" dir="auto"><div class="flex w-full flex-col gap-1 juice:empty:hidden juice:first:pt-[3px]"><div class="markdown prose w-full break-words dark:prose-invert dark">1. **Pause (Control = 1)**: This will halt the currently executing script until Run or Restart is set. It will not stop the motor, disable outputs, or otherwise modify the state of the emDrive from what was last set by the script. This has no effect if the script is not executing.
2. **Run (Control = 2)**: This will resume execution of a paused script from where it was left off. If the script is not executing nor paused but is downloaded and verified, it will start executing the downloaded script. This has no effect if the script is already executing.
3. **Restart (Control = 3)**: This will terminate the currently executing or paused script, recompile, and restart it. If the script is not executing nor paused but is downloaded and verified, it will start executing the downloaded script.

</div></div></div></div>If a script is already executing when a new script is downloaded, the executing script is terminated as the download is initiated. After the new script is successfully downloaded and verified, it is automatically executed.

<p class="callout info">**NOTE**: The script is executed only after motor control has been initialized, which may delay script execution after the device powers on (usually by approximately 100 ms, although this value may vary).</p>

#### 3.3.3 Errors

When an error with the script is detected, the Status object (0x2040, 0x2) is set to a value signaling the type of error. There are four distinct types of errors that are detectable at different stages of script execution:

1. **File is non-existent or corrupted (Status = 0)**: This is set when the script is not stored on the emDrive, or the stored script is corrupted. This error is triggered when script verification fails, either when the device powers on or whenever a new script is downloaded.
2. **Compilation failed (Status = 1)**: This is set when the script could not be compiled, which could be caused by syntax errors or running out of memory. This error is triggered every time script compilation fails, such as when the script is restarted, executed for the first time, or downloaded while another script is already executing, causing the new script to be automatically compiled after downloading.
3. **Execution failed (Status = 2)**: This is set when an error occurs during runtime—such as in initialization, loop, or other required routines—caused by several reasons like accessing nil objects, passing invalid values, missing functions, running out of memory, and others. This error is also raised if the `Error()` function is called from within the script.
4. **Script timed out and was stopped (Status = 6)**: This is set when the initialization, loop, or other required routines take longer to execute than expected.

<p class="callout info">The initialization routine must execute within 100 ms, while the loop and other routines are required to execute within 2 × `LoopPeriodMs`.</p>

<p class="callout info">Further details of what went wrong with the script can be retrieved from the output object.</p>

All the above-mentioned errors are permanent. When an error is raised, emDrive protection is activated, and emDrive enters an error state from which it cannot recover (refer to the emDrive manual for more details about protections and error states). At this point, the script should be corrected for errors, downloaded to the emDrive, and then the device should be reset to clear the error.

#### 3.3.4 Debugging

There is no proper debugging mechanism in place; however, utilizing Lua I/O objects and general-purpose CANopen objects, some form of limited debugging is possible. Using the input object, the user can control the flow of the program. The user can also write debug information to the output object. Additionally, all objects at index 0x3020, can be used freely for debugging purposes.

![](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-csv5iyqd.png)

#### 3.3.5 Resource monitor

The resource monitor is used to measure characteristics of the script during compile-time, initialization, and runtime (loop). All available objects relevant to resource monitoring are shown under object 0x2031 and described in Table 53.

![](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-mzioj2yl.png)

<div align="center" id="bkmrk-table-53%3A-script-res">  
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border-spacing: 0px; width: 67.7778%; height: 411.702px;"><caption>Table 54: Script resource monitor objects description</caption><thead><tr style="height: 23.4896px;"><td style="width: 0%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="247">**<span lang="EN-US" style="font-size: 9.0pt;">Name</span>**

</td><td style="width: 0%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="301">**<span lang="EN-US" style="font-size: 9.0pt;">Description</span>**

</td></tr></thead><tbody><tr style="height: 45.8681px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">EnableLoopMonitor</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Enable loop resource monitoring which includes execution time and RAM usage.</span>

</td></tr><tr style="height: 23.4896px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Time\_Loop\_Immediate</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Immediate measured loop duration \[us\].</span>

</td></tr><tr style="height: 180.139px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 180.139px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Time\_Loop\_Maximum</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 180.139px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Maximum measured loop duration \[us\].</span>

<span lang="EN-US" style="font-size: 9.0pt;"> </span>

<span lang="EN-US" style="font-size: 9.0pt;">This value might sometimes appear unreasonably large that is when task running Lua script gets interrupted by higher priority tasks.</span>

<span lang="EN-US" style="font-size: 9.0pt;"> </span>

<span lang="EN-US" style="font-size: 9.0pt;">Write 0 to clear value and prepare it for new measurement.</span>

</td></tr><tr style="height: 45.8681px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Time\_Initialization</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Time \[ms\] required to execute initialization routine.</span>

</td></tr><tr style="height: 45.8681px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Time\_Compile</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Time \[ms\] required to load the script - that is time to script initialization.</span>

</td></tr><tr style="height: 23.4896px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Memory\_Free</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Immediately available RAM \[byte\].</span>

</td></tr><tr style="height: 23.4896px;"><td style="width: 0%; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="247"><span lang="EN-US" style="font-size: 9.0pt;">Memory\_Used</span>

</td><td style="width: 0%; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0cm 1.5pt; height: 23.4896px;" valign="top" width="301"><span lang="EN-US" style="font-size: 9.0pt;">Immediately used RAM \[byte\].</span>

</td></tr></tbody></table>

</div>Initialization and compile-time measurements are performed every time a new script is downloaded and executed or when an existing script is restarted. Memory and loop time monitoring must be explicitly enabled by setting `EnableLoopMonitor` to 1. This is because these measurements are calculated every loop, thereby shortening the processing time allocated to the script.

### 3.4 Using the emdrive Library

#### 3.4.1 Option 1: Automatic Setup

1. **Add Code to Script**
    
    
    - In `firstscript.lua`, add the following line:  
          
        ```lua
        require('emdrive')
        ```
2. **Apply Path Modification**
    
    
    - A pop-up window will appear in the bottom right corner. Click "Apply and modify."
    - After applying, delete the `require('emdrive')` line.  
        [![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/NgCimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/NgCimage.png)
3. **Check .vscode Folder**
    
    
    - A new folder named `.vscode` will be created.
    - Inside, there will be a `settings.json` file containing the path to the library.

#### 3.4.2 Option 2: Manual Setup

1. **Create .vscode Folder**
    
    
    - Manually create a `.vscode` folder in your workspace.
2. **Create settings.json File**
    
    
    - Inside the `.vscode` folder, create a `settings.json` file.
3. **Add Library Path to settings.json**
    
    
    - Add the following code to `settings.json`: <div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">  
        </div><div class="overflow-y-auto p-4" dir="ltr">  
        </div></div>```json
        {
            "lua.workspace.library": [
                "D:/LuaLibraries"
            ]
        }
        ```

## 4. Examples

### 4.1 Example 1: "Hello World"

Description:

Print "Hello World" every 100ms to IO\_Output.  
  
To make the script work, you need to have two functions: `Initialize` and `Loop`.

1. **Copy the Code**
    
    Copy the following code to an `example.lua` file:
    
    ```lua
    function Initialize()	
    	LoopPeriodMs = 100
    end
    
    function Loop()
        IO.Write("Hello World ")
    end
    ```
2. **Load the Script on the Inverter**
    
    
    - Go to `0x2040 0x05 - Script`.
    - Select "Write from file" and click "...".
    - A pop-up window will appear. Locate the saved script and click "Open".
    - Click "Write".  
        <div drawio-diagram="133"><img src="http://help.emsiso.com/uploads/images/drawio/2024-07/drawing-12-1719911353.png" alt=""/></div>
3. **Check if the Script is Valid**
    
    
    - Go to `0x2040 0x02 - Status`.
    - The value "3" indicates the downloaded file is valid.
4. **Run the Script**
    
    
    - Set `0x2040 0x03 - Control` to `2`.
    - If the script is running, the status value should be "5".
5. **View the Output**
    
    
    - Go to `0x2040 0x07 - IO_output`.
    - Click "Read" to see the "Hello World" string in the Description window.  
        <div drawio-diagram="134"><img src="http://help.emsiso.com/uploads/images/drawio/2024-07/drawing-12-1719911670.png" alt=""/></div>

### 4.2 Example 2: Data types &amp; variables

#### 4.2.1 Example 2.1: Data types

Lua is a lightweight, high-level programming language known for its simplicity and flexibility. It has several basic data types, each serving a different purpose. Here are the main data types in Lua along with examples for each:

1. Nil  
    Represents the absence of a value.
2. Boolean  
    Represents a boolean value, either true or false.
3. Number  
    Represents both integer and floating-point numbers.
4. String  
    Represents a sequence of characters.
5. Table  
    Represents associative arrays, which can be used as arrays, dictionaries, or other data structures.
6. Function  
    Represents a callable function.

```lua
function Initialize()	
	LoopPeriodMs = 100
end

function Loop()
    
    -- 1. Nil
    local myVariable = nil
    IO.Print(myVariable)  -- Output: nil

    -- 2. Boolean
    local isTrue = true
    local isFalse = false
    IO.Print(isTrue)  -- Output: true
    IO.Print(isFalse)  -- Output: false

    -- 3. Number
    local integerNumber = 42
    local floatingNumber = 3.14
    IO.Print(integerNumber)  -- Output: 42
    IO.Print(floatingNumber)  -- Output: 3.14

    -- 4. String
    local myString = "Hello, Lua!"
    IO.Print(myString)  -- Output: Hello, Lua!

    -- 5. Table
    local myTable = { key1 = "value1", key2 = "value2" }
    IO.Print(myTable.key1)  -- Output: value1
    IO.Print(myTable.key2)  -- Output: value2

    local arrayTable = { "apple", "banana", "cherry" }
    IO.Print(arrayTable[1])  -- Output: apple

    -- 6. Function
    local function myFunction(a, b)
      return a + b
    end
    IO.Print(myFunction(2, 3))  -- Output: 5
 
    -- 6. Anonymous function
    local anonFunction = function(x, y)
      return x * y
    end
    IO.Print(anonFunction(4, 5))  -- Output: 20

end
```

#### 4.2.2 Example 2.2: Variables

1. Global variables  
    Global variables are accessible from anywhere in the program unless shadowed by a local variable of the same name. By default, any variable declared without the `local` keyword is global.  
    ```lua
    myGlobalVariable = 10  -- Global variable
    
    function printGlobal()
      print(myGlobalVariable)
    end
    
    printGlobal()  -- Output: 10
    ```
2. Local Variables  
    Local variables are only accessible within the block or function where they are declared. They help avoid polluting the global namespace and can be used to manage scope more effectively.  
    ```lua
    local myLocalVariable = 20  -- Local variable
    
    function printLocal()
      local myLocalVariable = 30  -- Local to this function
      print(myLocalVariable)
    end
    
    printLocal()  -- Output: 30
    print(myLocalVariable)  -- Output: 20
    ```
3. Table fields  
    Variables can also be fields of tables, allowing for the creation of more complex data structures like arrays, dictionaries, and objects.  
    ```lua
    local myTable = {
      field1 = "Hello",
      field2 = "World"
    }
    
    print(myTable.field1)  -- Output: Hello
    print(myTable.field2)  -- Output: World
    ```

**Variable scope**

- **Global Scope:** Variables declared outside of any function or block are global by default.
- **Local Scope:** Variables declared with the `local` keyword within a function, block, or loop are local to that block.

1. Global vs. Local  
    ```lua
    myGlobal = "I am global"
    
    function testScope()
      local myLocal = "I am local"
      print(myGlobal)  -- Accessible
      print(myLocal)   -- Accessible
    end
    
    testScope()
    
    print(myGlobal)  -- Accessible
    -- print(myLocal) -- Error: myLocal is not accessible here
    ```
2. Local Variable Shadowing  
    ```lua
    local x = 5  -- Local variable in the main chunk
    
    function shadowTest()
      local x = 10  -- Local variable in the function
      print(x)  -- Output: 10
    end
    
    shadowTest()
    print(x)  -- Output: 5
    ```

<p class="callout warning">Global variables and tables use a lot of memory, especially in embedded systems. To save memory, it's best to use local variables whenever possible.   
If you use a global variable at the start of your code and don't need it later, clear the global variable to free up memory. You can do this by adding the following code:</p>

```lua
myGlobalVariable = nil
```

### 4.3 Example 3: Inputs/Outputs

#### 4.3.1 Example 3.1: Use of digital inputs &amp; outputs

Turn low side 1 - ON when switch on digital pin 1 is switched ON.

```lua
function Initialize()	
	LoopPeriodMs = 10
end

function Loop()

    local switch = Digital.Get(DIGITAL_IN_1)

    if switch == 1 then
        Digital.Set(LOW_SIDE_1, 1)
    else
        Digital.Set(LOW_SIDE_1, 0)
    end
end
```

#### 4.3.2 Example 3.2: Use of analog inputs

Print analog value of analog input 1 when switch on digital pin 1 is switched ON.

```lua
function Initialize()	
	LoopPeriodMs = 10
end

function Loop()

    local switch = Digital.Get(DIGITAL_IN_1)

    if switch == 1 then
        local rawVal = Analog.Get(ANALOG_IN_1)
        IO.Print(rawVal)    
    end
end
```

### 4.4 Example 4: Blink LED

#### 4.4.1 Example 4.1: Blink LED - "delay"

Loop period is set to 1000ms  
LED is connected on low side 1.  
Blink LED every 0.5s with Time.WaitMs().

```lua
function Initialize()	
	LoopPeriodMs = 1000
end

function Loop()

    local ledState = Digital.Get(LOW_SIDE_1)

    if(ledState == 0) then
        Digital.Set(LOW_SIDE_1, 1)
    else
        Digital.Set(LOW_SIDE_1, 0)
    end

    Time.WaitMs(500)

end
```

If we set the LoopPeriodMs to 100ms, the script stops running and shows a status of "6", meaning "Script timed out and was stopped."

Here are the key points to understand:

- **Time.WaitMs() Function**: This function pauses the script for a specified time. In our example, it pauses for 0.5 seconds.
- **LoopPeriodMs Setting**: We set the script to loop every 100ms.
- **Error Explanation**: Since the script must loop every 100ms but pauses for 0.5 seconds, it causes an error.

<p class="callout warning">**Important Note**: Be very careful when using the Time.WaitMs() function to avoid such errors.</p>

#### 4.4.2 Example 4.2: Blink LED - using loop time

We want the LED to blink every 0.5 seconds, while the main loop runs every 10ms. Here's how we do it:

<div class="flex-shrink-0 flex flex-col relative items-end" id="bkmrk--23"><div><div class="pt-0.5 juice:pt-0"><div class="gizmo-bot-avatar flex h-6 w-6 items-center justify-center overflow-hidden rounded-full juice:h-8 juice:w-8">  
</div></div></div></div><div class="group/conversation-turn relative flex w-full min-w-0 flex-col agent-turn" id="bkmrk-count-loops%3A-we-coun"><div class="flex-col gap-1 md:gap-3"><div class="flex flex-grow flex-col max-w-full"><div class="min-h-[20px] text-message flex flex-col items-start whitespace-pre-wrap break-words [.text-message+&]:mt-5 juice:w-full juice:items-end overflow-x-auto gap-2" data-message-author-role="assistant" data-message-id="f1b2a81e-8005-4fbd-ad4a-ba47ce2b13a0" dir="auto"><div class="flex w-full flex-col gap-1 juice:empty:hidden juice:first:pt-[3px]"><div class="markdown prose w-full break-words dark:prose-invert dark">1. **Count Loops**: We count each loop from 1 to 50.
2. **Multiply Counter**: Multiply the counter by the loop period (10ms).
3. **Check Reminder**: Divide the result by 500.
4. **Toggle Output**: If the remainder is 0, we toggle the LED.

</div></div></div></div></div></div>```lua
Main_loop_period = 10
Counter = 1


function Initialize()	
	LoopPeriodMs = Main_loop_period
end

function Loop()

    if ((Counter)*Main_loop_period)%500==0 then
    
        local ledState = Digital.Get(LOW_SIDE_1)

        if(ledState == 0) then
            Digital.Set(LOW_SIDE_1, 1)
        else
            Digital.Set(LOW_SIDE_1, 0)
        end

    end
 
    if Counter<50 then
        Counter=Counter+1
    else
        Counter=1
    end

end
```

#### 4.4.3 Example 4.3: Blink LED - using processor time

  
The script initializes a start time variable and defines two functions. In the `Loop` function, the script checks if the `StartTime` is nil and if so, sets it to the current time in milliseconds.  
The `Loop` function then continuously gets the current time in milliseconds. If 500 milliseconds have passed since the `StartTime`, it resets the `StartTime` to the current time.   
It then gets the state of a digital output `LOW_SIDE_1`.  
If `LOW_SIDE_1` is off (state is 0.0), it turns it on (state to 1.0).  
If `LOW_SIDE_1` is on (state is 1.0), it turns it off (state to 0.0).

This process repeats every 500 milliseconds, toggling the state of `LOW_SIDE_1` each time.

```lua
StartTime = nil

function Initialize()	
	LoopPeriodMs = 10
end

function Loop()

    --Execute only once at the start of the loop
    if(StartTime == nil) then
        StartTime = Time.GetMs()
    end

    --Chechk every loop what is the time
    local CurrentTime = Time.GetMs() 

    if (CurrentTime - StartTime >= 500) then
        StartTime = CurrentTime

        local ledState = Digital.Get(LOW_SIDE_1)

        if(ledState == 0) then
            Digital.Set(LOW_SIDE_1, 1)
        else
            Digital.Set(LOW_SIDE_1, 0)
        end

    end
end
```

### 4.5 Example 5: CAN send

#### 4.5.1 Example 5.1: (CAN send simple message)

To send a CAN message every 100ms with an ID of 0x205 and data value 500 using the first 2 bytes, follow these steps:

[![image.png](http://help.emsiso.com/uploads/images/gallery/2024-07/scaled-1680-/tnJimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-07/tnJimage.png)

1. **Use Template**:
    
    
    - Start with example 4.3 as a template.
2. **Add Variables and Functions**:
    
    
    - Define a `CanID` variable.
    - Initialize CAN with the `CAN.Initialize()` function.
3. **Sending Parameters**:
    
    
    - Use the `CAN_TX_ONLY` parameter for sending.
    - Messages will not be extended.
    - Set filters to 0 since we are only sending.
4. **Modify the Code**:
    
    
    - Delete the code for toggling the output.
5. **Create Custom Function**:
    
    
    - Create a function that is called every 100ms.
    - Name the argument `Data_raw`.
    - Split `Data_raw` into 2 bytes.
    - Send the data using the `CAN.Send()` function.

```lua
CanID = 0x205

StartTime = nil

function Initialize()

    CAN.Initialize(CAN_TX_ONLY,false,0,0)

	LoopPeriodMs = 10
end

function Loop()

    --Execute only once at the start of the loop
    if(StartTime == nil) then
        StartTime = Time.GetMs()
    end

    --Chechk every loop what is the time
    local CurrentTime = Time.GetMs() 

    if (CurrentTime - StartTime >= 100) then
        StartTime = CurrentTime
        SendData(500)
    end
end

function SendData(Data_raw)
    local val = Data_raw
    local byte0 = math.floor(val) & 0xFF
    local byte1 = (math.floor(val) & 0xFF00) >> 8
    CAN.Send(CanID,{byte0,byte1,0,0,0,0,0,0})
end
```

In this example we only need 2 bytes, thus we don't need to send all 8 bytes out. You could do this instead:

```
 CAN.Send(CanID,{byte0,byte1})
```

#### 4.5.2 Example 5.2 : CAN send extended message (J1939)

We will do the same as in example 5.1 except we will send an extended message (It will be a J1939 message PH3 - the data order might be different in the standard).

   
ID = 0x18FF8203.   
  
The only thing we need to change is 2 lines, we need to change the CanID and in the CAN.Initialize() function, the boolean value to true. If we change only the CanID then the message will still be sent out but the ID will be 0x199 (last 3 digits of - ID 0x18FF8199).

```lua
CanID = 0x18FF8199
CAN.Initialize(CAN_TX_ONLY,true,0,0)
```


### 4.6 Example 6: CAN receive

#### 4.6.1 Example 6.1 : CAN receive

In this example we will turn ON and OFF a LED that is connected on low side 1 with a received can message.  
The Can ID has to be 0x123 and we will send only one byte of data. If the value of data is 1 then the LED will be turned ON, otherwise it will be turned OFF.   
   
To use the CAN receive function we need to change the CAN.Initialite() and add a function called "CAN.Received(message)". With the following code we always go into the CAN.Received() function when a message is received and then we check if the ID is correct.

```lua
function Initialize()
    CAN.Initialize(CAN_RX_TX,false,0,0)
	LoopPeriodMs = 10
end

function Loop()


end

function CAN.Received(message)
    if (message.ID == 0x123) then
        IO.Print(" Data1: ", message.Data[1])
        if(message.Data[1] == 1) then
            Digital.Set(LOW_SIDE_1, 1)
        else
            Digital.Set(LOW_SIDE_1, 0)
        end
    end
end
```

We can also add a filter so we only go into the CAN.Received() when the message has a proper ID. We achieve this with the following code.

```lua
function Initialize()
    CAN.Initialize(CAN_RX_TX,false,0x123,0x123)
	LoopPeriodMs = 10
end

function Loop()


end

function CAN.Received(message)
    --if (message.ID == 0x123) then
    IO.Print(" Data1: ", message.Data[1])
    if(message.Data[1] == 1) then
        Digital.Set(LOW_SIDE_1, 1)
    else
        Digital.Set(LOW_SIDE_1, 0)
    end
    --end
end
```

### 4.7 Example 7: Read &amp; Set CANopen objects

  
In this example, we'll use an analog input (HW AIN1) as a throttle to set the motor velocity reference (object `0x3010 0x05`). We will also read this object and print its value to the Lua output. Additionally, we'll limit the maximum RPM using the math library to prevent the motor from running away if there's a problem with the analog reading.

0V = 0RPM  
5V = 200RPM  
  
For this example to work you need an inverter that is configured to work with the connected motor. You need to be first able to spin it in velocity mode using the configurator.  
When you start the script go to operational and turn on PWMs manually.

<p class="callout warning">If the analog throttle is damaged (either a short circuit or a broken circuit), there is no safety system in place. Here’s what can happen:  
  
If the circuit is broken, no voltage will be applied, and the RPM will be 0.  
If there is a short circuit, the inverter will receive the full 5V on the analog input, causing the RPM to go to the maximum.  
  
To prevent these issues, we need to add safety features. These will be demonstrated in Example 8.</p>

```lua
VelocityRef = {0x3010, 0x05}

function Initialize()
	LoopPeriodMs = 10
end

function Loop()
   

    local rpm = Analog.Get(ANALOG_IN_1) * 40
    rpm = math.min(rpm,200)

    CANopen.SetObjectValue(VelocityRef, rpm)
    
    local VelRef_from_CANopen = CANopen.GetObjectValue(VelocityRef)

    IO.Print(VelRef_from_CANopen)
end
```

### 4.8 Example 8: Demo application

#### 4.8.1 Example 8.1 : Demo application using CANopen objects.

In this example, we will demonstrate how to use the HW AIN1 input for a simple throttle control with a potentiometer (0-5V).

- **Throttle Input: HW AIN1 (0-5V Potentiometer)**
    - Minimum RPM: 0 (corresponds to 0.5V)
    - Maximum RPM: 200 (corresponds to 4.5V)
    - Motor Stop Conditions: 
        - If the throttle voltage is below 0.2V or above 4.8V, the motor will stop to protect against short and break issues.
    - PWM Enable Condition: 
        - If the throttle voltage is below 0.5V, the PWM signals will be enabled

```lua
function Initialize()

    CANopen.SetObjectValue(VelocityRef, 0) -- Set Velocity ref to 0
	CANopen.SetObjectValue(ControlMode, 1) -- Set velocity mode
	CANopen.SetNMTState(CO_OPERATIONAL)    -- Go into operational mode

	LoopPeriodMs = 100
end

function Loop()
    local throttleVoltage = Analog.Get(ANALOG_IN_1)
    -- Decide whether to enable or disable the motor
    if Digital.Get(DIGITAL_IN_1) == 1 then
        -- only enable if voltage on 0.2 < ANALOG_IN_1 < 0.5 V so the motor does not start ang goes to high RPM
        if  (0.2 < throttleVoltage and throttleVoltage < 0.5) then
            CANopen.SetObjectValue(PwmControl, 1)
        end
    else
        CANopen.SetObjectValue(PwmControl, 0)
    end

    if (throttleVoltage > 0.2 and throttleVoltage < 4.8) == true then
           -- Map values 0.5 - 4.5 V to 0 - 200 RPM and
            local rpm = (throttleVoltage - 0.5) / 4 * 200
            rpm = math.min(rpm, 200)
            rpm = math.max(rpm, 0)
            CANopen.SetObjectValue(VelocityRef, rpm)
    else
        CANopen.SetObjectValue(VelocityRef, 0)
        CANopen.SetObjectValue(PwmControl, 0)
    end
end
```

#### 4.8.2 Example 8.2 : Demo application using dedicated motor library.

In this example we will have the same functionality of the code as in example 8.1. but with the use of motor library  
With the use of the motor library the code is easier to read and write than example 8.1.

```lua
function Initialize()

    Motor.SetReferenceVelocity(0)       -- Set Velocity ref to 0
	Motor.SetControlMode(VELOCITY_MODE) -- Set velocity mode
	CANopen.SetNMTState(CO_OPERATIONAL) -- Go into operational mode

	LoopPeriodMs = 100
end

function Loop()
    local throttleVoltage = Analog.Get(ANALOG_IN_1)
    -- Decide whether to enable or disable the motor
    if Digital.Get(DIGITAL_IN_1) == 1 then
        -- only enable if voltage on 0.2 < ANALOG_IN_1 < 0.5 V so the motor does not start ang goes to high RPM
        if  (0.2 < throttleVoltage and throttleVoltage < 0.5) then
            Motor.Enable()
        end
    else
        Motor.Disable()
    end

    if (throttleVoltage > 0.2 and throttleVoltage < 4.8) == true then
           -- Map values 0.5 - 4.5 V to 0 - 200 RPM and
            local rpm = (throttleVoltage - 0.5) / 4 * 200
            rpm = math.min(rpm, 200)
            rpm = math.max(rpm, 0)
            Motor.SetReferenceVelocity(rpm)
    else
        Motor.SetReferenceVelocity(0)
        Motor.Disable()
    end
end
```

### 4.9 Example 9: Throttle script (state - machine)

##### Throttle Control

- **Adjusting the Throttle:** Use the potentiometer connected to Analog\_IN\_1.
- **Protection:** The potentiometer is protected against short and break circuits.
- **Deadband:** A deadband of 0.3V is set for the potentiometer.
- **Speed Limits (needs to be set in objects described below):** 
    - Minimum speed: 0 RPM
    - Maximum speed: 300 RPM

##### Motor Operation

- **Activation:**
    - The motor runs only when digital pin 1 (ON/OFF switch) is connected.
    - Change motor direction using a switch on digital pin 3.
- **Speed Setting:**
    - Forward max speed: Object 0x3020 0x0D
    - Reverse max speed: Object 0x3020 0x0E
    - Switching direction at max speed changes to the corresponding reverse speed.

##### LED Diagnostics

- **LED Indicator (HS1):**
    - **On:** System working normally.
    - **Blinking:** System in error mode.
- **Error Blink Codes:**
    - **Error 2:** Blinks twice, then pauses.
    - **Error 3:** Blinks three times, then pauses.

##### Voltage and RPM Details

- **Working Voltage Range:**
    - Minimum RPM: at 0.5V
    - Maximum RPM: at 4.5V
    - Deadband: 0.3V
- **Error Conditions:**
    - **ERROR1:** Voltage out of bounds
    - **ERROR2:** Analog\_IN\_1 &lt; (Min\_Volt - Deadband)
    - **ERROR3:** Analog\_IN\_1 &gt; (Max\_Volt + Deadband)

##### CANopen Error Messages

- **Error Message (0x80 + nodeID):**
    - Sent every 100ms in error state.
    - Data length: 8 bytes.
    - **Byte 0 Mapping:**
        - Bit 0: Throttle potentiometer error out of bounds
        - Bit 1: Throttle potentiometer break circuit error
        - Bit 2: Throttle potentiometer short circuit error
- **Warning Message (0x180 + nodeID):**
    - Sent every 100ms in start state.
    - Data length: 8 bytes.
    - **Byte 0:** Warning code 0x01 (Motor disabled, potentiometer not in min position)

<p class="callout warning">If the motor spins at Forward max speed and you switch the direction with the switch then it will spin at Reverse max speed  
</p>

```lua
-- Limits
MAX_RPM = 300
MIN_RPM = -300

-- Objects
FORWARD_MAX_SPEED_ID = {0x3020, 0xD}
REVERSE_MAX_SPEED_ID = {0x3020, 0xE}
LED_ID 				 = {0x30A4, 0x02}


-- Inputs
ENABLE_SW 	 = DIGITAL_IN_1
DIRECTION_SW = DIGITAL_IN_2
THROTTLE_IN  = ANALOG_IN_1
DIRECTION_IN = DIGITAL_IN_3


-- Voltage thresholds
THROTTLE_MIN_V = 0.5
THROTTLE_MAX_V = 4.5
DEADBAND 	 = 0.3


ERROR	  = 0
ERROR_reg = 0
WARNINGS  = 0


StartTime1	= nil
StartTIme2	= nil
StartTime3 	= nil
StartTime4 	= nil
FlagCounter = 0


DIN		  = {ON = 1, OFF = 0}
LED 	  = {OFF = 0x0, ON = 0x1}
DIRECTION = {FORWARD = 1, REVERSE = 0}

-- Application FSM
Application = {}


function Initialize()
	CAN.Initialize(CAN_TX_ONLY,false,0,0)

	Application.NextState = "Idle"

    Motor.SetReferenceVelocity(0)
	Motor.SetControlMode(VELOCITY_MODE)

	LoopPeriodMs = 10
end


function Loop()
	Application[Application.NextState]()
end


Application.Idle = function ()
	CANopen.SetObjectValue(LED_ID, LED.ON)
	CANopen.SetNMTState(CO_OPERATIONAL)
	Application.NextState = "Start"
end


Application.Start = function ()


    -- IF enable switch is off go to stop state
    if (Digital.Get(ENABLE_SW) == DIN.OFF ) then
		Application.NextState = "Stop"
		return
	end


    -- Get voltage
	local throttleVoltage = Analog.Get(THROTTLE_IN)


    -- Go into error state if throttle voltage is out of bounds
    if OutOfBounds(throttleVoltage, (THROTTLE_MIN_V - DEADBAND), (THROTTLE_MAX_V + DEADBAND)) == true then
		ERROR = (ERROR or 0) | 1
		Application.NextState = "Error"
		return
	end


    -- Check that voltage is bellow minimal throttle voltage - so that the motor does not start at high speed
	if Motor.GetState() == MOTOR_OFF then
		if throttleVoltage < (THROTTLE_MIN_V) then
            Motor.Enable()
			WARNINGS = WARNINGS & Negate_Xbit(1, 8)
            return
		else
			WARNINGS = (WARNINGS or 0) | 1
        end
	end

	-- Only set velocity reference when pwms are enabled
	if ((Motor.GetState() == MOTOR_RUN) and (throttleVoltage >= 0.5)) then
		-- Calculate Voltage
    	--local rpm = ((throttleVoltage - THROTTLE_MIN_V) * MAX_RPM) / (THROTTLE_MAX_V - THROTTLE_MIN_V)
		local rpm = ((throttleVoltage - THROTTLE_MIN_V) * GetMaxSpeed()) / (THROTTLE_MAX_V - THROTTLE_MIN_V)
    	-- Limit RPM
    	rpm = math.min(rpm, MAX_RPM)
    	rpm = math.max(rpm, MIN_RPM)
		IO.Print("REF: ", rpm)
    	-- Set ref
		Motor.SetReferenceVelocity(rpm)
	end

	-- Send warnings every 100ms
	local CurrentTime = Time.GetMs()
	if((StartTIme2 == nil) or (CurrentTime-StartTIme2) >= 100) then
		SendWarnings()
	end
end


Application.Stop = function ()
    Motor.SetReferenceVelocity(0)
	Motor.Disable()
    --When eneble sw is activated go to start state
	if (Digital.Get(ENABLE_SW) == DIN.ON) then
		Application.NextState = "Start"
	end
end

Application.Error = function ()

    Motor.Disable()
	Motor.SetReferenceVelocity(0)

	--local ledValue = CANopen.GetObjectValue(LED_ID)
    local throttleVoltage = Analog.Get(THROTTLE_IN)
	local ErrorBlinkCounter = 0
	local CurrentTime

	--If bit 0 = 1 then OutOfBounds is detected
	if (ERROR & 1) == 1 then
		if throttleVoltage < (THROTTLE_MIN_V - DEADBAND) then
			ERROR = ERROR | 2
			ERROR_reg = ERROR_reg | 1 -- set the generic error register
		elseif throttleVoltage > (THROTTLE_MAX_V + DEADBAND) then
			ERROR = ERROR | 4
			ERROR_reg = ERROR_reg | 1 -- set the generic error register
		else
			-- Clear ERROR bit 0, 1, 2
			ERROR = ERROR & Negate_Xbit(7, 16)
			-- Clear the generic error register
			ERROR_reg = ERROR_reg | Negate_Xbit(1, 8)
		end
	end

	-- Send Errors every 100ms
	CurrentTime = Time.GetMs()
	if ((StartTime1 == nil) or (CurrentTime - StartTime1) >= 100) then
		StartTime1 = CurrentTime
		SendError()
	end

	-- Determine how many times we want to blink the led
    if ((ERROR & 2) >> 1) == 1 then
        ErrorBlinkCounter = 2
    elseif ((ERROR & 4) >> 2) == 1 then
        ErrorBlinkCounter = 3
    end

    -- Start the blinking cycle if enough time has passed
	CurrentTime = Time.GetMs()
    if StartTime3 == nil or (CurrentTime - StartTime3) >= 3000 then
        StartTime3 = CurrentTime
        FlagCounter = 0
    end

    -- Handle the blinking logic
    if FlagCounter < 2 * ErrorBlinkCounter then
        if StartTime4 == nil or (CurrentTime - StartTime4) >= 300 then
            StartTime4 = CurrentTime
            FlagCounter = FlagCounter + 1

            -- Toggle LED
            --if ledValue == 0  then
            if FlagCounter % 2 == 1 then
				CANopen.SetObjectValue(LED_ID, LED.ON)
            else
                CANopen.SetObjectValue(LED_ID, LED.OFF)
            end
        end
	else
		-- Ensure the LED is off during the pause period
        CANopen.SetObjectValue(LED_ID, LED.OFF)
    end

    if ERROR == 0 then
		FlagCounter = 0
		Application.NextState = "Idle"
		return
	end
end


function GetMaxSpeed()
	if Digital.Get(DIRECTION_IN) == DIRECTION.FORWARD then
		return CANopen.GetObjectValue(FORWARD_MAX_SPEED_ID)
	end
	return CANopen.GetObjectValue(REVERSE_MAX_SPEED_ID)
end


function SendError()
	-- Send on ID + nodeID; we get the NodeId from CANopen off the inverter
	local CanID = 0x80 + CANopen.GetObjectValue({0x100B, 0x00})
	local byte0 = ERROR & 0xFF
	local byte1 = (ERROR & 0xFF00) >> 8
	local byte2 = ERROR_reg & 0xFF
	CAN.Send(CanID,{byte0, byte1, byte2, 0, 0, 0, 0, 0})
end

function SendWarnings()
	-- Send on PDO + nodeID;
	local CanID = 0x180 + CANopen.GetObjectValue({0x100B, 0x00})
	local byte0 = WARNINGS & 0xFF
	CAN.Send(CanID,{byte0, 0, 0, 0, 0, 0, 0, 0})
end


function OutOfBounds(throttleVoltage, minVal, maxVal)
    if (throttleVoltage < minVal) or (throttleVoltage > maxVal) then
        return true
    else
        return false
    end
end


--- Fuctino to negate bits
---@param value number Value to negate
---@param xBit number Number of bites e.g 16bit => xBit = 16
function Negate_Xbit(value, xBit)
    local negated = 0
    for i = 0, (xBit - 1) do
        if (value & (1 << i)) == 0 then
            negated = negated + (1 << i)
        end
    end
    return negated
end
```

### 4.10 Example 10: Read protections of motor control in Lua

Purpose:  
This script is designed to monitor and report various hardware errors in motor control systems, using Lua to check status registers for issues such as overtemperature, voltage discrepancies, and communication failures.

Description:

- Protection\_bits Table: Lists each error with a unique bitmask for identification.
- Initialize Function: Sets initial conditions, including the loop frequency.
- Loop Function: Repeatedly retrieves the current error status, checks each potential error against the current status, and prints messages for any active errors.

Usage:  
It is best to use only the protections that you need to check or send. By doing this, you can make the `Protection_bits` table smaller, which in turn reduces memory usage—a crucial consideration in environments with limited resources. Either way, if the value returned from the function is greater than 0, an error has occurred.

```lua
local Errors = {}
local Protection_bits = {
    {0x1, "sw_phase_error"},
    {0x2, "sw_DC_link_overvoltage_error"},
    {0x4, "sw_DC_link_undervoltage_error"},
    {0x8, "bridge_overtemperature_error"},
    {0x10, "capacitor_overtemperature_error"},
    {0x20, "motor_overtemperature_error"},
    {0x40, "current_offset_error"},
    {0x80, "CAN_command_timeout_error"},
    {0x100, "system_self_test_failed_error"},
    {0x800, "motor_feedback_error"},
    {0x8000, "CAN_communication_error"},
    {0x10000, "logic_supply_monitor_error"},
    {0x20000, "dc_link_overvoltage_comparator_error"},
    {0x80000, "gatedriver_error"},
    {0x100000, "HV_interlock"},
    {0x200000, "motor_temperature_sensor_fail"},
    {0x400000, "capacitor_temperature_sensor_fail"},
    {0x800000, "bridge_temperature_sensor_fail"},
    {0x1000000, "bridge_fault"},
    {0x2000000, "logic_supply_fault"},
    {0x4000000, "bus_bar_fault"},
    {0x8000000, "system_initialization_error"},
    {0x10000000, "fault_Vrefs_chip"},
    {0x20000000, "application_error_state"},
    {0x40000000, "motor_control_error"}
    --{0x80000000, "error_extended"}
}

-- Initialize
function Initialize()
    LoopPeriodMs = 10
end

function Loop()
    local protections = Motor.GetProtectionsLow()
    
    for i = 1, #Protection_bits do
        local bitmask = Protection_bits[i][1]
        local varname = Protection_bits[i][2]
        Errors[i] = {bitmask = bitmask, name = varname, state = (protections & bitmask) == bitmask}
    end

    -- Example usage to print all active errors
    for i = 1, #Errors do
        if Errors[i].state then
            IO.Print("Error detected: " .. Errors[i].name)
        end
    end
end
```

## 5. Benchmark

### 5.1 Examples for benchmark:

#### 5.1.1 00\_Empty\_script  


```lua
function Initialize()
	LoopPeriodMs = 10
end

function Loop()
end
```

#### 5.1.2 01\_GetObject

```lua
function Initialize()
	LoopPeriodMs = 10
end

function Loop()
	for i = 1,100 do
		CANopen.GetObjectValue({0x30B0, 0x04})
	end
end
```

#### 5.1.3 02\_GetObject\_with\_library

```lua
function Initialize()
	LoopPeriodMs = 10
end

function Loop()
	for i = 1,100 do
		Digital.Get(DIGITAL_IN_4)
	end
end
```

#### 5.1.4 03\_GetSet

```lua
function Initialize()
	LoopPeriodMs = 10
end

function Loop()
	for i = 1,50 do
		local throttle = CANopen.GetObjectValue({0x3090, 0x01})
		CANopen.SetObjectValue({0x3010, 0x05}, throttle * 40) --at 4.5V = 180RPM
	end
end
```

#### 5.1.5 04\_GetSet\_with\_library

```lua
function Initialize()
	LoopPeriodMs = 10
end

function Loop()
	for i = 1,50 do
		local throttle = Analog.Get(ANALOG_IN_1)
		Motor.SetReferenceVelocity(throttle * 40) --at 4.5V = 180RPM
	end
end
```

### 5.2 Results

We loaded each script onto the inverter and started the "Resource Manager." We ran the script for a specific period and logged the variables to a live chart, from which we then created the following table:

<p class="callout info">Examples from 05 onwards can be found under the title 4. Examples.</p>

<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" id="bkmrk-table-55%3A-script-ben" style="border-collapse: collapse; border-spacing: 0px; width: 99.5062%; height: 469.348px;"><caption>Table 55: Script benchmark tests</caption><thead><tr style="height: 45.8681px;"><td style="width: 39.1363%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="247">**<span lang="EN-US" style="font-size: 9.0pt;">Name of script</span>**

</td><td style="width: 9.44242%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="301">**<span lang="EN-US" style="font-size: 9.0pt;">RAM usage \[kB\]</span>**

</td><td style="width: 8.82121%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">RAM free  
\[kB\]</span>**

</td><td style="width: 10.3121%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">RAM used  
\[%\]</span>**

</td><td style="width: 9.93939%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Avg. loop duration \[us\]</span>**

</td><td style="width: 10.6848%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Compile time \[ms\]</span>**

</td><td style="width: 11.6788%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Initialization time \[ms\]</span>**

</td></tr></thead><tbody><tr style="height: 29.4688px;"><td style="height: 29.4688px; width: 39.1363%;">00\_Empty\_script</td><td class="align-center" style="height: 29.4688px; width: 9.44242%;">11.800</td><td class="align-center" style="height: 29.4688px; width: 8.82121%;">24.040

</td><td align="right" class="xl63 align-center" height="20" style="height: 29.4688px; width: 10.3121%;" width="64">33</td><td class="align-center" style="height: 29.4688px; width: 9.93939%;">13</td><td class="align-center" style="height: 29.4688px; width: 10.6848%;">2.7</td><td class="align-center" style="height: 29.4688px; width: 11.6788%;">0.175</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">01\_GetObject</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">11.728</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">24.112</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">33</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">5000</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">2.9</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.173</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">02\_GetObject\_with\_library</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">11.784</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">24.056</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">33</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">510</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">2.94</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.241</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">03\_GetSet</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.088</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.752</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">5000</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.178</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.177</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">04\_GetSet\_with\_library</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.128</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.712</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">450</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.149</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.174</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">05\_Timer\_example\_4\_1</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.064</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.776</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">500407</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.294</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.242</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">06\_Timer\_example\_4\_2</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.200</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.640</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">17</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.669</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.177</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">07\_Timer\_example\_4\_3</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.232</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.608 </td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">19</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.747</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.175</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">08\_Example\_5</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">12.104</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">23.736</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">34</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">18</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">4.332</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.213</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">09\_Example\_6</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">15.512</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">20.328</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">43</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">9</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.468</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.225</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">10\_Example\_7</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">22.048</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">12.792</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">63</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">125</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">3.506</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.191</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">11\_Example\_8\_1</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">13.472</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">22.368</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">38</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">110</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">5.030</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.293</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">12\_Example\_8\_2</td><td class="align-center" style="height: 29.8785px; width: 9.44242%;">13.072</td><td class="align-center" style="height: 29.8785px; width: 8.82121%;">22.768</td><td align="right" class="xl63 align-center" height="20" style="height: 29.8785px; width: 10.3121%;">36</td><td class="align-center" style="height: 29.8785px; width: 9.93939%;">50</td><td class="align-center" style="height: 29.8785px; width: 10.6848%;">4.628</td><td class="align-center" style="height: 29.8785px; width: 11.6788%;">0.250</td></tr><tr style="height: 35.4688px;"><td style="height: 35.4688px; width: 39.1363%;">13\_Example\_9</td><td class="align-center" style="height: 35.4688px; width: 9.44242%;">21.112</td><td class="align-center" style="height: 35.4688px; width: 8.82121%;">14.728</td><td align="right" class="xl63 align-center" height="20" style="height: 35.4688px; width: 10.3121%;">59</td><td class="align-center" style="height: 35.4688px; width: 9.93939%;">250</td><td class="align-center" style="height: 35.4688px; width: 10.6848%;">15.756

</td><td class="align-center" style="height: 35.4688px; width: 11.6788%;">0.742</td></tr></tbody></table>

![Ram used [%]](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-3chsvi0d.png)

![Average loop time [us]](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-znzcz6k9.png)

Examples 01, 03, and 05 have too much loop time and were excluded from the chart.

As you can see from the table and charts, reading and writing values directly from the CANopen stack takes longer than using our library. For example, the 01\_GetObject example has an average loop time execution of 5ms, whereas the 02\_GetObject\_with\_library example has an average time of 510µs, which is approximately 10 times faster. Based on these results, it is better to use functions that directly interact with the inverter instead of the CANopen stack, where possible.

We can also see that the delay function used in example 05\_Timer\_example\_4\_1 has a very long loop time because we used the delay to blink an LED. This function must be used with caution and only for small delays if you have no other option.

For writing applications, we recommend using a state machine, which is more reliable. With a state machine, you have more control over what happens in each state and can properly define the transitions between states.

In section "5.3 Live chart data for each example", we can see the loop time, RAM used and RAM free for a specific time period. We can se that we have some spikes in loop time, which can indicate that some specific part of the code was executed or that the script was interrupted with a higher priority task. We can also see that the RAM usage can very based on which part of the code is executed.

### 5.3 Global variables benchmark

In this section, we will demonstrate how the number of global variables affects script RAM usage and loop execution time.

Below is the code that will be used to test 10 global variables. We will increase the number of global variables to 20, 30, 100, and 150, but the principle will remain the same

```lua
Global1 = 1
Global2 = 1
Global3 = 1
Global4 = 1
Global5 = 1
Global6 = 1
Global7 = 1
Global8 = 1
Global9 = 1
Global10 = 1

function Initialize()
	LoopPeriodMs = 10
end

function Loop()
  IO.Print(Global1)
  IO.Print(Global2)
  IO.Print(Global3)
  IO.Print(Global4)
  IO.Print(Global5)
  IO.Print(Global6)
  IO.Print(Global7)
  IO.Print(Global8)
  IO.Print(Global9)
  IO.Print(Global10)
end
```

In the table below, we recorded the data for different sets of global variables. We can observe that as the number of global variables increases, the compile time, initialization time, loop execution time, and RAM usage all increase. It is important to remember that we are limited by the loop execution time set in the initialize() function. If we exceed that time, we encounter an error.

More importantly, we need to carefully manage the number of global variables because excessive use can lead to memory overflow. As shown in the table below, having 150 global variables consumes around 75% of the RAM, but our code has almost no functionality. If we add the following code right after the Loop() function:

```lua
for i = 1,50 do
		local throttle = CANopen.GetObjectValue({0x3090, 0x01})
		CANopen.SetObjectValue({0x3010, 0x05}, throttle * 40) --at 4.5V = 180RPM
end
```

We see that the RAM usage jumps to 98%. This shows that RAM usage depends not only on the number of global variables but also on the quality of the code itself. Therefore, we need to write efficient code, which means avoiding the use of global variables, using local variables, and implementing proper algorithms.

<p class="callout info">For these reasons, it is difficult to specify the maximum number of global and local variables. We recommend testing your script continuously during development.</p>

<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" id="bkmrk-table-56%3A-how-the-nu" style="border-collapse: collapse; border-spacing: 0px; width: 99.5062%; height: 225.139px;"><caption>Table 56: How the number of globals affect the execution of a script</caption><thead><tr style="height: 45.8681px;"><td style="width: 39.1363%; border: 1pt solid windowtext; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="247">**<span lang="EN-US" style="font-size: 9.0pt;">Number of globals</span>**

</td><td style="width: 9.44242%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;" valign="top" width="301">**<span lang="EN-US" style="font-size: 9.0pt;">RAM usage \[kB\]</span>**

</td><td style="width: 8.82121%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">RAM free  
\[kB\]</span>**

</td><td style="width: 10.3121%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">RAM used  
\[%\]</span>**

</td><td style="width: 9.93939%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Avg. loop duration \[us\]</span>**

</td><td style="width: 10.6848%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Compile time \[ms\]</span>**

</td><td style="width: 11.6788%; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; background: rgb(168, 208, 141); padding: 0cm 1.5pt; height: 45.8681px;">**<span lang="EN-US" style="font-size: 9.0pt;">Initialization time \[ms\]</span>**

</td></tr></thead><tbody><tr style="height: 29.8785px;"><td style="height: 31.4583px; width: 39.1363%;">10 globals  
</td><td class="xl65 align-center" height="21" style="height: 31.4583px; width: 9.44242%;" width="82">12.656</td><td class="xl66 align-center" height="21" style="height: 31.4583px; width: 8.82121%;" width="74">23.184</td><td class="xl65 align-center" height="21" style="height: 31.4583px; width: 10.3121%;" width="92">35</td><td class="xl65 align-center" height="21" style="height: 31.4583px; width: 9.93939%;" width="87">200</td><td class="xl65 align-center" height="21" style="height: 31.4583px; width: 10.6848%;" width="81">3.874</td><td class="xl65 align-center" height="21" style="height: 31.4583px; width: 11.6788%;" width="81">0.257</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">20 globals</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.44242%;" width="82">14.480</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 8.82121%;" width="74">21.360</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.3121%;" width="92">40</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.93939%;" width="87">380</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.6848%;" width="81">4.942</td><td class="xl66 align-center" height="21" style="height: 29.8785px; border-top: none; width: 11.6788%;" width="81">0.412</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">30 globals</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.44242%;" width="82">14.688</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 8.82121%;" width="74">21.152</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.3121%;" width="92">41</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.93939%;" width="87">650</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.6848%;" width="81">6.018</td><td class="xl66 align-center" height="21" style="height: 29.8785px; border-top: none; width: 11.6788%;" width="81">0.591</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">100 globals</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.44242%;" width="82">25.408</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 8.82121%;" width="74">10.432</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.3121%;" width="92">71</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.93939%;" width="87">2000</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.6848%;" width="81">13.5</td><td class="xl66 align-center" height="21" style="height: 29.8785px; border-top: none; width: 11.6788%;" width="81">0.795</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">150 globals</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.44242%;" width="82">26.976</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 8.82121%;" width="74">8.864</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.3121%;" width="92">75</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.93939%;" width="87">3110</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.6848%;" width="81">18.4</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 11.6788%;" width="81">1.276</td></tr><tr style="height: 29.8785px;"><td style="height: 29.8785px; width: 39.1363%;">150 globals + 4 lines of code</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.44242%;" width="82">35.072</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 8.82121%;" width="74">768</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.3121%;" width="92">98</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 9.93939%;" width="87">8000</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 10.6848%;" width="81">18.9</td><td class="xl65 align-center" height="21" style="height: 29.8785px; border-top: none; width: 11.6788%;" width="81">1.213</td></tr></tbody></table>

## 6. Best practices

For further insights and practical tips, I recommend exploring "Programming in Lua," available at: [Programming in Lua](https://www.lua.org/gems/). Authored by experts in the field, this comprehensive resource offers invaluable guidance for Lua developers. It's worth noting that the entire topic is accessible free of charge as of April 24, 2024. Additionally, some sections of the topic include examples to further illustrate key concepts and techniques.

### 6.1 Minimizing Global Variables

The most common problem with Lua scripting occurs when the script becomes "big" and the programmer uses only or to much global, resulting in an "out of memory" error. In Lua scripting, it's imperative to exercise caution with global variables to prevent memory exhaustion and script failures, especially on embedded systems. Emphasizing the utilization of local variables whenever possible is paramount. By minimizing global variable usage, we mitigate the risk of memory overflow and enhance script performance.


## 7. Known issues and limitations

This section describes known issues and limitations, their causes, and solutions or mitigations if they exist.

### 7.1 Issues

#### 7.1.1 Lua is not enabled

Error 0x06070010 when loading a script may indicate Lua object 0x2040 0x01 isn't set to 1. To resolve, ensure proper access level in Configurator to unlock this feature. If you do not have the proper access level contact us.

[![image.png](http://help.emsiso.com/uploads/images/gallery/2024-04/scaled-1680-/YPqimage.png)](http://help.emsiso.com/uploads/images/gallery/2024-04/YPqimage.png)

[![image.png](http://help.emsiso.com/uploads/images/gallery/2024-04/scaled-1680-/jl3image.png)](http://help.emsiso.com/uploads/images/gallery/2024-04/jl3image.png)

#### 7.1.2 Output object out of memory error

When reading an output object whose value is periodically changing by the script, it is possible that an "Out of memory" error, as shown in Figure 8, may be reported by the emDrive Configurator.

![](http://help.emsiso.com/uploads/images/gallery/2024-07/embedded-image-zmy4rnas.png)

**<u><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Cause</span></u>**<span lang="EN-GB" style="mso-ansi-language: EN-GB;">: unsynchronized reading and writing to output object by script and emDrive Configurator at the same time.</span>

**<u><span lang="EN-GB" style="mso-ansi-language: EN-GB;">Solution:</span></u>**<span lang="EN-GB" style="mso-ansi-language: EN-GB;"> read output object again.</span>

#### 7.1.3 IO.Print() isn't functioning

If <span style="background-color: rgb(206, 212, 217);">*IO.Print()*</span> isn't functioning, it may signal an outdated firmware version. FW 1.12.2 - lacks support, while FW 1.13.2 onwards enables the function.

#### 7.1.4 Protections

If multiple protections are active, the CANopen read wont work for the protection object. (New FW will fix this issue)