Class: TagClient

TagClient

Provides methods for interacting with tags on an EtherNet/IP server.


Fires:
Example
var eipc = $wat.load('eipc')[0];
var client = eipc.createTagClient('192.168.100.100', 1);
client.opened.connect(function() {
  console.log('Available tags', client.tagNames);
  // tags from tagNames can now be replicated using createTag
});
client.open();

Members


<readonly> connected :bool

True when a connection has been successfully established with the server at host/port, and the list of tags has been retreived from the server. The connectedChanged event is emitted when this value changes.

Type:
  • bool
Since:
  • 1.0 (WAT 2.2)
See:

host :string

The name or IP address to connected to during open. When this value is not an IP address, it will attempt to be resolved to an IP address using DNS.

Type:
  • string
Since:
  • 1.0 (WAT 2.2)
See:

port :number

The EtherNet/IP port (not TCP port) to connect to during open. Typically corresponds to the slot number when communicating with a PLC.

Type:
  • number
Since:
  • 1.0 (WAT 2.2)
See:

skipChangeCheck :bool

When true, the server values that indicate a change has been made on the server will NOT be checked. This means that the tag list, and any meta-data associated with the tags will only be read once when a device is connected to a server for the first time.

If these values are not checked, the plugin will not be made aware when a change is made at the server and will not attempt to re-read the tag list or tag meta-data. This can result in some or all tags failing to read/write when a change is made at the server, even if the change is seemingly unrelated to the tags used in the application.

However, if there is reasonable confidence that changes made at the server will have no effect and/or the WATbox can be refreshed or restarted if strange behavior results from a server change, then enabling this setting can reduce re-loads and the associated delays.

When set, this will apply to this, and any other TagClients connected to the same server (IP/port).

Type:
  • bool
Since:
  • 1.3 (WAT 2.3)
See:

<readonly> tagNames :bool

After a connection has been successfully established with the server, this property contains a list of tag names that were reported by the server. This property does not change while a connection is open with a server. However, if something changes on the server that requires the tag names to be refreshed, the connections will be closed briefly while the tags are re-read. To handle this case, it is good practice to re-read this property when opened is emitted (or when connected transitions to true) AND to check any replicated tags to ensure they still exist (if they do still exist, any connections to events of the tag must be re-connected).

Type:
  • bool
Since:
  • 1.0 (WAT 2.2)
See:

<readonly> tags :Object

Any tags that have been created using createTag are available by name via this property. Do not use for WS API clients. Instead cache a reference to the created tag and use it.

Type:
  • Object
Since:
  • 1.0 (WAT 2.2)
Example
var eipc = $wat.load('eipc')[0];
var client = eipc.createTagClient('192.168.100.100');
client.opened.connect(function() {
  client.createTag('TheTagName');
  // the tag is now available via the tags property
  client.tags.TheTagName.autoRead = 1000;
});
client.open();

Methods


close()

Stops EtherNet/IP communications.

Since:
  • 1.0 (WAT 2.2)

createTag(tagName)

Creates an object that can be used to manipulate a single tag on the server. The supplied tagName must be a name in tagNames, otherwise an empty tag will be created. This can be called while disconnected, in which case the tag will be queried and read (if it exists) once the connection is established. Use eipc.Tag#loaded to determine when a tag is ready to be used.

Parameters:
Name Type Description
tagName string

The name of the tag to replicate

Since:
  • 1.0 (WAT 2.2)
Returns:
Type
eipc.Tag

destroy(obj)

Deletes a previously created tag.

Parameters:
Name Type Description
obj eipc.Tag

The tag to delete.

Since:
  • 1.0 (WAT 2.2)

open()

Attempts to establish communications with the server/port specified in host/port.

Since:
  • 1.0 (WAT 2.2)
Returns:

True if the communication attempt successfully started (does not indicate if communications have been successfully established).

Type
bool

Events


closed

Indicates that EtherNet/IP communications have been stopped, because close was called, a communications error occurred, or the server terminated the connection.

connectedChanged may also be used.

Since:
  • 1.0 (WAT 2.2)

connectedChanged

Emitted when the connected property changes.

Parameters:
Name Type Description
connectionState bool
Since:
  • 1.0 (WAT 2.2)

error

Emitted whenever a communications error is encountered.

Parameters:
Name Type Description
errorDescription string
Since:
  • 1.0 (WAT 2.2)

hostChanged

Emitted when host changes.

Since:
  • 1.5 (WAT 2.4)

opened

Indicates that EtherNet/IP communications have been successfully established and that the list of available tags have been read (available in tagNames). If any tags had been created prior to this event (using createTag), then the tags will automatically be loaded (or re-loaded) at this time (see eipc.Tag#load). If the tag had been previously loaded (e.g. during a previous connection), then all cip properties in eipc.Tag#data will be destroyed and re-created. This means that any connections to events (e.g. cip.Number#event:valueChanged) will need to be re-established.

connectedChanged may also be used.

Since:
  • 1.0 (WAT 2.2)

portChanged

Emitted when port changes.

Since:
  • 1.5 (WAT 2.4)

skipChangeCheckChanged

Emitted when skipChangeCheck changes.

Since:
  • 1.5 (WAT 2.4)

tagNamesChanged

Emitted when tagNames changes.

Since:
  • 1.5 (WAT 2.4)