Skip to content

acsys.sync

Beau Harrison edited this page Nov 9, 2022 · 2 revisions

This package provides support for the SYNC service. The SYNC service returns clock (TCLK, Test, CMTF, NML) and State event information in soft real-time.

Here's an example of using the library. This script registers to receive $02 and $8F event information and displays them as they arrive.

#!/usr/bin/env python3
import asyncio
import logging
import acsys.sync

# Set up the logger. We define a format for the messages and
# the minimal log level (INFO) that should get logged.

FORMAT = '%(asctime)-15s [%(levelname)s] %(message)s'
logging.basicConfig(format=FORMAT)

log = logging.getLogger('acsys')
log.setLevel(logging.INFO)

# This function calls 'acsys.sync.get_events' to register for
# the two clock events. The return value is a generator which
# is iterated across in the 'async-for-loop'.

async def my_client(con):
    async for ii in acsys.sync.get_events(con, ['e,2', 'e,8f']):
        log.info('%s', str(ii))

# Start the 'async' framework. Specify 'my_client' to be the
# function to be run in the async environment.

acsys.run_client(my_client)

API Reference

Classes

ClockEvent

Simple class to hold clock event information.

ClockEvent(stamp, ev, number)

Creates an instance. Scripts typically don't create these objects but, instead, receive them from @get_events()@.

.stamp - property

The timestamp of when the event occurred.

.event - property

The clock event number.

.number - property

The clock event instance number. As clock events are triggered, they are assigned an ascending number to "uniquely" identify them.

StateEvent

Simple class to hold state event information.

StateEvent(stamp, di, value)

Creates an instance. Scripts typically don't create these objects but, instead, receive them from @get_events()@.

.stamp - property

The timestamp of when the event occurred.

.di - property

The device index associated with the event.

.value - property

The value of the device which caused the state event to match (and, hence, fire.)

Functions

find_service(con, clock, node=None)

Searches for an available SYNC service. con is an acsys.Connection object. node, if None, will search for an available node running the SYNC service. clock specifies which clock to monitor and can be one of syncd_protocol.Clock_Tclk, syncd_protocol.Clock_Test, syncd_protocol.Clock_CMTF, or syncd_protocol.Clock_NML. It defaults to Clock_Tclk. If node is a string, it should be the name of an ACNET node. This function will verify that a SYNC service is running.

This function returns a string representing an ACNET node running the SYNC service. If no service was found, None is returned.

get_available(con, clock)

Returns a list of nodes running the SYNC service. con is an acsys.Connection object. clock specifies which clock to monitor (see find_service() for more information.)

get_events(con, ev_str, sync_node=None, clock)

Registers a list of events to monitor with a SYNC service and returns a stream of events that match. con is an acsys.Connection object. ev_str is a list of strings, each an event description in the format used by DRF2. sync_node, if specified, forces a particular ACNET node to be used. Otherwise one is chosen from the pool. clock specifies which clock to monitor (see find_service() for more information.)

This function returns an async generator which will yield instances of ClockEvent and StateEvent as they occur.

Clone this wiki locally