cancel
Showing results for 
Search instead for 
Did you mean: 

Error while reading Ethercat CoE SDO via Datalayer (C++)

c-u
New Poster

Error while reading Ethercat CoE SDO via Datalayer (C++)

Hi everyone,

we need to read (and write) acyclical CoE objects to configure some motion controllers.

In this example we try to read the object with index 0x6041 of type U16

First we tried a request via the GUI and received the expected response. The request looks like this:

{
    "request": {
        "addressType": "fixedphysical",
        "address": 1003,
        "objectIndex": 24641,
        "subIndex": 0,
        "flags": "noFlags",
        "data": [],
        "maxLength": 2
    }
}

 

But when we try to do the apparently same request in our C++ application we always get a "DL_TYPE_MISMATCH". We build the flatbuffer as follows:

 

#include "comm/ethercat/master/fbs/sdo_generated.h"

// ...

flatbuffers::FlatBufferBuilder flatBufferBuilder = flatbuffers::FlatBufferBuilder();
std::vector<uint8_t> data;
data.resize(2);
auto requestData = flatBufferBuilder.CreateVector<uint8_t>(data);
auto sdoRequest = comm::ethercat::master::fbs::CreateSDORequest(flatBufferBuilder,
                                                                comm::ethercat::master::fbs::Addresstype::Addresstype_fixedphysical,
                                                                1003,    // ethercat slave address
                                                                24641,   // object index 0x6041
                                                                0,       // sub index 0
                                                                comm::ethercat::master::fbs::SDOFlags::SDOFlags_noFlags,
                                                                requestData,
                                                                2);
auto sdo = comm::ethercat::master::fbs::CreateSDO(flatBufferBuilder, sdoRequest);
flatBufferBuilder.Finish(sdo);
comm::datalayer::Variant payload;
auto variantResult = payload.copyFlatbuffers(flatBufferBuilder);

// ...

 

and do an asynchronous read:

 

 // DataLayerClient_ is an initialized comm::datalayer::IClient
auto result = DataLayerClient_->readAsync("fieldbuses/ethercat/master/instances/ethercatmaster/device_access/coe/sdo",
                                          payload,
                                          [](comm::datalayer::DlResult result, const comm::datalayer::Variant *data)
                                          {
                                              if (comm::datalayer::STATUS_FAILED(result))  // here we get the DL_TYPE_MISMATCH
                                              {
                                                  TRACE_MSG("Datalayer Read failed: %s", result.toString());
                                              }
                                              else
                                              {
                                                  // ...
                                              }
                                          });

 

 

We already tried several variations of the flatbuffer (e.g. different sized data, omitting the data, ..) but always get a DL_TYPE_MISMATCH.

What might be the reason for this Error? How can we fix it?

Is there any additional documentation of the Datalayer Interface of the EthercatMasterApp? All our information is based on the read-/write-type descriptions in the Datalayer itself.

 

Best Regards,
Chris

 


(The ctrlX is running on RM21.11 with SDK 1.12.0)

2 REPLIES 2
nickH
New Contributor

Re: Error while reading Ethercat CoE SDO via Datalayer (C++)

Hello Chris, 

sorry for the late reply. Unfortunately I did not find the time to build a test setup and investigate your issue. 

On the first look, the handling of your FlatBuffer looks good. I'm not sure about the requestData but I would need to try this out by myself. Additionally you could try to use the flatbuffers method ForceDefaults to use default values. 

 

...
builder.ForceDefaults(true);

builder.Finish(requestSDO);
_result = _data.shareFlatbuffers(builder);
std::cout<<"_data.shareFlatbuffers(builder) "<< _result.toString()<<std::endl;

_result =_client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/device_access/coe/sdo", &_data);
std::cout<<"_client->readSync(...) "<< _result.toString()<<std::endl;  
...

 

Further I would recommend to try it with a synchronous read first, to eliminate sources for error. 

I am sorry but at this point there is not more documentation on the interface.

 

Best regards,

Nick

 

c-u
New Poster

Re: Error while reading Ethercat CoE SDO via Datalayer (C++)

Hi Nick,

thanks for the reply, we tried to do the read the SDO synchronously with following minimal example, but we still get a DL_TYPE_MISMATCH as result. 

#include "comm/datalayer/datalayer.h"
#include "comm/datalayer/datalayer_system.h"
#include "comm/ethercat/master/fbs/sdo_generated.h"
// ... further includes

int main(int ac, char *av[])
{
  comm::datalayer::DlResult result;
  comm::datalayer::DatalayerSystem datalayer;
  datalayer.start(false);
  // connect to client
  // * in process communication (runs as bundle of rexroth-automation) use factory()->createClient()
  // * inter process communication (runs on same target) use factory()->createClient(DL_IPC_AUTO)
  // * on other device use  factory()->createClient("tcp://<ip>:2069")
  comm::datalayer::IClient *client = datalayer.factory()->createClient(DL_IPC_AUTO);

  if (client->isConnected())
  {
    std::cout << "Client connected" << std::endl;
  }
  else
  {
    std::cout << "Client not connected" << std::endl;
  }

  comm::datalayer::Variant data;
  do
  {
    uint16_t address = 1003;
    uint16_t objectIndex = 0x6041;
    uint8_t objectSubIndex = 0;
    flatbuffers::FlatBufferBuilder flatBufferBuilder;

    auto sdoRequest = comm::ethercat::master::fbs::CreateSDORequest(flatBufferBuilder,
                                                                    comm::ethercat::master::fbs::Addresstype::Addresstype_fixedphysical,
                                                                    address,
                                                                    objectIndex,
                                                                    objectSubIndex,
                                                                    comm::ethercat::master::fbs::SDOFlags::SDOFlags_noFlags);
    auto sdo = comm::ethercat::master::fbs::CreateSDO(flatBufferBuilder, sdoRequest);
    flatBufferBuilder.ForceDefaults(true);
    flatBufferBuilder.Finish(sdo);

    std::cout << "------------------StartCycle--------------------------" << std::endl;
    result = data.shareFlatbuffers(flatBufferBuilder);
    std::cout << "data.shareFlatbuffers(builder) " << result.toString() << std::endl;
    result = client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/device_access/coe/sdo", &data);
    std::cout << "client->readSync(...) " << result.toString() << std::endl;
    std::cout << "------------------StopCycle---------------------------" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));
  } while (!endProcess);
}

 

We would appreciate any information that could help us to resolve this issue.

Best regards 
Chris

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