Hello,

I have trouble to make my encoder EL5101 work with etherlab-rc5. A
colleague of mine tests it with LabView and it works. We concluded
that the only difference is that he downloaded last XML files.

I found a _huge_ difference in the file size of EL5101 xml between the
version in rc5 and the last available.
I downloaded the last available files and started the setup.m file in
the xml directory. I hope this is the right thing to do. (???)

I got a message that there is unrecognised DWORD in the EL5101 xml file.
I changed the XMLparsePDOEntry file and included the DWORD same as
UINT32. Hope this is the right thing. (???)

It now parses all the XML files
I attach the file modified m file for your reference.

-- 
Julian Stoev, PhD.
Control Researcher
function pdo_entry = XML_ParsePdoEntry(xml)

pdo_entry.Index = [];
pdo_entry.SubIndex = [];
pdo_entry.BitLen = [];
pdo_entry.DataType = [];

if ~nargin
    return
end

%% Get the Index and BitLen - required
try
    index = xml.getElementsByTagName('Index').item(0);
    pdo_entry.Index = fromHexString(index.getTextContent.trim);
    bit_len = xml.getElementsByTagName('BitLen').item(0);
    pdo_entry.BitLen= fromHexString(bit_len.getTextContent.trim);
catch
end

if isempty(pdo_entry.Index) || isempty(pdo_entry.BitLen)
    invalidDocument
end

if ~pdo_entry.Index
    return
end

%% Parse SubIndex and DataType

try
    subindex = xml.getElementsByTagName('SubIndex').item(0);
    pdo_entry.SubIndex = fromHexString(subindex.getTextContent.trim);
    data_type = xml.getElementsByTagName('DataType').item(0);
    data_type = data_type.getTextContent.trim;
catch
    invalidDocument
end

pdo_entry.DataType = getDataType(data_type, pdo_entry.BitLen);

%%
function w = getDataType(dt,bitlen)
if dt.startsWith('BOOL')
    w = 1;
elseif dt.startsWith('USINT') || dt.startsWith('UINT8') ...
        || dt.startsWith('BYTE') || dt.startsWith('STRING')
    w = 8;
elseif dt.equals('UINT') || dt.startsWith('UINT16')
    w = 16;
elseif dt.startsWith('UDINT') || dt.startsWith('UINT32') || 
dt.startsWith('DWORD')
    w = 32;
elseif dt.startsWith('ULINT') || dt.startsWith('UINT64')
    w = 64;
elseif dt.startsWith('SINT') || dt.startsWith('INT8')
    w = -8;
elseif dt.equals('INT') || dt.startsWith('INT16')
    w = -16;
elseif dt.startsWith('DINT') || dt.startsWith('INT32')
    w = -32;
elseif dt.startsWith('LINT') || dt.startsWith('INT64')
    w = -64;
elseif dt.startsWith('UINT')
    w = str2double(dt.substring(4));
    if bitlen ~= w
        warning('EtherCATDevice:XML_ParsePdoEntry:checkBitlen', ...
            ['Check the data types - <DataType> said %s, ', ...
            '<BitLength> said %u'], char(dt), bitlen);
        if isnan(w)
            w = bitlen;
        end
    end
elseif dt.startsWith('BIT')
    w = str2double(dt.substring(3));
    if isnan(w)
        w = bitlen;
    end
    if bitlen ~= w
        warning('EtherCATDevice:XML_ParsePdoEntry:checkBitlen', ...
            ['Check the data types - <DataType> said %s, ', ...
            '<BitLength> said %u'], char(dt), bitlen);
        if isnan(w)
            w = bitlen;
        end
    end
else
    error('Unknown data type %s', char(dt))
end

    

%%
function invalidDocument
error('XML file is not a valid EtherCATInfo Document');
_______________________________________________
etherlab-users mailing list
etherlab-users@etherlab.org
http://lists.etherlab.org/mailman/listinfo/etherlab-users

Reply via email to