diff --git a/examples/pireceiver.m b/examples/pireceiver.m index b83a786..9ea2cc7 100644 --- a/examples/pireceiver.m +++ b/examples/pireceiver.m @@ -11,15 +11,25 @@ % if the condition is true and if so continues. If false, execution stops. %% Initialize HELICS library in MATLAB -helicsStartup() +%helicsStartup() +%HELICS_PATH = 'C:\Users\mukh915\matHELICS\helics'; +HELICS_PATH = '/home/helics-user/Softwares_user/matHELICS/'; +addpath(HELICS_PATH) +% Checking if Octave or Matlab +isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; +if isOctave + % Using custom Import as the import function is not yet implemented in Octave + addpath(fullfile(HELICS_PATH, '+helics')) +else + import helics.* +end -import helics.*; %% Configuration deltat = 0.01; %Base time interval (seconds) sim_stop_time = 20; % HELICS options -helics_core_type = 'zmq'; +helics_core_type = 'zmq'; fedinitstring = '--federates=1'; % required with current C interface when using separate processes for each federate %% Provide summary information @@ -39,16 +49,16 @@ helics.helicsFederateInfoSetCoreInitString(fedinfo, fedinitstring); -%% Set the message interval (timedelta) for federate. +%% Set the message interval (timedelta) for federate. % Note: % 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 +% setTimedelta routine is a multiplier for the default timedelta % (default unit = seconds). % Set one message interval -helicsFederateInfoSetTimeProperty(fedinfo,helics_property_time_delta,deltat); -helicsFederateInfoSetIntegerProperty(fedinfo,helics_property_int_log_level,helics_log_level_warning); +helicsFederateInfoSetTimeProperty(fedinfo, HelicsProperties.HELICS_PROPERTY_TIME_DELTA, deltat); +helicsFederateInfoSetIntegerProperty(fedinfo, HelicsProperties.HELICS_PROPERTY_INT_LOG_LEVEL, HelicsLogLevels.HELICS_LOG_LEVEL_WARNING); diff --git a/examples/pisender.m b/examples/pisender.m index 0574218..b0e2eff 100644 --- a/examples/pisender.m +++ b/examples/pisender.m @@ -1,17 +1,27 @@ % PISENDER script demonstrating MATLAB-HELICS interface % % Usage: -% 1. Start two separate MATLAB terminals -% 2. In the first: +% 1. Start two separate MATLAB terminals +% 2. In the first: % >> pisender % 3. In the second: % >> pireciever %% Initialize HELICS library in MATLAB -helicsStartup() +%helicsStartup() +%HELICS_PATH = 'C:\Users\mukh915\matHELICS\helics'; % matHELICS path +HELICS_PATH = '/home/helics-user/Softwares_user/matHELICS/'; % matHELICS path +addpath(HELICS_PATH) +% Checking if Octave or Matlab +isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; +if isOctave + % Using custom Import as the import function is not yet implemented in Octave + addpath(fullfile(HELICS_PATH, '+helics')) +else + import helics.* +end -import helics.*; %% Configuration deltat = 1; %Base time interval (seconds) numsteps = 20; @@ -20,7 +30,7 @@ % Note: these configure this matlab process to host the main broker and 1 % federate pisend_start_broker = true; -helics_core_type = 'zmq'; +helics_core_type = 'zmq'; broker_initstring = '--federates 2 --name=mainbroker'; fed_initstring = '--broker=mainbroker --federates=1'; @@ -59,19 +69,19 @@ % Note: % 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 +% setTimedelta routine is a multiplier for the default timedelta % (default unit = seconds). % Set one message interval -helicsFederateInfoSetTimeProperty(fedinfo,helics_property_time_delta,deltat); -helicsFederateInfoSetIntegerProperty(fedinfo,helics_property_int_log_level,helics_log_level_warning); +helicsFederateInfoSetTimeProperty(fedinfo, HelicsProperties.HELICS_PROPERTY_TIME_DELTA, deltat); +helicsFederateInfoSetIntegerProperty(fedinfo, HelicsProperties.HELICS_PROPERTY_INT_LOG_LEVEL, HelicsLogLevels.HELICS_LOG_LEVEL_WARNING); %% Actually create value federate vfed = helicsCreateValueFederate('MATLAB Pi SENDER Federate',fedinfo); disp('PI SENDER: Value federate created'); %% Register our value to publish -pub = helicsFederateRegisterGlobalPublication(vfed, 'testA', helics_data_type_double, ''); +pub = helicsFederateRegisterGlobalPublication(vfed, 'testA', HelicsDataTypes.HELICS_DATA_TYPE_DOUBLE, ''); disp('PI SENDER: Publication registered (testA)'); %% Start execution @@ -111,11 +121,11 @@ helicsBrokerWaitForDisconnect(broker,-1); disp('PI SENDER: Broker disconnected'); - helics.helicsFederateFree(vfed); - helics.helicsCloseLibrary(); + helicsFederateFree(vfed); + helicsCloseLibrary(); else %But if we just setup the federate, we can simply call endFederate - helicsFederateDestroy(vfed); %#ok + helicsFederateDestroy(vfed); %#ok disp('PI SENDER: Federate finalized'); end diff --git a/examples/simpleFederate.m b/examples/simpleFederate.m index 7826f5f..75125e2 100644 --- a/examples/simpleFederate.m +++ b/examples/simpleFederate.m @@ -1,14 +1,25 @@ %% a single federate example for HELICS in matlab -helicsStartup -import helics.* +%helicsStartup +%HELICS_PATH = 'C:\Users\mukh915\matHELICS\helics'; % matHELICS path +HELICS_PATH = '/home/helics-user/Softwares_user/matHELICS/'; % matHELICS path +addpath(HELICS_PATH) +% Checking if Octave or Matlab +isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; +if isOctave + % Using custom Import as the import function is not yet implemented in Octave + addpath(fullfile(HELICS_PATH, '+helics')) +else + import helics.* +end + % create a broker so we don't have to do this separately brk=helicsCreateBroker('','B1','-f1'); % create a combination federate so we add both endpoint and % publications/inputs fi=helicsCreateFederateInfo(); fed1=helicsCreateCombinationFederate('fed1',fi); -helicsFederateSetFlagOption(fed1,HelicsFederateFlags.HELICS_FLAG_UNINTERRUPTIBLE,HELICS_TRUE) +helicsFederateSetFlagOption(fed1, HelicsFederateFlags.HELICS_FLAG_UNINTERRUPTIBLE, HELICS_TRUE) % register Endpoint1/2 e1=helicsFederateRegisterGlobalEndpoint(fed1,'Endpoint1',''); e2=helicsFederateRegisterGlobalEndpoint(fed1,'Endpoint2',''); @@ -58,5 +69,5 @@ %now the broker should terminate the cosimulation helicsBrokerWaitForDisconnect(brk,0); %close up the library and clean up any memory use that hasn't been cleaned -%already. +%already. helicsCloseLibrary();