C&H Technologies EM405-8 User manual

Manual Part No: 11030574A
MODEL
EM405-8
SCRIPTING MANUAL
ETHERNET
M-MODULE
CARRIER/
BRIDGE

ii
COPYRIGHT
C&H Technologies, Inc. (C&H) provides this manual "as is" without warranty of any kind,
either expressed or implied, including but not limited to the implied warranties of
merchantability and fitness for a particular purpose. C&H may make improvements and/or
changes in the product(s) and/or program(s) described in this manual at any time and without
notice.
This publication could contain technical inaccuracies or typographical errors. Changes are
periodically made to the information herein; these changes will be incorporated in new editions
of this publication.
Copyright © 2009, 2012 by C&H Technologies, Inc.
The information and/or drawings set forth in this document and all rights in and to inventions
disclosed herein which might be granted thereon disclosing or employing the materials, methods,
techniques, or apparatus described herein, are the exclusive property of C&H Technologies, Inc.
A Reader's Comment Form is provided at the back of this publication. If this form has been
removed address comments to:
C&H Technologies, Inc.
Technical Publications
800 Paloma Drive, Suite 150
Round Rock, Texas 78665
C&H may use or distribute any of the information you supply in any way that it believes
appropriate without incurring any obligations whatever.

iii
DOCUMENT REVISION NOTICE
C&H Technologies, Inc. makes every attempt to provide up-to-date manuals with the associated
equipment. Occasionally, throughout the life of an instrument, changes are deemed necessary to
equipment related documentation. The latest revision of our documentation is available for
download from our web site at http://www.chtech.com.
NOTE
The contents of any amendment may affect operation,
maintenance, or calibration of the equipment.

iv
INTRODUCTION
This manual describes the operation and use of the scripting features of the EM405-8 Ethernet
M-Module Carrier/Bridge (Part Number 11029380). The scripting features described throughout
this manual are available on all EM405-8’s containing firmware version 3.0 and later. Contained
within this manual are the functional details and the programmatic guidelines to adequately
develop and deploy script-based applications for the EM405-8.
The EM405-8 is one of many test, data acquisition and control modules provided by C&H
Technology and is one of a number of M-Module carriers in C&H Technologies’ product line.
All manufacturing options of the EM405-8 include the scripting features; however, only options
that include an internal mass storage device provide non-volatile storage of scripts and
autonomous operation using the startup script feature.
The part numbers of the EM405-8’s that are covered by this manual are:
Part Number Description
11029380-0001 EM405-8 with external triggers
11029380-0002 EM405-8 without external triggers
11029380-0003 EM405-8 with external triggers and 16GB mass storage
11029380-0004 EM405-8 without external triggers, but with 16GB mass storage
EM405-8’s that contain a firmware revision prior to 3.0 can be updated in the field to the most recent firmware
revision containing the scripting support. Please contact C&H Technologies Technical Support for update files and
detailed instructions.

v
TABLE OF CONTENTS
1.0 GENERAL DESCRIPTION ............................................................................................1
1.1 PURPOSE OF EQUIPMENT.............................................................................................2
1.2 THE LUA SCRIPTING LANGUAGE...............................................................................2
1.3 KEY FEATURES OF EM405-8 SCRIPTING ...................................................................2
1.4 APPLICABLE REFERENCES..........................................................................................3
2.0 USING AND MANAGING SCRIPTS ............................................................................4
2.1 COMMANDS..................................................................................................................... 4
2.1.1 ? | Help ......................................................................................................................... 4
2.1.2 Data.............................................................................................................................. 5
2.1.3 Halt............................................................................................................................... 5
2.1.4 List ...............................................................................................................................5
2.1.5 Read.............................................................................................................................6
2.1.6 Remove ........................................................................................................................ 6
2.1.7 Retrieve........................................................................................................................6
2.1.8 Run............................................................................................................................... 7
2.1.9 Socket?.........................................................................................................................8
2.1.10 Upload..........................................................................................................................8
2.1.11 Ver................................................................................................................................ 9
2.2 STORING SCRIPTS AND SUPPORTING FILES............................................................ 9
2.3 SCRIPTING SOCKET INTERFACE...............................................................................10
2.3.1 Configuring the Scripting Socket Interface ............................................................... 10
2.3.2 Connecting to the Scripting Socket Interface ............................................................11
2.3.3 Interactive Mode........................................................................................................11
3.0 DEVELOPING SCRIPTS.............................................................................................. 13
3.1 DEVELOPMENT SOFTWARE – EM405-8 IVI DRIVER SOFT FRONT PANEL......13
3.2 EM405-8 EXTENSIONS LIBRARY ............................................................................... 13
3.3 PASSING DATA.............................................................................................................. 20
3.4 CALLING M-MODULE DRIVERS................................................................................ 22
3.4.1 Using Alien to Call M-Module Drivers..................................................................... 22
3.4.2 Dealing with data.......................................................................................................25
3.4.2.1 Buffers................................................................................................................25
3.4.2.2 Arrays.................................................................................................................26
3.4.2.3 Pointer Unpacking..............................................................................................27
3.4.2.4 Callback Functions.............................................................................................27
3.4.3 Building M-Module Drivers into a Linux Shared Library......................................... 28
3.5 SHARING DATA BETWEEN SCRIPTS........................................................................28
3.6 STARTUP SCRIPT ..........................................................................................................28
3.7 USING THE MASS STORAGE DEVICE.......................................................................29
4.0 USING LUA TO WRITE CUSTOM WEB PAGES....................................................30
4.1 URL OF SCRIPT BASED PAGES.................................................................................. 30
4.2 ADDING A LINK TO THE C&H NAVIGATION MENU............................................. 31
4.3 URL OF PICTURES AND OTHER SUPPORTING FILES...........................................32
4.4 PASSING ARGUMENTS TO THE SCRIPT................................................................... 32
4.5 DEVELOPING THE PAGE CONTENT..........................................................................33

vi
LIST OF FIGURES
Figure 1 EM405-8 Scripting Utilities Architecture Diagram.........................................................1
Figure 2 Retrieve Script Download Format....................................................................................7
Figure 3 Script Upload Format.......................................................................................................9
Figure 4 Network Configuration Webpage ..................................................................................10
Figure 5 EM405-8 IVI Driver Scripting Panel Screenshot...........................................................13
Figure 6 Data Passing Example....................................................................................................21
Figure 7 M-Module Driver Example Code...................................................................................25
Figure 8 M-Module Driver Example Using Buffers ....................................................................26
Figure 9 M-Module Driver Example Using Arrays......................................................................27
Figure 10 Simple Lua Based Web Page .......................................................................................30
Figure 11 Example Adding Link to the Navigation Menu ...........................................................31
Figure 12 Example Linking to a User Image.................................................................................32
Figure 13 Example Retrieving Arguments from the URL ............................................................33
Figure 14 Example Using “l_em405web.lua” Library..................................................................35
LIST OF TABLES
Table I Use and Management Commands......................................................................................4
Table II. Functions in the EM405-8 Extensions Library..............................................................14
Table III. Alien Data Types ..........................................................................................................23
Table IV l_em405web.lua Library Functions................................................................................33

1
1.0 GENERAL DESCRIPTION
The scripting utilities of the EM405-8 M-Module Bridge provide enhanced programming
capabilities allowing the user to easily embed software on the bridge to improve performance
and further integrate a set of M-modules. The scripting utilities are based off of the Lua
programming language and include extensions and customizations designed specifically for the
EM405-8. An architecture diagram of the scripting utilities is shown in Figure 1. Since Lua is
an interpretive language, EM405-8 users can easily develop scripts without the need for an
expensive development environment.
By embedding a script or a set of scripts on the EM405-8, the burden for monitoring, configuring
and controlling the M-modules is taken off the network and placed onto the EM405-8’s embedded
processor. This provides significant performance improvements and allows the EM405-8 and
associated M-modules to be customized and configured. It can also act independently for a long
period of time without the need for a network client to monitor the device(s).
Figure 1EM405-8 Scripting Utilities Architecture Diagram
PART OF SCRIPTING EN
VIRONMENTFURNISHED
BYC&H
APPLICATION SPECIFIC
CUSTOMER DEVELOPMEN
T
HARDWARE
STANDARD AVAILABLE S
OFTWARE FROM C&H OR
THIRD PARTY
M-MODULES
EM405
-
8 UTILITIES
(TRIGGERS, FANS, ETC.)
EM405
-
8 LUA EXTENSIONS
M
-
MODULE ANSI
-
C DRIVERS
SCRIPTS
LUA STD LIBRARIES
ALIEN LIB
MASS STORAGE
EM405
-
8 SCRIPT MANAGEMENT
EM405
-
8 IVI DRIVER
DEVELOP SCRIPTS
MANAGE SCRIPTS
RUN SCRIPTS
VIEW SCRIPT OUTPUT
USER
APPLICATION
CONTROL SCRIPTS
SEND COMMANDS
RETRIEVE DATA
WEB BROWSER
CUSTOM SCRIPT-BASED
WEBPAGES
HOST
EM405
-
8
RUN
-
TIME ENVIRONMENT
EMBEDDED ON EM405-8
ARM PROCESSOR
STANDARD TOOLS
TELNET –RAW SOCKET I/F
TERMINAL EMULATOR
TEXT-BASED DEVELOPMENT
ETHERNET
COMMANDS
AND DATA

2
1.1 PURPOSE OF EQUIPMENT
The EM405-8 was designed for measurement, automation and control applications. The EM405
easily interfaces a VITA 12-1996 standard M-Module to a typical Ethernet network. The carrier
allows the numerous functions available in the M-Module mezzanine format to be remotely
located near the unit-under-test, easing many system integration issues. Over 100 M-Modules
are available from numerous manufacturers.
The scripting utilities were added to the EM405-8 to allow users to fully utilize the embedded
processor of the EM405-8 and to allow for easy customization of the integrated unit.
1.2 THE LUA SCRIPTING LANGUAGE
Lua (pronounced LOO-ah) is a powerful, fast, lightweight embeddable scripting language. It is
important to note that the name Lua is not an acronym. Lua was written in ANSI-C and is
designed to easily integrate with other software written in C and other conventional
programming languages. Thus,one of Lua’s primary strengths is its extensibility. Lua’s
extensibility is two-fold. Lua can be used to extend an application by embedding Lua scripting
into the application. Also, Lua itself is extendible allowing Lua scripts to utilize libraries and
components written in other programming languages.
Lua is an interpreted language in that Lua programs are stored as text that is interpreted at run-
time. Inreality, Lua code is compiled atruntime into an intermediate form; however, the fact
that compilation is performed at runtime allows scripts to be run directly from text and allows
Lua to retain the designation of an interpreted language.
Lua is free software distributed under the terms of the MIT license. The MIT license is short and
very liberal, allowing the user unrestricted use the software.
Further details, including documentation and references can be found at www.lua.org.
1.3 KEY FEATURES OF EM405-8 SCRIPTING
The EM405-8 implementation of scripting includes the basics of Lua including all standard
libraries, as well as EM405-8 specific extensions and EM405-8 specific script development
tools. Key features include:
Lua 5.1 programming language interpreter
Lua 5.1 standard libraries (math, table, string, i/o, operating system, etc.)
EM405-8 extensions to control M-modules and EM405-8 utilities
Call high-level M-module drivers and other libraries
TCP/IP based interactive interpreter for development
Develop scripts using any text editor. No compilation required
Store and retrieve data to/from mass storage device (mass storage is an EM405-8 option)
Receive commands and pass data over the Ethernet interface
Network based commands to use and manage scripts (store, retrieve, run, halt, etc.)
Create custom web pages to control the instrument

3
1.4 APPLICABLE REFERENCES
In addition to this reference manual there are several sourcesof further information on both the
EM405-8 and the Lua programming language. These documents should be referenced for details
of topics not covered or not elaborated on by this manual. The most applicable references are:
- EM405-8 User’s Manual, C&H Technologies, Inc., C&H part No: 11029384.
- Programming in Lua – 2nd Edition, Ierusalimschy, Roberto, Rio de Janeiro, 2006
- Lua Reference Manual, Ierusalimschy, Roberto, De Figueiredo Luiz Henrique, Celes
Waldemar, Lua.org, 2006
- Lua.org, http://www.lua.org
- Alien, http://alien.luaforge.net/, http://luaforge.net/projects/alien/

4
2.0 USING AND MANAGING SCRIPTS
The scripting utilities are accessible via the standard EM405-8 command interfaces (VXI-11 and
raw socket). In addition, a special scripting socket interface is available to help develop and
debug scripts. A set of use and management commands are defined and any of these commands
can be sent via any ofthe available interfaces with a few exceptions.
2.1 COMMANDS
The scripting commands allow the user to develop, use and manage scripts. These commands
are the primary interface to the scripting utilities and are used during both development and
deployment of scripts. They are available, with a few exceptions, via any of the EM405-8’s
command interfaces including the special scripting socket interface. A complete list of use and
management commands is shown in Table I. Details of each command can be found in the
subsequent sections.
Table IUse and Management Commands
?|help list command help
data <data> send up to 16Kbytes to a script (VXI-11 only)
halt <script> halt the script of the specified name
-l <script> halt last script started of specified name
-nx <script> halt script number x of specified name
-a [script] halt all running scripts
list list all scripts
-l [script] list details (script name optional)
-r [script] list if running (script name optional)
read <script> read the specified script
remove <script> remove the script
retrieve
<script><port>
retrieve the script using the specified port
-d delete the file upon retrieval
run <script> run specified script
-e <command> execute command
-i enter interactive mode (scripting socket only)
socket? returns 1 if scripting socket running,0 if not
-p returns the port of the scripting socket
upload <script><port>
upload the script using the specified port
-x execute script after upload
-o overwrite script if file exists
ver returns versions of Lua and EM405-8 extensions
Note: An asterisk (*) is required before the command if sent via the VXI-11 or raw socket interface. The
EM405-8 contains a binary command protocol. An asterisk (*) character denotes that the remaining
command consists of ASCII characters. If the first byte is anything other that an asterisk (*) the EM405-8
perceives it as a binary command. The binary commands are not available via the scripting socket therefore
the asterisk (*) is not required nor recognized.
2.1.1 ? | Help
The help command or simply ‘?’ will return a list of commands along with argument options
and descriptions similar to Table I. The result will be output via the same interface from which
the command was received.
help or ?

5
2.1.2 Data
The data command allows the user to transfer up to 16 kilobytes of data to a running script.
This command is only available over the VXI-11 or raw socket interface. It has no effect if sent
over the scripting socket interface.
data <up to 16K of data>
The command requires a running script that is expecting or polling for data. If such a script is
not running then this command will result in an I/O Error. For details on transferring data
to/from a running script refer to section 3.3.
2.1.3 Halt
The halt command is used to stop running scripts. Scripts always run in their own thread
allowing multiple scripts to be run at the same time. The halt command has the following
syntax:
halt <options>
options:
<script> halt the first script started of the specified name
-l <script> halt the last script started of the specified name
-nX <script> halt script number x of specified name
-a [script] halt all scripts or all scripts of the specified name
In addition to running more that one script at a time, the same script can be concurrently run
multiple times, each in its own thread. The system maintains a sequence list indicating the order
in which each instance of a running script was started. Using the halt command, the usercan
specify the specific instance to halt,based on this start sequence. The system does not maintain
any further details other that the start order. It is up to the user to understand the details of a
specific instance, such as the responsibilities of that instance, and the order in which that instance
was started.
With the –a option the user can halt all running scripts of a specified name, by passing the script
name argument or all running scripts within the system by not specifying a script name.
2.1.4 List
The list command will return a list of all scripts stored on the system. The result will be output
via the same interface from which the command was sent.
list [options]
options:
-l show details of each file
-r show only scripts that are currently running
[script] if the optional [script] is specified only that script
will be shown

6
Arguments of the list command are optional. If no arguments are provided, all scripts will be
listed without details. Use the –l option to show the details of the scripts. Details include the
file size, date,the system/user designation and a run/idle status indication.The –r option shows
only those scripts that are currently running. Both options may be included in a single list
command. If the optional [script] argument is passed only scripts of the specified name will
be listed.
In the output of the list command, each script listing is terminated with a “new line” character
(‘\n’ or 0xA). The entire list is terminated with a carriage return (‘\r’ or 0xD).
2.1.5 Read
The read command will return the source code of the specified script via the interface from
which the command was sent. For example, if in the scripting socket interface you type read
myscript.lua the source code of myscript.lua will appear in the terminal window. If you
send the same command via the VXI-11 interface, the next VXI-11 read will return the source
code of the script. Note that the VXI-11 interface has a 16 kilobyte limit therefore any script
greater than 16 kilobytes will not be returned properly. An alternative to the read command is
the retrieve command detailed in section 2.1.7.
read <script>
2.1.6 Remove
The remove command will delete the specified script from both volatile and non-volatile
memory. A removedscript is not recoverable therefore care must be taken to ensure a script is
saved on a host computer before sending the remove command.
remove <script>
2.1.7 Retrieve
The retrieve command is used to download a script from the EM405-8 to the host computer.
A download port must be specified.
retrieve [options] <script> <port>
options:
-d delete the file upon retrieval
Upon receiving the retrieve command, the EM405-8 will search for the specified script and
return a 4-byte acknowledge (“ack\n” if found or “nck\n” if not found)via the same interface
from which the command was received. If the script was found, the EM405-8 will launch a
small TCP/IP server at the specified port. The host application must then connect to this server
to download the script. The TCP/IP server will automatically exit once the script has been
downloaded. Therefore, a new retrieve command must be used for each script to be
downloaded.

7
The script is sent over the TCP/IP server by the EM405-8 in a raw format preceded by 4 bytes
specifying the size of the file as shown in Figure 2. Figure 2also shows the simple procedure to
download the file.
Figure 2Retrieve Script Download Format
If the –d option is found, the script will be deleted at the completion of the download. A deleted
script is not recoverable therefore care must be taken before sending the -d option
2.1.8 Run
The run command starts the specified script, launches interactive mode or executes the specified
Lua command. One of the three arguments is required for the run command. Only one
argument can be passed in a single run command.
run <argument>
arguments:
<script> run the specified script
-i enter interactive mode (scripting socket only)
-e <command> executes the specified command
Running a specific script will launch the script in its own process so that it may run
independently and so that the user may launch more that one script. In reality, the run command
is optional. Scripts can be run by simply sending the name of the script to the EM405-8 as a
command itself. Further, if the file extension of the script is .lua than the extension may be
omitted. For example,if the script file is myscript.lua then the following three commands
perform the same action of launching the script
run myscript.lua
myscript.lua
myscript
Interactive mode is a special mode of the scripting socket in which the user can type Lua source
code directly to the interpreter to be run immediately. Details on interactive mode can be found
in section 2.3.3. The –i option is only valid from the scripting socket interface and does not
return until the socket is closed.
FILE SIZE (4 BYTES)
FILE DATA
0
4
4 + FILE SIZE
Download Procedure
1. Send the download command
2. Read the 4-byteAcknowledge
3. If “nck\n” thenexitelse if “ack\n” continue
4. Connect to the download port via raw socket
5. Read 4-bytes to determine size. Byte 0 is
the least significant byte.
6. Read size bytes to buffer
7. Write buffer to file on host computer

8
The –e argument allows the user to input Lua source to be run immediately. It is different than
interactive mode in that it does not give the user a different command prompt in the scripting
socket and more importantly once the command(s) is complete the Lua state is lost. In other
words, variables, loaded libraries and other constructs that are normally valid from one command
to the next are only available during that one command.
2.1.9 Socket?
The socket? command will return an ASCII ‘1’ if the scripting socket interface is available and
an ASCII ‘0’ if not. Further passing the –p argument will return the TCP/IP port of the scripting
socket interface. Note that the –p argument will return a port number regardless of whether or
not the scripting socket is available.
socket? [options]
options:
-p returns the port number of the raw socket interface
It is useful to send the socket? command via the VXI-11 or raw socket interface to determine if
the scripting socket interface is available and to determine at which TCP/IP port to connect to it.
2.1.10 Upload
The upload command is used to upload a script from a host computer to the EM405-8. An
upload port must be specified.
upload [options] <script> <port>
options:
-x execute the script after upload
-o overwrite the script if the file exists
Upon receiving the upload command, the EM405-8 will first determine if a script of the same
name already exists. If the EM405-8 finds a script of the same name and the –o is not provided a
4-byte negative acknowledge (“nck\n”) is returned. If it does not find a script of the same name
or if the –o option is provided, a 4-byte positive acknowledge (“ack\n”) is returned. The
acknowledge, whether it is positive or negative, is sent via the same interface from which the
command was received.
If a positive acknowledge is returned the,EM405-8 will launch a small TCP/IP server at the
specified port. The host application must then connect to this server to upload the script. The
TCP/IP server will automatically exit once the script has been uploaded. Therefore, a new
upload command must be used for each script to be uploaded.
The host computer must send the script in a raw format preceded with 4 bytes specifying the size
of the file as shown in Figure 3. Figure 3also shows the simple procedure to upload the file.

9
Figure 3Script Upload Format
If the –x option is found, the script will be automatically executed at the completion of the
download. A minor limitation of the –x option is that is does not allow you to pass arguments to
the script upon running it. If this functionality is needed, simply use the upload command
without the –x option followed by the run command.
2.1.11 Ver
The ver command will return version information of both the Lua interpreter and the EM405-8
extensions. The result will be output via the same interface from which the command was
received. There are no arguments to the ver command.
ver
2.2 STORING SCRIPTSANDSUPPORTINGFILES
All scripts and supporting files are stored in a single script pool. Since there are no
subdirectories in the script pool each file must have a unique name. Using the upload command
detailed in section 2.1.10, the user can upload and store any file into the script pool. All file
related commands such as list, read, remove, retrieve and run operate on the script pool.
Files in the script pool are labeled either sys or user. The system files are scripts that are
furnished by C&H and are stored on the EM405-8 as part of the EM405-8 firmware. These files
include EM405-8 utility scripts. User files are those uploaded by the user. Using the –l
argument of the list command, the sys versus user type of each file can be determined.
If the EM405-8 being used includes the internal mass storage option, the script pool is
automatically stored on the mass storage device in a non-volatile fashion. If the EM405-8 does
not contain the internal mass storage option, the script pool, with the exception of the system
scripts,is stored in volatile memory and must be uploaded after every power-up. In both cases,
the absolute path ofthe user script pool is: /usr/scripts/user.
There are several symbolic links in the EM405-8 web server host directory and link to the script
pool. These symbolic linksallow scripts to be used to create custom web pages and allow these
custom webpage to link to images and other files uploaded by the user. Details on the symbolic
links and the use of scripts to develop custom web pages can be found in section 4.0.
FILE SIZE (4 BYTES)
FILE DATA
0
4
4 + FILE SIZE
Upload Procedure
1. Send the upload command
2. Read the 4-byteAcknowledge
3. If “nck\n” thenexitelse if “ack\n” continue
4. Connect to the upload port via raw socket
5. Determine the file size
6. Pass the 4-byte size. Byte 0 is the least
significant byte.
7. Read the file and pass size bytes to the
EM405-8

10
2.3 SCRIPTING SOCKET INTERFACE
The EM405-8 supplies a TCP/IP socket interface that allows the user to interact with the
scripting utilities of the carrier. This is the primary interface used for developing scripts. This
interface accepts commands that allow the user to run scripts and view the script output. If a
script is started from the scripting socket interface, the scripting socket interface acts as the
stdout of the script. The commands accepted over the scripting socket interface are detailed in
section 2.1. In addition, the interface implements an interactive mode that allows the user to
input script commands line by line.
2.3.1 Configuring the Scripting Socket Interface
The scripting socket interface provided by the EM405-8 is disabled by default. It can be enabled
via the webpage of the EM405-8 under “Network Configuration.” Figure 4shows the Network
Configuration webpage.
Figure 4Network Configuration Webpage
The “Scripting Socket” enable/disable selection determines whether the socket interface is
available and the “Scripting Socket Port” specifies the TCP/IP port number at which the user will
connect to the interface. The default port number is 10011. If this port is used by a different
application in the system then this setting can be modified.

11
Port numbers are assigned by the Internet Assigned Numbers Authority (IANA) and many are
reserved for specific functions such as HTTP, SMTP, or telnet. Care must be taken not to choose
a port number that is reserved or that will be commonly used on the network.
2.3.2 Connecting to the Scripting Socket Interface
Application software can utilize the scripting socket interface using a standard TCP/IP raw
socket connection to the EM405-8’s IP address and the scripting socket port number. The
application can then transmit ASCII commands as detailed in section 2.1 and receive standard
output directly from the scripts.
Alternatively and more commonly, the user will utilize the scripting socket interface using a
telnet type connection in which the user will be able to manually type in commands and view the
script output. For example, using the Windows command prompt or a Linux terminal, the user
can connect tothe scripting socket interface by typing the following:
$ telnet 192.168.1.236 10011
In this example 192.168.1.236 is the IP address of the EM405-8 and 10011 is the configured port
number of the scripting socket interface. For proper operation and display, the telnet interface
must be configured for local echo and for CR+LF termination of commands.
The user can directly input commands as detailed in section 2.1 at the command prompt. In
addition,the scripting socket interface forwards the standard output console (stdout and
stderr) to the socket allowing all data destined for the stdout and stderr to be displayed on
the scripting socket interface. The data includes stdout data (print() function) from the
scripts themselves and warnings, errors and messages from the Lua interpreter.
In contrast, the standard EM405-8 VXI-11 and raw socket interfaces accept the same commands
that are available via the scripting socket interface; however these interfaces do not allow the
user to interactively control the scripting utilities with a telnet type connection nor do they allow
the user to receive console messages and errors.
2.3.3 Interactive Mode
From the scripting socket interface, the user can enter interactive mode with the command
run –i.
Once in interactive mode, the user can input Lua statements directly at the command prompt.
Interactive mode reads lines that the user inputs and executes them as they are read like the
following example (bold indicates the output):
>print(5+10)
15
Interactive mode recognizes incomplete Lua statements and in-turn prompts the user for more
data until the statement is complete or a syntax error is found. This allows the user to input
multi-line statements such as for loops and if-else conditional statements. For example an if-then

12
statement will look like the following (bold indicates the output):
>a=10
>if a == 5 then
>> print(“pass”)
>>else
>>print(“fail”)
>>end
fail
Interactive mode also supports a special prefix “=” that will cause the interpreter to print the
value of the expression to the right of the “=” sign. For example (bold indicates the output):
>a=10+5
>=a
15
There are a few limitations to interactive mode. Notably, each statement is executed as its own
Lua script; therefore local variables are not carried over to the next statement. The following
example illustrates this (bold indicates the output):
>local b=10
>print(b)
nil
>c=10
>print(c)
10
Another notable limitation is the inability to print tables.
There is no command to exit interactive mode. The user may exit interactive mode by simply
disconnecting from the scripting raw socket. When the user re-connects to the scripting raw
socket he/she will return to normal mode. Interactive mode is a great tool to learn and
experiment with the Lua language; however most script development will be done by writing
scripts into files that are uploaded and run.

13
3.0 DEVELOPING SCRIPTS
3.1 DEVELOPMENT SOFTWARE – EM405-8 IVI DRIVER SOFT FRONT PANEL
The EM405-8 IVI Driver Soft Front Panel contains a scripting panel that allows the user to
interface with the scripting utilities and provides tools to ease script development. A screenshot
of this scripting panel is shown in Figure 5. With this panel the user can interactively use and
manage the scripts. The panel provides the capability to, among others, upload, retrieve, run,
halt, and remove scripts.The panel also contains debug utilities that allow the user to run a
script in the scripting socket interface and view the script output in a standard command prompt.
Further, the panel allows the user to open a command prompt to the scripting socket interface
where he/she can directly input use and management commands.
Figure 5EM405-8 IVI Driver Scripting Panel Screenshot
3.2 EM405-8 EXTENSIONS LIBRARY
The EM405-8 Extension Library is a set of functions in the form of a Lua library that can be
included and called from a Lua script like any of the standard Lua libraries. The functions in the
EM405-8 Extension Library allow a Lua script to utilize and interact with the EM405-8 utilities
and M-module hardware. Functions include the ability to read and write M-module registers,
configure the EM405-8 triggers, send and receive data via the VXI-11 interface, control the
EM405-8 fans,and read the EM405-8 temperature sensors.

14
To use the Lua libraries simply require the library in the script as follows:
require “lua_em405”
Once the library is loaded any of the library functions are available for use in the script with the
following syntax:
lua_em405.function()
To further enhance readability, the library can be assigned to a local or global variable and the
library functions can be called with this variable as the prefix as in the following example. This
method will be used throughout this manual.
em405 = require “lua_em405”
em405.function()
Table II summarizes the functions that are in the EM405-8 Extensions Library. Details of each
function including a function description, valid parameter ranges and return types follow the
table.
Numerical constants in the Lua language are written much like they are in ANSI-C. Examples of
numerical constants are:
7 7.893 756.87e-6 0.784e1 0x76
The detailed descriptions below follow the same conventions.
Table II. Functions in the EM405-8 Extensions Library
Function Description
clock Returns the number of clocks used by the process
clockspersec Returns the number of clocks per second
emclose Free resources allocated during library load
emfans Control the speed of the fans
emread Read an EM405-8 carrier control register
emtemp Read an EM405-8 on-board temperature sensor
emwrite Write an EM405-8 carrier control register
input Input data to the script from the VXI-11 interface
mread Read an M-Module register
mreadblock Read a block of M-Module registers
mreadfifo Repeatedly read an M-Module register
mreadid Read the ID PROM of an M-Module
mwrite Write an M-Module register
mwriteblock Write a block of M-Module registers
mwritefifo Repeatedly write an M-Module register
output Output data to VXI-11 interface
usleep Sleep for specified microseconds
version Get the version of the EM405-8 Extension Library
Other manuals for EM405-8
1
Table of contents
Other C&H Technologies Network Router manuals
Popular Network Router manuals by other brands

TP-Link
TP-Link Archer AX6000 user guide

ATON
ATON Room Speaker Level Audio Router DLA4 Product guide

TP-Link
TP-Link TD-8841 user guide

TRENDnet
TRENDnet TE100-S16R Guide d'installation rapide

D-Link
D-Link DIR-518L Quick installation guide

Ruckus Wireless
Ruckus Wireless MediaFlex NG Quick installation guide