Custom streams and functions

Custom data item

A new data item is created by overriding the secsgem.secs.data_items.DataItemBase class:

class UNITS_New(DataItemBase):
    __type__ = SecsVarDynamic
    __allowedtypes__ = [SecsVarArray, SecsVarBoolean, SecsVarU1, SecsVarU2, SecsVarU4, SecsVarU8, SecsVarI1, SecsVarI2, SecsVarI4, SecsVarI8, \
        SecsVarF4, SecsVarF8, SecsVarString, SecsVarBinary]

In this case the UNITS field allows all types instead only a string.

Custom stream function

To integrate this new data item in a stream function then you need to inherit secsgem.secs.functions.SecsStreamFunction :

class SecsS01F12_New(secsgem.secs.functions.SecsStreamFunction):
    _stream = 1
    _function = 12

    _data_format = """
        <L
            <L
                <SVID>
                <SVNAME>
                <UNITS_New>
            >
        >
    """

    _to_host = True
    _to_equipment = False

    _has_reply = False
    _is_reply_required = False

    _is_multi_block = True

The data format is defined in a definition language that is based on SML. For more information on the definition language see Secs Function Definition Language

Data can also be defined using an old, python type based format. This was the format the functions were initially coded in. The format still works, but will be deprecated in the near future.

class SecsS01F12_New(secsgem.secs.functions.SecsStreamFunction):
    _stream = 1
    _function = 12

    _data_format = [
        [
            SVID,
            SVNAME,
            UNITS_New
        ]
    ]

    _to_host = True
    _to_equipment = False

    _has_reply = False
    _is_reply_required = False

    _is_multi_block = True

Integrate a stream function

Now we want to integrate this stream/function into the secsgem.gem.handler.GemHandler. You create a new class inherited from it and update the function list of that class:

class NewHandler(secsgem.gem.GemHostHandler):
    def __init__(self, settings: secsgem.common.Settings):
        super().__init__(settings)

        self.settings.streams_functions.update(SecsS01F12_New)

You can also add new methods and properties to the class if required.

The streams functions list can also be updated outside of the Handler:

settings = secsgem.hsms.HsmsSettings()
settings.streams_functions.update(SecsS01F12_New)

handler = NewHandler(settings)