How to use the helics.helicsFederateGetState function in helics

To help you get started, we’ve selected a few helics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GMLC-TDC / HELICS / tests / python_helics / test_message_filter.py View on Github external
p1 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port1", "")
    p2 = h.helicsFederateRegisterGlobalEndpoint(mFed, "port2", "random")

    f1 = h.helicsFederateRegisterGlobalFilter(fFed, h.helics_filtertype_custom, "filter1")
    h.helicsFilterAddSourceTarget(f1, "port1")
    f2 = h.helicsFederateRegisterGlobalFilter(fFed, h.helics_filtertype_delay, "filter2")
    h.helicsFilterAddSourceTarget(f2, "port1")
    h.helicsFederateRegisterEndpoint(fFed,'fout','');
    f3 = h.helicsFederateRegisterFilter(fFed, h.helics_filtertype_random_delay, 'filter3');
    h.helicsFilterAddSourceTarget(f3,'filter/fout');

    h.helicsFilterSet(f2, "delay", 2.5)
    h.helicsFederateEnterExecutingModeAsync(fFed)
    h.helicsFederateEnterExecutingMode(mFed)
    h.helicsFederateEnterExecutingModeComplete(fFed)
    state = h.helicsFederateGetState(fFed)
    assert state == 2
    data = "hello world"

    filt_key = h.helicsFilterGetName(f1);
    assert filt_key == 'filter1';

    filt_key = h.helicsFilterGetName(f2);
    assert filt_key == 'filter2';

    h.helicsEndpointSendMessageRaw(p1, "port2", data)
    h.helicsFederateRequestTimeAsync(mFed, 1.0)
    grantedtime = h.helicsFederateRequestTime(fFed, 1.0)
    assert grantedtime == 1.0
    grantedtime = h.helicsFederateRequestTimeComplete(mFed)
    assert grantedtime == 1.0
    res = h.helicsFederateHasMessage(mFed)
github GMLC-TDC / HELICS / tests / python / test_message_federate.py View on Github external
def test_message_federate_initialize(mFed):
    state = h.helicsFederateGetState(mFed)
    assert state == 0
    h.helicsFederateEnterExecutingMode(mFed)

    state = h.helicsFederateGetState(mFed)
    assert state == 2
github GMLC-TDC / HELICS / tests / python / test_message_federate.py View on Github external
# HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta, deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo, h.helics_property_int_log_level, 1)


    mFed = h.helicsCreateMessageFederate("TestA Federate", fedinfo)

    yield mFed

    h.helicsFederateFinalize(mFed)
    state = h.helicsFederateGetState(mFed)
    assert state == 3
    while (h.helicsBrokerIsConnected(broker)):
        time.sleep(1)

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(mFed)
    h.helicsCloseLibrary()
github GMLC-TDC / HELICS / tests / python_helics / test_message_filter.py View on Github external
def FreeFederate(fed, fedinfo):
    h.helicsFederateFinalize(fed)
    state = h.helicsFederateGetState(fed)
    assert state == 3 # TODO: should this be 3?

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(fed)
github GMLC-TDC / HELICS / tests / python / test_value_federate.py View on Github external
# HELICS minimum message time interval is 1 ns and by default
    # it uses a time delta of 1 second. What is provided to the
    # setTimedelta routine is a multiplier for the default timedelta.

    # Set one second message interval #
    h.helicsFederateInfoSetTimeProperty(fedinfo, h.helics_property_time_delta, deltat)

    h.helicsFederateInfoSetIntegerProperty(fedinfo, h.helics_property_int_log_level, 1)

    vFed = h.helicsCreateValueFederate("TestA Federate", fedinfo)

    yield vFed

    h.helicsFederateFinalize(vFed)

    state = h.helicsFederateGetState(vFed)
    assert state == 3

    while (h.helicsBrokerIsConnected(broker)):
        time.sleep(1)

    h.helicsFederateInfoFree(fedinfo)
    h.helicsFederateFree(vFed)
    h.helicsCloseLibrary()
github GMLC-TDC / HELICS / examples / python / timing-demo / timing-federate2.py View on Github external
def destroy_value_federate(fed):
    status = h.helicsFederateFinalize(fed)
    assert status == 0
    status, state = h.helicsFederateGetState(fed)
    assert state == 3
    assert status == 0

    h.helicsFederateFree(fed)

    h.helicsCloseLibrary()
github GMLC-TDC / HELICS / examples / python / timing-demo / timing-federate1.py View on Github external
def destroy_value_federate(fed, broker):
    status = h.helicsFederateFinalize(fed)
    assert status == 0
    status, state = h.helicsFederateGetState(fed)
    assert status == 0
    assert state == 3

    while (h.helicsBrokerIsConnected(broker)):
        time.sleep(1)

    h.helicsFederateFree(fed)

    h.helicsCloseLibrary()