# Reader Reference

# Triggers

This chapter provides the following sections:

- Introduction to Event Triggers
- OLE for Process Control (OPC) Trigger Driver
- TCP Trigger Driver
- PLC Trigger Driver
- Directional Trigger Driver

## Introduction to Event Triggers

Applications can define event cycle specifications (`ECSpec`) and programming cycle specifications (`PCSpec`) where the beginning or end of each cycle is triggered by external events. BEA provides an extensible mechanism for connecting sources of external events to the ALE engine.

## OLE for Process Control (OPC) Trigger Driver

OPC is a series of standards specifications that define a standard set of objects, interfaces, and methods for use in process control and manufacturing automation applications to facilitate interoperability. (For more information on OPC, see http://www.opcfoundation.org.)

WebLogic RFID Edge Server includes a driver for OPC triggers. An event or programming cycle in the Edge Server can be triggered by polling for a change in an OPC item. The Edge Server communicates with the OPC service using the OPC XML-DA protocol, which is a SOAP interface to an OPC Data Access provider. The OPC XML-DA implementation is provided by a third party.

The general form of the trigger URI is:

    opcpoll:itemName=item;http://hostname/location

where:

- `item` is the name of the OPC item that the driver polls for changes.
- `http://hostname/location` is the URL that is used to create the connection to the OPC XML-DA server.

When an event cycle or programming cycle that uses an OPC trigger is first requested (that is, when the event cycle or programming cycle is invoked using the `poll` or `immediate` method or subscribed using `subscribe`), the Edge Server polls the OPC XML-DA server for the current value of the specified OPC item. Subsequently, each time the value of the OPC item changes, a trigger will be delivered to the event cycle or programming cycle.

## TCP Trigger Driver

WebLogic RFID Edge Server provides a TCP trigger driver that uses simple Telnet input to start or stop ALE event cycles in the Edge Server.

The following example shows how to invoke TCP triggers manually:

1. Open two Telnet sessions, one for the start trigger and one for the stop trigger.

For example,

`:prompt> telnet localhost 7070
:prompt> telnet localhost 7071`

2. In the Administration Console, edit an ECSpec to set the start and stop trigger URIs, then click Deploy.

1. Start Trigger URI: `tcplisten:``ip_address``:7070`
2. Stop Trigger URI: `tcplisten:``ip_address``:7071`

Note: | If you specify two colons, for example, `tcplisten::7070`, it uses all IP addresses.

3. Activate the ECSpec by clicking Test or Activate Once.
4. Invoke the start trigger by pressing a carriage return in the Telnet session `localhost:7070`.

When the start trigger is fired, the event cycle starts receiving tag data. The event cycle stops when either the stop trigger fires or other stop conditions are met.

5. Invoke the stop trigger by pressing a carriage return in the Telnet session `localhost:7071`.

The event cycle terminates and an ECSpec report is generated.

In production, an application invokes a TCP trigger by:

1. Opening a socket connection to the TCP port (in the previous example, `localhost = 7070`)
2. Writing a line feed (a character code that advances the screen cursor or printer to the next line, `<LF>` or `0x0A` hex)

The TCP trigger driver listens for the line feed. When supplied, it provides the trigger URI to start or stop the event cycle.

## PLC Trigger Driver

The RFID Edge Server PLC trigger driver converts PLC messages into trigger URIs for starting or stopping ALE event cycles. Figure 5-1 illustrates a typical PLC trigger setup.

Figure 5-1 PLC Trigger Input

For more information on how the RFID Edge Server communicates with and controls RFID devices by interacting with PLCs, see Controlling RFID Devices via PLC.

### Configuring PLC Triggers

You configure PLC triggers in the `edge.props` file using the following steps:

Note: | All property names shown in this section should be prefixed with `com.connecterra.ale.plc`, which is abbreviated `[CCAP]` in the properties below.

1. Create a backup copy of `edge.props` and open the original for editing.
2. Define a transport to be used for PLC communications; for example, a `Modbus` transport named modbus0.

    # ModBus transport configuration
    [CCAP].plcTransport.modbus0.metaName = ModBus
    [CCAP].plcTransport.modbus0.hostname = plcHostName
    [CCAP].plcTransport.modbus0.socketTimeout = 10000
    [CCAP].plcTransport.modbus0.pollInterval = 10000

3. Define a message convention; for example, the `Simple` message convention named simplemodbus0.

    [CCAP].plcMessageConvention.simplemodbus0.metaName = Simple
    [CCAP].plcMessageConvention.simplemodbus0.plcTransport = modbus0

4. Define the inbound message for the message convention chosen in step 3.

    #Define inboundMessage `photoeye1' which is connected to a PLC pin with
    #address 2052. (`d' is a convention referring to discrete input in the
    #ModBus protocol.)
    [CCAP].inboundMessage.photoeye1.plcMessageConvention = simplemodbus0
    [CCAP].inboundMessage.photoeye1.receiveItem = d2052
    [CCAP].inboundMessage.photoeye1.matchValues = true

5. Define the PLC trigger.

    #Define a trigger named `plcmessage' using the PLCTriggerDriver
    com.connecterra.ale.triggerDriver.plcmessage.class=com.connecterra.ale.triggertypes.PLCTriggerDriver

6. Save the changes to `edge.props` and restart the Edge Server.
7. In the Administration Console, edit an ECSpec to set a start or stop condition trigger URI; for example, Start Trigger URI: plcmessage:photoeye1

## Directional Trigger Driver

WebLogic RFID Edge Server includes a directional trigger driver that gets input from two source points, A and B, and determines if an object is moving from A to B or from B to A.

- How It Works
- Configuring the Directional Trigger Driver
- Examples

### How It Works

In the following example, two photoelectric sensors are positioned at a dock door, one at reading point A and one at reading point B. Tagged items move between points A and B in one direction at a time.

Figure 5-2 shows the input triggers, A and B, and the directional output triggers.

Figure 5-2 Input and Output Triggers

Moving items which first block photoelectric sensor A (generating output trigger abIn), then block sensor B (generating output trigger abOut), signal that AB traversal is finished. Moving items which block photoelectric sensor B first, then sensor A, (generating output triggers baIn then baOut), signal that BA traversal is finished.

Note: | There is a maximum allowed travel time (T) between point A and point B. The trigger driver resets to the idle state after travel time T elapses, even if an object moves past photoelectric sensor A (moves in) but fails to move past photoelectric sensor B at the exit point (does not move out).

The directional trigger driver listens for input triggers. Input triggers might be PLC triggers, whose sources are PLC inbound messages which receive inputs from photoelectric sensors or other IO inputs, such as GPIO. Other types of triggers can also provide inputs, such as TCP triggers.

Figure 5-3 Input Sources

The directional trigger driver monitors the status (state change) of the input triggers, for example, when the photoelectric sensors are blocked. When the trigger driver receives the input trigger status, it generates trigger messages for trigger listeners in the event cycle, one listener for event start conditions and one for event stop conditions. When the start trigger is fired, the event cycle starts getting tag data; the event cycle stops when either the stop trigger fires or the cycle duration time expires.

### Configuring the Directional Trigger Driver

You configure the directional trigger driver in the `edge.props` file by specifying the trigger driver class name, the timeout (in milliseconds), and two input triggers.

In the `edge.props` file example in Listing 5-1, the directional trigger name is door1; you can substitute the trigger name with any string.

Listing 5-1 Directional Trigger Driver Configuration

    #Define the directional trigger
    #Trigger driver class name
    com.connecterra.ale.triggerDriver.door1.class=com.connecterra.ale.triggertypes.DirectionTriggerDriver

    #Directional trigger state timeout (if start trigger is fired, but stop
    #trigger fails to fire, the directional trigger will reset to idle state
    #after timeout period in ms)
    com.connecterra.ale.triggerDriver.door1.timeout=10000

    #input trigger URI at point `a'
    com.connecterra.ale.triggerDriver.door1.aTrigger=plcmessage:photoeye1

    #input trigger URI at point `b'
    com.connecterra.ale.triggerDriver.door1.bTrigger=plcmessage:photoeye2

The directional trigger driver generates four output trigger URIs; for example, door1`:abIn`, door1`:abOut`, door1`:baIn`, door1`:baOut`. You use the trigger URI to specify the starting condition (for example, `door1``:abIn`) or stopping condition (for example, `door1``:abOut`) in the event cycle definition.

Note: | `abIn`, `abOut`, `baIn`, and `baOut` are defined names and cannot be changed.

### Examples

The following examples illustrate two directional trigger configurations.

#### Using Reader GPIO Ports

This example describes using the directional trigger driver with a Symbol XR400 reader (it does not work with the AR400 reader) and Symbol XR400 Reader Light Indication Box. Refer to the reader manufacturer's manual for the wiring details (Symbol Reader Manual, XR Series RFID Reader Integrator Guide, Part Number 72E-71773-03 Rev. A, February 2006).

Photoelectric sensors are connected to the Light Indication Box, then to the reader GPIO input ports (at pins #4 and #5). The GPIO port status is forwarded to the directional trigger driver using the `Reader` type PLC transport and the `simple` message convention.

##### Directional Trigger and Reader Configuration: Main Steps

To configure the directional trigger and the reader, perform the following steps:

1. In the `edge.props` file, define the following properties (see Listing 5-2):

- GPIO transport name and type
- Message convention
- Input triggers for points `a` and `b`
- Directional trigger driver

2. In the ECSpec (for the example directional trigger named door1), define the following start and stop conditions:

- Start Trigger URI: `door1``:abIn` for `a' to `b' movement (or `door1``.baIn` for `b' to `a' movement)
- Stop Trigger URI: `door1``:abOut` for `a' to `b' movement (or `door1``.baOut` for `b' to `a' movement)
- Stop duration (for example, 10000 ms)

3. Configure the Symbol XR400 reader for GPIO mode, as described in Enabling GPIO Mode (Symbol XR400 Reader Only).
4. In the Administration Console, configure these Symbol XR400 reader parameters:

- Enable Reader GPIO Mode (`enableGPIO`): `true`.
- GPIO Transport Name: `mygpio` (as defined in `edge.props`, bolded in Listing 5-2)
Listing 5-2 Example GPIO Directional Trigger Configuration

    #In edge.props file
    #Define the PLC Transport type `Reader' named `mygpio'
    com.connecterra.ale.plc.plcTransport.mygpio.metaName = Reader

    #Define the message convention `Simple' named `simplegpio'
    com.connecterra.ale.plc.plcMessageConvention.simplegpio.metaName = Simple
    com.connecterra.ale.plc.plcMessageConvention.simplegpio.plcTransport = mygpio

    #Define inboundMessage named `photoeye1'
    com.connecterra.ale.plc.inboundMessage.photoeye1.plcMessageConvention = simplegpio

    #Photoeye1 connected to the reader's GPIO input port pin #5
    com.connecterra.ale.plc.inboundMessage.photoeye1.receiveItem = input5
    com.connecterra.ale.plc.inboundMessage.photoeye1.matchValues = true

    #Define inboundMessage named `photoeye2'
    com.connecterra.ale.plc.inboundMessage.photoeye2.plcMessageConvention = simplegpio

    #Photoeye2 connected to reader's GPIO input port pin #4
    com.connecterra.ale.plc.inboundMessage.photoeye2.receiveItem = input4
    com.connecterra.ale.plc.inboundMessage.photoeye2.matchValues = true

    #Define the input trigger named `plcmessage' using the PLCTriggerDriver
    com.connecterra.ale.triggerDriver.plcmessage.class=com.connecterra.ale.triggertypes.PLCTriggerDriver

    #Define the directional trigger
    #Driver class name
    com.connecterra.ale.triggerDriver.door1.class=com.connecterra.ale.triggertypes.DirectionTriggerDriver

    #Directional trigger state timeout (if start trigger is fired, but stop
    #trigger fails to fire, the trigger will reset to idle state after timeout
    #period in ms)
    com.connecterra.ale.triggerDriver.door1.timeout=10000

    #input trigger URI at point `a'
    com.connecterra.ale.triggerDriver.door1.aTrigger=plcmessage:photoeye1

    #input trigger URI at point `b'
    com.connecterra.ale.triggerDriver.door1.bTrigger=plcmessage:photoeye2

#### Using a ModBus PLC

The following example defines a directional trigger named door2 and uses two PLC IO inputs as input triggers. The PLC inputs are forwarded to the directional trigger driver using the `ModBus` type PLC transport and the `simple` message convention. The RFID Edge Server communicates with the PLC using the Modbus protocol. See Controlling RFID Devices via PLC.

The four output trigger URIs are `door2``:abIn`, `door2``:abOut`, `door2``:baIn`, `door2``:baOut`.

Listing 5-3 Example Directional Trigger Configuration Using PLC Modbus Protocol

    #In edge.props file
    #Define the ModBus transport named `modbus0'
    com.connecterra.ale.plc.plcTransport.modbus0.metaName = ModBus
    com.connecterra.ale.plc.plcTransport.modbus0.hostname = localhost
    com.connecterra.ale.plc.plcTransport.modbus0.socketTimeout = 10000
    com.connecterra.ale.plc.plcTransport.modbus0.pollInterval= 1000

    #Define the message convention `Simple'
    com.connecterra.ale.plc.plcMessageConvention.simplemodbus0.metaName = Simple
    com.connecterra.ale.plc.plcMessageConvention.simplemodbus0.plcTransport = modbus0

    #Define inboundMessages `msg1' and `msg2', which are connected to PLC input
    # IO 5 and 6 (`d' is a convention referring to discrete input in ModBus
    #protocol)
    com.connecterra.ale.plc.inboundMessage.msg1.plcMessageConvention = simplemodbus0
    com.connecterra.ale.plc.inboundMessage.msg1.receiveItem = d5
    com.connecterra.ale.plc.inboundMessage.msg1.matchValues = true
    com.connecterra.ale.plc.inboundMessage.msg2.plcMessageConvention = simplemodbus0
    com.connecterra.ale.plc.inboundMessage.msg2.receiveItem = d6
    com.connecterra.ale.plc.inboundMessage.msg2.matchValues = true

    #Define the input trigger named `plcmessage' using the PLCTriggerDriver
    com.connecterra.ale.triggerDriver.plcmessage.class=com.connecterra.ale.triggertypes.PLCTriggerDriver

    #Define the directional trigger `door2' - timeout = 10000ms
    com.connecterra.ale.triggerDriver.door2.class=com.connecterra.ale.triggertypes.DirectionTriggerDriver
    com.connecterra.ale.triggerDriver.door2.timeout=10000

    #input trigger at point `a'
    com.connecterra.ale.triggerDriver.door2.aTrigger=plcmessage:msg1

    #input trigger at point `b'
    com.connecterra.ale.triggerDriver.door2.bTrigger=plcmessage:msg2