Class: IOLinkDevice

IOLinkDevice

Provides methods and properties for communicating with a single IO-Link sensor/actuator device


An IO-Link device requires a memory map in order to start. A memory map is XML that describes how the memory is organized. When applied, the attributes described in the map become accessible to JavaScript. JavaScript can then write to the outputs and connect to changed events on the inputs. Memory maps can be created and edited using the memory map editor tool. See Memory Map for more detail. Setting up an IO-Link device memory map is very similar to FLNet. See FLNet Memory Map for an example of how to set up an FLNet memory map.

As seen in the example below, the elements within the 'map' element must use the tag 'inputdata' (for input process data), 'outputdata' (for output process data) or 'parameterdata' (for parameter data), to specify the type of IO-Link data. There must be a single input process data element and a single output process data element. For each of these, the size attribute specifies the number of bytes of process data, and the name attribute must be absent. There may be multiple (or zero) parameter data elements, one for each parameter item that will be read or written. The index and subindex attributes specify the index and subindex numbers of the parameter data, and the name attribute must be present.

Fires:
Example
<types>
   <udt name="InputData" size="3">
      <u16 name="CountValue" index="0" />
      <u8 index="2">
         <bool name="BDC1" index="0" />
         <bool name="Stability" index="1" />
         <bool name="TeachIn" index="2" />
         <bool name="OK" index="3" />
         <bool name="TooLow" index="4" />
         <bool name="TooHigh" index="5" />
      </u8>
   </udt>
   <udt name="OutputData" size="1">
      <u8 index="0">
         <bool name="CounterReset" index="0" />
         <bool name="LEDOff" index="1" />
      </u8>
   </udt>
   <udt name="VendorName" size="7">
      <cstring name="Name" size="7" index="0" />
   </udt>
</types>
<map>
   <inputdata type="InputData" size="3" />
   <outputdata type="OutputData" size="1" />
   <parameterdata name="VendorName" type="VendorName" index="16" subindex="0" />
   <parameterdata name="Mode" type="u8" index="182" subindex="1" />
   <parameterdata name="Limit" type="u16" index="182" subindex="2" />
</map>

Members


bigEndian :bool

Should be set to true if 16-bit and 32-bit numbers defined in the memory map are in big endian format, false for little endian.

Type:
  • bool
Since:
  • 0.1 (WAT 2.4)
Default Value:
  • true

<readonly> connected :bool

Returns true when successfully connected, and in the Operate state

Type:
  • bool
Since:
  • 0.1 (WAT 2.4)

<readonly> inputData :iolink.UDT

Gets an object that can be used to access the input process data area of the I/O memory map.

Type:
  • iolink.UDT
Since:
  • 0.1 (WAT 2.4)

<readonly> map :object

Gets an object representation of the memory map. This must be used in WSAPI applications, in order to access the inputData, outputData and parameterData sections of the defined memory map.

Type:
  • object
Since:
  • 0.1 (WAT 2.4)
See:
Example
// standard JavaScript application
device.inputData.read();
device.outputData.write();
var countValue = device.inputData.data.CountValue.v;
device.parameterData.VendorName.readSuccess.connect(onVendorNameReadSuccess);
device.parameterData.VendorName.read();
var vendorName = device.parameterData.VendorName.data.HoldingRegister1.v;

// equivalent WSAPI application
device.map.inputData.obj.read();
device.map.outputData.obj.write();
var countValue = device.map.inputData.data.CountValue.v;
device.map.parameterData.VendorName.obj.readSuccess.connect(onVendorNameReadSuccess);
device.map.parameterData.VendorName.obj.read();
var vendorName = device.map.parameterData.VendorName.data.HoldingRegister1.v;

mmap :string

Gets/sets the XML description of the memory map. When load is called, this description is used to create an object tree that can be used to directly access the attributes from JavaScript.

This is typically set using AJAX to retrieve an XML memory map file.

Type:
  • string
Since:
  • 0.1 (WAT 2.4)
Example
var iolink = $wat.load('IO-Link')[0];
var device = iolink.master.createDevice(port);

function initIOLink(mmap)
{
   device.mmap = mmap;
   // set up the other IO-Link device settings here

   if (device.load() == false)
   {
      alert("Failed to load IO-Link memory map");
      return;
   }
}

// called after the page loads, for example in the body onload
function getXML()
{
   xmlhttp = new XMLHttpRequest();
   xmlhttp.open("GET", "iolinkDevice.xml", true);
   xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState == 4) {
         initIOLink(xmlhttp.responseText);
      }
   }
   xmlhttp.send("");
}

mmapFile :string

The name of a file in the file system of the uP device (e.g. /wat/mmap.xml) to read the memory map from if mmap is empty when load is called.

It is often more convenient to use AJAX and mmap to load a memory map.

Type:
  • string
Since:
  • 0.1 (WAT 2.4)
See:

<readonly> outputData :iolink.UDT

Gets an object that can be used to access the output process data area of the I/O memory map.

Type:
  • iolink.UDT
Since:
  • 0.1 (WAT 2.4)

<readonly> parameterData :iolink.UDT

Gets an object that can be used to access the parameter data area of the I/O memory map.

Type:
  • iolink.UDT
Since:
  • 0.1 (WAT 2.4)

port :int

The IO-Link port number

Type:
  • int
Since:
  • 0.1 (WAT 2.4)

Methods


close()

Close the connection to the IO-Link sensor/actuator.

Since:
  • 0.1 (WAT 2.4)
Example
device.close();

load()

Loads the memory map that has been set using mmap or mmapFile and creates an object tree to access the defined instances and attributes.

Since:
  • 0.1 (WAT 2.4)

open()

Attempts to open a connection to the IO-Link sensor/actuator.

Since:
  • 0.1 (WAT 2.4)
Returns:

Indicates if the open was successfully started.

Type
bool
Example
device.open();

reset()

Resets properties to the default value. Useful for resetting to a known state when re-configuring.

Since:
  • 0.1 (WAT 2.4)
Example
device.reset();

Events


bigEndianChanged

Emitted when the endianness of the memory map changes. See bigEndian for more details.

Parameters:
Name Type Description
bigEndian bool

Endianness of the memory map

Since:
  • 0.1 (WAT 2.4)

closed

Emitted when the connection to the IO-Link sensor/actuator has been closed, or is no longer in the Operate state.

Since:
  • 0.1 (WAT 2.4)

connectedChanged

Emitted when the connected state of the IO-Link sensor/actuator changes. See connected for more details.

Parameters:
Name Type Description
connected bool

Whether the sensor/actuator is currently connected, and in the Operate state.

Since:
  • 0.1 (WAT 2.4)

error

Emitted when the connection to the IO-Link sensor/actuator detects an error condition.

Parameters:
Name Type Description
err string

Description of the error

Since:
  • 0.1 (WAT 2.4)

mapChanged

Indicates that the map property has changed.

Since:
  • 0.1 (WAT 2.4)

mmapChanged

Emitted when the XML description of the memory map changes. See mmap for more details.

Parameters:
Name Type Description
mmap string

XML description of the memory map

Since:
  • 0.1 (WAT 2.4)

mmapFileChanged

Emitted when the memory map filename changes. See mmapFile for more details.

Parameters:
Name Type Description
mmapFile string

Name of the memory map file

Since:
  • 0.1 (WAT 2.4)

opened

Emitted when a connection to the IO-Link sensor/actuator has been established, and is in the Operate state.

Since:
  • 0.1 (WAT 2.4)