The way you access to the realtime data in the scheduler example is quite similar then in the datalayer.realtime example. The main difference is that you do not connect to the ctrlX Data Layer via:
datalayer.factory()->createClient(DL_IPC_AUTO);
but you will use the service provided by the ctrlX Data Layer itself. You can do so because your code will be added as a bundle. To register a dependency to the service use following code in the activator.cpp. Please note that the name of the classes could differ:
// datalayer: cpp ServiceDependency w/ specifier 'name'
ServiceDependency<sdk::control::cmp_workshop, comm::datalayer::IDataLayerFactory>& serviceDepDl = component.createServiceDependency<comm::datalayer::IDataLayerFactory>(IDATALAYER_FACTORY_INTERFACE_NAME);
serviceDepDl.setVersionRange(IDATALAYER_CONSUMER_RANGE);
serviceDepDl.setRequired(true);
serviceDepDl.setStrategy(DependencyUpdateStrategy::suspend);
serviceDepDl.setCallbacks(&sdk::control::cmp_workshop::cppDlServiceStateChanged);
serviceDepDl.setCallbacks(&sdk::control::cmp_workshop::cppDlServiceAdded, &sdk::control::cmp_workshop::cppDlServiceRemoved);
In the callbacks created you can then handle over the service to your callableFactory:
std::shared_ptr<example::workshopCallableFactory> m_factory;
void cmp_workshop::cppDlServiceAdded(comm::datalayer::IDataLayerFactory* service) //Called automatically when callable added to task
{
m_datalayer_factory = service;
if (m_datalayer_factory)
{
m_factory->setDataLayerFactory(service); //Push DataLayerFactor service to m_factory
}
}
In your callableFactory start using it like you can see it in the datalayer.realtime example:
void workshopCallableFactory::setDataLayerFactory(comm::datalayer::IDataLayerFactory *datalayer_factory) //Called from cmp_workshop.cpp
{
m_datalayer_factory = datalayer_factory;
}
comm::datalayer::IClient *client = m_datalayer_factory->createClient();
The code that is called now in the cycle time you defined in the task can be found in the callable.cpp:
case common::scheduler::SchedEventType::SCHED_EVENT_TICK:
{
// Do cyclic stuff
// Better do not use something like std::cout, use trace instead.
TRACE_MSG("Scheduler event tick");
return common::scheduler::SchedEventResponse::SCHED_EVENT_RESP_OKAY;
}
... View more