Hello Chris, I found some time to do some testing and successfully read out a EtherCAT CoE SDO parameter. Here is the access from the Web UI of the Data Layer: Here you can see the FlatBuffer Schema of an SDO: include "addresstype.fbs";
namespace comm.ethercat.master.fbs;
enum SDOFlags: uint32 (bit_flags)
{
noFlags = 0,
completeAccess = 1,
}
table SDORequest
{
addressType: Addresstype;
address: uint16;
objectIndex: uint16;
subIndex: uint8;
flags: SDOFlags;
data: [uint8];
maxLength: uint32;
}
table SDOResponse
{
data: [uint8];
}
table SDO
{
request: SDORequest;
response: SDOResponse;
}
root_type SDO; Here I read the same SDO Parameter in C++ and printed out the response to the console: //_result is DlResult
//_data is Variant
//_client is IClient
flatbuffers::FlatBufferBuilder builder;
//build SDORequest
auto requestSDO = comm::ethercat::master::fbs::CreateSDORequest(builder,
comm::ethercat::master::fbs::Addresstype::Addresstype_fixedphysical,
1001,
12403,
1,
comm::ethercat::master::fbs::SDOFlags::SDOFlags_noFlags
);
builder.ForceDefaults(true);
builder.Finish(requestSDO);
//Build SDOResponse
std::vector<uint8_t> data;
data.resize(2);
auto responseData = builder.CreateVector<uint8_t>(data);
auto responseSDO = comm::ethercat::master::fbs::CreateSDOResponse(builder, responseData);
builder.ForceDefaults(true);
builder.Finish(responseSDO);
//Build SDO
auto sdo = comm::ethercat::master::fbs::CreateSDO(builder, requestSDO, responseSDO);
builder.ForceDefaults(true);
builder.Finish(sdo);
//share Flatbuffer to Variant
_result = _data.shareFlatbuffers(builder);
std::cout<<"_data.shareFlatbuffers(builder) "<< _result.toString()<<std::endl;
//use a data layer client to do the actual reading
_result =_client->readSync("fieldbuses/ethercat/master/instances/ethercatmaster/device_access/coe/sdo", &_data);
std::cout<<"_client->readSync(...) "<< _result.toString()<<std::endl;
if(_result == comm::datalayer::DlResult::DL_OK){
_result = _data.verifyFlatbuffers(comm::ethercat::master::fbs::VerifySDOBuffer);
std::cout<<"verifyFlatbuffers: "<<_result.toString()<<std::endl;
if (_result == comm::datalayer::DlResult::DL_OK)
{
auto buffer = _data.getData();
auto sdoValue= comm::ethercat::master::fbs::GetSDO(buffer);
auto sdoValueResponse = sdoValue->response();
auto sdoValueResponseData = sdoValueResponse->data();
auto length = sdoValueResponseData->Length();
for(uint32_t i = 0; i<length; i++){
std::cout<<"Response Data Byte" << i <<": "<<int(sdoValueResponseData->Get(i))<<std::endl;
}
}
} The output in the console is: _data.shareFlatbuffers(builder) DL_OK
_client->readSync(...) DL_OK
verifyFlatbuffers: DL_OK
Response Data Byte0: 1
Response Data Byte1: 96 Sorry for the late reply. I hope this (not optimized) code snippet can help you out. Best regards, Nick
... View more