C&H Technologies EM405-8 Manual

Other manuals for EM405-8: User Manual
Manual is about: ETHERNET M - MODULE CARRIER / LXI BRIDGE

Summary of EM405-8

  • Page 1

    Manual part no: 11030574a m o d e l e m 4 0 5 - 8 s c r i p t i n g m a n u a l e t h e r n e t m - m o d u l e c a r r i e r / b r i d g e.

  • Page 2

    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) an...

  • Page 3

    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 availa...

  • Page 4

    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 wi...

  • Page 5

    V table of contents 1.0 general description ............................................................................................ 1 1.1 purpose of equipment............................................................................................. 2 1.2 the lua scripting language .............

  • Page 6

    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 ...........

  • Page 7

    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 progra...

  • Page 8

    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 lo...

  • Page 9

    3 1.4 applicable references in addition to this reference manual there are several sources of 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 refe...

  • Page 10

    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 t...

  • Page 11

    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 the command requires a running script that is expecting...

  • Page 12

    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 th...

  • Page 13

    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 2 also shows the simple procedure to download the file. Figure 2 retrieve script download format if the –d option is found, the script will be d...

  • Page 14

    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, variable...

  • Page 15

    9 figure 3 script 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 u...

  • Page 16

    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 sc...

  • Page 17

    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 s...

  • Page 18

    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 e...

  • Page 19

    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 pan...

  • Page 20

    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...

  • Page 21

    15 clock () description: returns an approximation of processor time used by the program. This function call the ansi-c function clock() in the c standard library. The time is returned as the number of processor clocks. To convert to seconds use the value returned by clockspersec(). The value is not ...

  • Page 22

    16 status, value = emread (offset) description: reads an em405-8 control register. These registers are shared between all m- modules and control the carrier utilities such as triggers and fans. Refer to the em405-8 user’s manual for register details. Parameters: offset integer specifying the registe...

  • Page 23

    17 status, value = mread (module, width, offset) description: reads an m-module register from a specified m-module position. Parameters: module integer indicating the m-module position to read. (0 – 7) width integer specifying the access width in bytes 2 = 16-bit 4 = reserved for future use offset i...

  • Page 24

    18 status, buffer = mreadfifo (module, width, offset, length) description: read a single m-module register repeatedly from a specified m-module position. The function will read length words from the specified offset without incrementing the address between each read parameters: module integer indica...

  • Page 25

    19 status = mwriteblock (module, width, offset, length, buffer) description: write a block of m-module registers to a specified m-module position. The function will write length words incrementing the address between each write parameters: module integer indicating the m-module position to write. (0...

  • Page 26

    20 version = version () description: get the version information of the em405-8 extension library (this library). Parameters: none return: version string describing the version of the library usleep () description: suspend the thread for the specified number of microseconds. The library function cal...

  • Page 27

    21 note: if a script is not running to accept that data, the visa function viwrite will return an i/o error. To retrieve data from the input fifo, the script must call the em405-8 extensions library function input . The em405-8 extensions library functions are detailed in section 3.1. The input func...

  • Page 28

    22 3.4 calling m-module drivers the scripting utilities include a lua library known as alien that allows a lua script to call dynamic libraries (,so, dll, etc.). Using alien, we can make calls to any of c&h technologies’ standard m-module drivers. Alien uses the foreign function interface (ffi) libr...

  • Page 29

    23 note that in the above example code, the path /usr/scripts/user/ is the absolute path of the script pool where libm228.So will be uploaded. The absolute path must be specified for alien to find the shared library. To use a function in the driver you first must tell alien the function prototype of...

  • Page 30

    24 you may find it strange that there are two variables specified on the left side of the equal sign. The first variable is the return value of the function. The second and subsequent variables are the return values of the parameters that are passed by reference. Alien supports by-reference types by...

  • Page 31

    25 figure 7 m-module driver example code 3.4.2 dealing with data the data types shown in table iii are straightforward and cover most function calls to m- module drivers. But there are m-module driver function calls that, for example, require special data types (c structures) or require the calling ...

  • Page 32

    26 figure 8 m-module driver example using buffers 3.4.2.2 arrays alien arrays build upon buffers by adding an extra layer of safety and elements that describe the array. The function alien.Array(type, length) allocates an array where type is the alien type of the elements and length is the number of...

  • Page 33

    27 figure 9 m-module driver example using arrays 3.4.2.3 pointer unpacking pointer can be de-referenced and converted to a lua type using one of the functions alien.Tostring , alien.Toint , alien.Toshort , alien.Tolong , alien.Tofloat , and alien.Todouble. These functions should be used with care as...

  • Page 34

    28 function alien.Callback() that lets the user create a callback by passing it the function and prototype of the callback function. The function alien.Callback() will return an object that can be passed to any argument of callback type. 3.4.3 building m-module drivers into a linux shared library in...

  • Page 35

    29 3.7 using the mass storage device in addition to providing non-volatile storage of scripts, the mass storage device (ordering option -0003 only) provides the user with a large amount of non-volatile memory for storage of user data. The em405-8 system only uses the mass storage device for the scri...

  • Page 36

    30 4.0 using lua to write custom web pages using lua, the user may create custom web pages to be served by the em405-8’s embedded web server. In addition to creating the pages, themselves, the user can add links to the standard navigation menu that is found on every one of the default web pages of t...

  • Page 37

    31 for example, if your script is named myscript.Lua then the url would be: /cgi-bin/script.Cgi?Script=myscript.Lua or /cgi-bin/private/script.Cgi?Script=myscript.Lua of course, typing these url’s directly into a browser would require the above to be preceded with the ip address; however, these are ...

  • Page 38

    32 4.3 url of pictures and other supporting files sometimes a script based webpage will need to link to other supporting files such as graphics and images. A directory name scripts on the root level of the url is provided to give the user a location for supporting files. In reality, /scripts is simp...

  • Page 39

    33 figure 13 example retrieving arguments from the url 4.5 developing the page content the user may customize the webpage to look however he/she likes by creating the entire html content. Alternatively, the user can maintain the em405-8 default look and feel of the webpage by using the l_em405web.Lu...

  • Page 40

    34 top(refresh, refresh_time, refresh_url) description: this function creates the html header information and displays the top banner including the c&h logo and banner graphic. The parameter allow the user to control the refresh meta tag. Parameters: refresh 1 or 0 indicating whether or not to inclu...

  • Page 41

    35 contents_post() description: this function closes the subsequently closes the nested table. The user should always call contents_post() if contents_pre() was used before the page content. The first html tag output by this function is note: the user may call top() and bottom() without calling cont...

  • Page 43

    N o t e s:.

  • Page 44

    ..

  • Page 45

    Reader's comment form your comments assist us in improving the usefulness of c&h's publications; they are an important part of the inputs used for revision. C&h technologies, inc. May use and distribute any of the information that you supply in any way that it believes to be appropriate without incu...

  • Page 46

    Instructions in its continuing effort to improve documentation, c&h technologies, inc. Provides this form for use in submitting any comments or suggestions that the user may have. This form may be detached, folded along the lines indicated, taped along the loose edge (do not staple), and mailed. Ple...