listenAsynch

listenAsynch(receiver: Object;
             msg:      String);

The listenAsynch method of the JadeSerialPort class listens for a remote application to connect to JADE.

When a connection is established, the object specified in the receiver parameter is sent the name of the callback method specified in the msg parameter.

You can call the listenAsynch method only when the state is Disconnected (0). When this method is called, the state is changed to Connecting (1), or listening.

On asynchronous calls, the state may not change immediately, and it can remain Disconnected (0) for a short period until JADE has rescheduled the request.

The following example shows the use of the listenAsynch method.

listenAsynch_click(btn: Button input) updating;
vars
    conlog : ConnectionLog;
begin
    // Sets the conlog variable to reference a ConnectionLog object.
    // If none exists, the object is created and its properties
    // are initialized.
    beginTransaction;
        conlog := ConnectionLog.firstInstance;
        if conlog = null then
            create conlog;
            conlog.numberOfListenCalls  := 0;
            conlog.numberOfOpenCalls    := 0;
            conlog.numberOfCloseCalls   := 0;
            conlog.numberOfBinaryReads  := 0;
            conlog.numberOfBinaryWrites := 0;
        endif;
    commitTransaction;
    // Sets the connection to listen on the current port and returns
    // immediately.  If a connection is made, the ConnectionLog object
    // referenced by conlog is called, to run the updateListenCalls method.
    self.connection.listenAsynch(conlog, "updateListenCalls");
end;

See also the Connection class timeout property.

When a connection is established, the user-written callback method specified in the msg parameter is called. The callback method must match the signature required by the calling listenAsynch method, as follows.

listenCallback(connection: Connection);

The following method is an example of a ConnectionLog class callback method for the listenAsynch method, which updates the number of method invocations recorded for this method.

updateListenCalls(connection: Connection) updating;
begin
    beginTransaction;
    self.numberOfListenCalls := self.numberOfListenCalls + 1;
    commitTransaction;
end;