How to use the helics.helicsEndpointSendMessageRaw 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
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)
    assert res==0
    res = h.helicsEndpointHasMessage(p2)
    assert res==0
    #grantedtime = h.helicsFederateRequestTime(fFed, 3.0)
    #assert res==h.helics_true

    h.helicsFederateFinalize(mFed)
    h.helicsFederateFinalize(fFed)
    #f2 = h.helicsFederateRegisterDestinationFilter (fFed, h.helics_custom_filter, "filter2", "port2")
    #ep1 = h.helicsFederateRegisterEndpoint (fFed, "fout", "")
github GMLC-TDC / HELICS / examples / user_guide_examples / Example_1c / EV_Controller / EV_Controller.py View on Github external
status = h.helicsEndpointSendMessageRaw(end, destination_name, str('0 + 0 j'))
                logger.info('Turning off {}'.format(end_name))
                k=k+1
            else:
                 logger.info('All EVs are Turned off')

        if  (Real_feeder_load < feeder_limit_lower):
            logger.info('Total Feeder Load is under the Feeder Lower Limit')
            logger.info('Feeder Can Support EVs ------>  Turn on EV')
            if (k > 0):
                k=k-1
                end = endid["m{}".format(k)]
                end_name = h.helicsEndpointGetName(end)
                destination_name = (end_name.replace(federate_name,distribution_fed_name))
                print('Endpoint Destination {}'.format(destination_name))
                status = h.helicsEndpointSendMessageRaw(end, destination_name, str('200000 + 0 j'))
                logger.info('Turning on {}'.format(end_name))
            else:
                logger.info('All EVs are Turned on')

    fig = plt.figure()
    fig.subplots_adjust(hspace=0.4, wspace=0.4)
    i = 1
    for keys in data:
        ax = fig.add_subplot(2, 3, i)
        ax.plot(time_sim, data[keys])
        ax.set_ylabel('EV Output in kW')
        ax.set_xlabel('Time ')
        ax.set_title(keys)
        i=i+1

    plt.show(block=True)
github GMLC-TDC / HELICS / examples / user_guide_examples / Example_1b / EV_Controller / EV_Controller.py View on Github external
logger.info("EV Controller grantedtime = {}".format(grantedtime))

        logger.info('Total Feeder Load is {} + {} j'.format(Real_feeder_load, Imag_feeder_load))

        if (Real_feeder_load > feeder_limit_upper):
            logger.info('Total Feeder Load is over the Feeder Upper Limit')
            logger.info('Warning ----> Feeder OverLimit --->  Turn off EV')

            if (k < endpoint_count):
                end = endid["m{}".format(k)]
                logger.info('endid: {}'.format(endid))
                end_name = str(h.helicsEndpointGetName(end))
                logger.info('Sending endpoint name: {}'.format(end_name))
                destination_name = (end_name.replace(federate_name, distribution_fed_name))
                logger.info('Endpoint destination: {}'.format(h.helicsEndpointGetDefaultDestination(end)))
                status = h.helicsEndpointSendMessageRaw(end, '', str('0 + 0 j')) #
                logger.info('Endpoint sending status: {}'.format(status))
                logger.info('Turning off {}'.format(end_name))
                k=k+1
            else:
                 logger.info('All EVs are Turned off')

        if  (Real_feeder_load < feeder_limit_lower):
            logger.info('Total Feeder Load is under the Feeder Lower Limit')
            logger.info('Feeder Can Support EVs ------>  Turn on EV')
            if (k > 0):
                k=k-1
                end = endid["m{}".format(k)]
                end_name = h.helicsEndpointGetName(end)
                destination_name = (end_name.replace(federate_name,distribution_fed_name))
                print('Endpoint Destination {}'.format(destination_name))
                status = h.helicsEndpointSendMessageRaw(end, '', str('200000 + 0 j'))
github GMLC-TDC / HELICS / examples / python / timing-demo / timing-federate1.py View on Github external
break
        while grantedtime < stop_at_time:
            print(">>>>>>>> Requesting time = {}".format(stop_at_time))
            status, grantedtime = h.helicsFederateRequestTime(fed, stop_at_time)
            assert status == 0
            if grantedtime != stop_at_time:
                status, value = h.helicsSubscriptionGetString(subid)
                assert status == 0
                print("Interrupt value '{}' from Federate 2".format(value))
            print("<<<<<<<< Granted Time = {}".format(grantedtime))
        assert grantedtime == stop_at_time, "stop_at_time = {}, grantedtime = {}".format(stop_at_time, grantedtime)
        if value_to_send is not None and value_to_send != '':
            print("Sending '{}' to Federate 2".format(value_to_send))
            status = h.helicsPublicationPublishString(pubid, str(value_to_send))
            assert status == 0
            status = h.helicsEndpointSendMessageRaw(epid, "endpoint2", str(value_to_send))
            assert status == 0
        status, value = h.helicsSubscriptionGetString(subid)
        assert status == 0
        print("Received value '{}' from Federate 2".format(value))
        while h.helicsEndpointHasMessage(epid):
            value = h.helicsEndpointGetMessage(epid)
            print("Received message '{}' at time {} from Federate 2".format(value.data, value.time))
        print("----------------------------------")

    destroy_value_federate(fed, broker)
github GMLC-TDC / HELICS / examples / user_guide_examples / Example_1c / EV_Controller / EV_Controller.py View on Github external
logger.info("EV Controller grantedtime = {}".format(grantedtime))

        logger.info('Total Feeder Load is {} + {} j'.format(Real_feeder_load, Imag_feeder_load))

        if (Real_feeder_load > feeder_limit_upper):
            logger.info('Total Feeder Load is over the Feeder Upper Limit')
            logger.info('Warning ----> Feeder OverLimit --->  Turn off EV')

            if (k < endpoint_count):
                end = endid["m{}".format(k)]
                end_name = str(h.helicsEndpointGetName(end))
                print(end_name)
                destination_name = (end_name.replace(federate_name, distribution_fed_name))
                print('Endpoint Destination {}'.format(destination_name))
                status = h.helicsEndpointSendMessageRaw(end, destination_name, str('0 + 0 j'))
                logger.info('Turning off {}'.format(end_name))
                k=k+1
            else:
                 logger.info('All EVs are Turned off')

        if  (Real_feeder_load < feeder_limit_lower):
            logger.info('Total Feeder Load is under the Feeder Lower Limit')
            logger.info('Feeder Can Support EVs ------>  Turn on EV')
            if (k > 0):
                k=k-1
                end = endid["m{}".format(k)]
                end_name = h.helicsEndpointGetName(end)
                destination_name = (end_name.replace(federate_name,distribution_fed_name))
                print('Endpoint Destination {}'.format(destination_name))
                status = h.helicsEndpointSendMessageRaw(end, destination_name, str('200000 + 0 j'))
                logger.info('Turning on {}'.format(end_name))
github GMLC-TDC / HELICS / examples / python / timing-demo / timing-federate2.py View on Github external
break
        while grantedtime < stop_at_time:
            print(">>>>>>>> Requesting time = {}".format(stop_at_time))
            status, grantedtime = h.helicsFederateRequestTime(fed, stop_at_time)
            assert status == 0
            if grantedtime != stop_at_time:
                status, value = h.helicsSubscriptionGetString(subid)
                assert status == 0
                print("Interrupt value '{}' from Federate 1".format(value))
            print("<<<<<<<< Granted Time = {}".format(grantedtime))
        assert grantedtime == stop_at_time, "stop_at_time = {}, grantedtime = {}".format(stop_at_time, grantedtime)
        if value_to_send is not None and value_to_send != '':
            print("Sending '{}' to Federate 1".format(value_to_send))
            status = h.helicsPublicationPublishString(pubid, str(value_to_send))
            assert status == 0
            status = h.helicsEndpointSendMessageRaw(epid, "endpoint1", str(value_to_send))
            assert status == 0

        status, value = h.helicsSubscriptionGetString(subid)
        assert status == 0
        print("Received value '{}' from Federate 1".format(value))
        while h.helicsEndpointHasMessage(epid):
            value = h.helicsEndpointGetMessage(epid)
            print("Received message '{}' at time {} from Federate 1".format(value.data, value.time))
        print("----------------------------------")


    destroy_value_federate(fed)