Javascript library: conversion.js – Rockwell Automation 1768-EWEB EtherNet/IP Web Server Module User Manual User Manual

Page 99

Advertising
background image

Publication ENET-UM527E-EN-P - October 2006

Create Custom Web Pages 99

Javascript Library: Conversion.js

The conversion.js library contains six functions. To include this library
in your custom web page, include this line.

<script type="text/javascript"

src="/scripts/conversion.js">

</script>

TThe conversion.js library contains these functions.

Function

Description

parseStruct(structStr,
type, stringlength)

The parseStruct function is the main function, where:

structStr

Contains the string returned from the ASP call, or a substring thereof,
beginning at the hex number which starts the value to be retrieved from
the string.

type

Indicates the data type to be parsed from the string. It should be one of
“SINT”, “USINT”, “INT”, “UINT”, “WORD”, “DINT”, “UDINT”, “DWORD”,
or “STRING”.

stringlength

(Optional) only used when the type to be parsed is a “STRING”. In this
case, it identifies how many digits of the input string to parse into ASCII
characters.

For example, to retrieve the device name from a device in slot 1 of the local chassis:

var idobj = "<% CIPMessage("1,1", 1, 1, 1, 0,

0,"0","STRING"); %>";

var namelen = parseStruct(idobj.substring(42,

idobj.length), "USINT");

var name = parseStruct(idobj.substring(45,

idobj.length), "STRING", namelen);

The Device Name attribute of the identity object instance starts 14 bytes into the
GET_ATTRIBUTE_ALL response. Each byte of the response in the “STRING” return style
takes 3 bytes (2 hex digits and a space), so the Device Name attribute begins at the 42

nd

character of the string. The first byte of the string contains the number of characters in the
string. After parsing this string length, pass the length on to the next function, which
parses the actual string beginning at the 15

th

byte (45

th

character) of the string.

decToHex(decimalnumber)

The decToHex function takes an unsigned decimal number as a parameter and returns
a string representing decimalnumber in hexadecimal notation. The return value does not
have a preceding “0x” and the returned string is always 8 characters long, with leading
zeros when necessary.

hexToDec(hexnumber)

The hexToDec function takes a string containing a hexadecimal number with no
preceding “0x” as a parameter, and returns a decimal number with the value of
hexnumber.

decToOct(dintnumber)

The decToOct function takes an unsigned decimal number as a parameter and returns
an 11-character string representing dintnumber in octal notation. The return value does
not have a preceding “0” and the returned string is always 11 characters long, with
leading zeros when necessary.

Advertising
This manual is related to the following products: