Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

DL_RT_INVALIDOBJECT

DL_RT_INVALIDOBJECT

Elleshar
Established Member

Dear Community,

we got an issue with a read from the Datalayer.

/**
 * MIT License
 *
 * Copyright (c) 2020-2021 Bosch Rexroth AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "comm/datalayer/datalayer.h"
#include "comm/datalayer/datalayer_system.h"
#include "comm/datalayer/memory_map_generated.h"

#include <stdio.h>
#include <signal.h>
#include <thread>
#include <iostream>

bool endProcess = false;
static void hdl(int sig, siginfo_t *siginfo, void *context)
{
  endProcess = true;
}

void cleanup(comm::datalayer::DatalayerSystem *datalayer,
             comm::datalayer::IClient *client,
             std::shared_ptr<comm::datalayer::IMemoryUser> input)
{
  comm::datalayer::DlResult result;
  std::cout << "finish my work" << std::endl;
  result = datalayer->factory()->closeMemory(input);
  if (comm::datalayer::STATUS_FAILED(result))
    std::cout << "Closing input memory failed with: " << result.toString() << std::endl;

  delete client;

  datalayer->stop();
  printf("\n");

  exit(0);
}

static constexpr const char *EthercatInputNode_ = "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input";
static constexpr const char *EthercatInputNodeMap_ = "fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input/map";

int main(int ac, char *av[])
{
  comm::datalayer::DlResult result;
  comm::datalayer::Variant data;
  comm::datalayer::DatalayerSystem datalayer;
  uint8_t *inData;
  uint8_t *outData;

  // Start datalayer without a broker - a broker already exists in automation snap
  datalayer.start(false);

  // Local
  // comm::datalayer::IClient *client = datalayer.factory()->createClient("tcp://boschrexroth:Boschrexroth1@192.168.1.12:2069");

  // Snap
  comm::datalayer::IClient *client = datalayer.factory()->createClient(DL_IPC_AUTO);

  if (!client->isConnected())
  {
    std::cout << "could not connect to datalayer, check ip and login data" << std::endl;
    datalayer.stop();
    return 1;
  }

  // Read the Memory Map to take the revision number, the revision number is necessary to work with the memory
  result = client->readSync(EthercatInputNodeMap_, &data);
  if (STATUS_FAILED(result))
  {
    std::cout << "Reading Memory Map failed with " << result.toString() << std::endl;
    delete client;
    datalayer.stop();
    return 2;
  }

  auto memMap = comm::datalayer::GetMemoryMap(data.getData());
  auto revision = memMap->revision();
  std::cout << "Revision Number of Memory Map: " << revision << std::endl;

  std::cout << "Opening some realtime memory: " << EthercatInputNode_ << std::endl;
  std::shared_ptr<comm::datalayer::IMemoryUser> input;
  result = datalayer.factory()->openMemory(input, EthercatInputNode_);
  if (comm::datalayer::STATUS_FAILED(result))
  {
    std::cout << "creation of input failed with: " << result.toString() << std::endl;
    delete client;
    datalayer.stop();
    return 3;
  }

  // Structure to interrupt the do while loop with SIGINT
  struct sigaction act;
  memset(&act, '\0', sizeof(act));
  act.sa_sigaction = &hdl;
  act.sa_flags = SA_SIGINFO;
  sigaction(SIGINT, &act, NULL);

  std::cout << "start producing some output data" << std::endl;
  do
  {
    std::this_thread::sleep_for(std::chrono::seconds(1));

    result = input->beginAccess(inData, revision);
    if (STATUS_SUCCEEDED(result))
    {
      std::cout << "first byte of input: " << inData[0] << std::endl;
      input->endAccess();
    }
    else
    {
      std::cout << "input memory not present at the moment: " << result.toString() << std::endl;
    };

  } while (!endProcess);

  // Cleanup closes the memory and stop the datalayersystem
  cleanup(&datalayer, client, input);
}

 

Output:
2022-07-25T15:24:35Z systemd[1]: Started Service for snap application sdk-cpp-realtime.datalayerRealtimeUser.
2022-07-25T15:24:35Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: Revision Number of Memory Map: 3985439437
2022-07-25T15:24:35Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: Opening some realtime memory: fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output
2022-07-25T15:24:35Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: start producing some output data
2022-07-25T15:24:36Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:37Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:38Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:39Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:40Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:41Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:42Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:43Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT
2022-07-25T15:24:44Z sdk-cpp-realtime.datalayerRealtimeUser[5312]: input memory not present at the moment: DL_RT_INVALIDOBJECT

Any suggestions how this can occur?
Actual we are using SDK version 1.14.
Our path to the datalayer-node is: fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/output
The communication over the web-ui is working fine.

Sincerely Elleshar

1 REPLY 1

nickH
Community Moderator
Community Moderator

Hello Elleshar,

I tested your code and it works like expected. So I can read the input values and can not reproduce your error. I would recommed to look at your fieldbus configuration. 

I tested it also with ctrlX CORE V1.14. As EtherCAT Slaves I used a ctrlX IO bus coupler and two DI16 modules. 

 

One side hint: 

To print out your uint8_t value in C++ correctly, you can use unsingned() to convert it.

result = input->beginAccess(inData, revision);
    if (STATUS_SUCCEEDED(result))
    {
      std::cout << "first byte of input: " << unsigned(inData[0]) << std::endl;
      input->endAccess();
    }

 

Best regards, 

Nick

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist