Get SDO Information via Ads

                                                                Get SDO Information via Ads

                                                                                                                                                2023 6/5  by Advan

[Foreword]

*Sdo Information 資訊可以存在於Device description ESI file , 或從站中,若從站支援 SDO Info資訊時可透過此文件方式取得SDO Info,該資訊跟SDO 數值一樣存在於Slave μC , 透過Mailbox方式做傳遞。

*Sdo Info TwinCAT 本身即提供的功能(See Device OD from online – via SDO Information ),但在應用端的說明文件參考並不多,此文件旨在說明如何藉由Ads 實現取得SDO Information的發展&測試紀錄,且ADS 能再透過AMS Router 方式存取,廣度得以擴展,讓應用端發展加添更多可能性。

*文件目的在說明如何從藉由應用端(Ads)實現取得sdo info 資訊,要點 & 實作紀錄,並說明基於此功能建置功能群之說明。

 

 

 

[Reference  參考文件]

ETG1000_6_V1i0i4_S_R_EcatALProtocols

5.6 CoE coding

EtherCAT Automation Protocol 參考手冊的

https://download.beckhoff.com/download/Document/automation/twincat3/EAP_EN.pdf

 

 


[Command Overview]

SDO Command / related E_CoeCommand

ADS Command

Index
Group

Index
Offset

Description & define

SDO Read (CoE.SDO.Upload)
/

eSdo_Read

AdsRead()

0xF302

Bit 16-31: Index
Bit 8: Complete Access
Bit 0-7: Subindex

SDO Upload request
Return Data Type :
取決於資料定義,最小單位為Byte

SDO Write (CoE.SDO.Download)

/

eSdo_Write

AdsWrite()

0xF302

Bit 16-31: Index
Bit 8: Complete Access
Bit 0-7: Subindex

SDO Download request
Return Data Type :
取決於資料定義,最小單位為Byte

SDO Information
Get Object list

/

eGetList_GetElementNumberInGroups

 

eGetList_GetIndex_All

eGetList_GetIndex_RxPDO

eGetList_GetIndex_TxPDO

eGetList_GetIndex_Backup

eGetList_GetIndex_Setting

AdsRead()

0xF3FC

Bit 16-31: List Type

0x0000 :依分類列出所有OD 數量

0x0001 :列出所有OD index List 清單

0x0002 :列出RXPDO OD index List 清單

0x0003 :列出TXPDO OD index List 清單

0x0004 :列出Backup OD index List 清單(資料停電保持群)

0x0005 :列出Setting OD index List 清單(參數設定群)

 

 

SDO Information Get Object list

(取得OD 列表數量 & Index資訊)

 

0x0000 Return Data Type :
UINT16[1] + UINT16[6]

(List type)     (OD Number INT[6])


0x0001 ~ 0x0005 Return Data Type :
UINT16[1] + UINT16[n]

 (List type)    (OD Index INT[n])

 



SDO Information
Get Object Description

/

eGetObjectDescription

AdsRead()

0xF3FD

Bit 16-31: Index

SDO Information Get Object Description

(取得Object 敘述)

Read the SDO description of the complete object with the specified index

 

Return Data Type : ST_SdoInfo_GetObjectDescriptionReply

SDO Information
Get Entry Description

/

eGetEntryDescription

AdsRead()

0xF3FE

Bit 16-31: Index
Bit 0-7: Subindex

SDO Information Get Entry Description

 

Read the SDO description of the individual entry with the specified subindex belonging to the object with the specified index.

 

Return Data Type : ST_SdoInfo_GetEntryDescriptionReply

 

 

 

 

 

* UINT16[6] mean 6 elements of UINT16 , eg..rData : ARRAY[0..5] OF UINT;                   (* PLC Coding *)         

 


 

[API Overview]

FB_EcCoeSdoService


此功能塊類似 TcEtherCAT.lib  EcCoeSdoReadEx , EcCoeSdoWriteEx 並做個加強,在支援SDO Info support 的裝置中可以提供OD(Object Dictionary)資訊的取得,其中功能包含

·         取得Object 數量 [eGetList_GetElementIndexNumber]

·         取得Object Index 清單 [eGetList_GetIndex_***]

                        eGetList_GetIndex_All           // 取得全部元素的Index 清單

                        eGetList_GetIndex_RxPDO,    // 取得RxPDO群裡元素的Index 清單

                        eGetList_GetIndex_TxPDO,    // 取得TxPDO群裡元素的Index 清單

                        eGetList_GetIndex_Backup,   // 取得Backup群裡元素的Index 清單

                        eGetList_GetIndex_Setting,   // 取得Setting群裡元素的Index 清單

 

·         取得Object Description 資訊 [eGetObjectDescription]

回傳格式為ST_SdoInfo_GetObjectDescription , 請參照下方說明

其內容資訊包含如下

                Object index ; eDataType資料型別 ;

nMaxSubIndex 最大Subindex 號碼(若有) ;

ObjectCode定義(eg 7 : Var => 則無Subindex , Subindex = 0 ) ;

以及Object Name.

 

·         取得Object Entry Description資訊 [eGetEntryDescription]

回傳格式為ST_SdoInfo_GetEntryDescription , 請參照下方說明

其內容資訊包含如下

                Object index ;

Object SubIndex ; ValueInfo (定義上為Unit type/default/min/max 尚不確定含意)

                eDataType資料型別 ;

nBitLen 資料長度Inbit ;

nObjectAccess 存取權限;

以及Object Name.

 

依上述功能,即可做後端建置,利用此功能塊建立CoE list,請參考[後記]的測試紀錄。 


 

VAR_INPUT

                sNetId                     : T_AmsNetId;         (* AmsNetId of the EtherCAT master device.*)

                eCommand             : E_CoeCommand ;

                nSlaveAddr              : UINT;     (* Address of the slave device. , Assign 16#FFFF as Master interface *)

                nSubIndex               : BYTE;                     (* Parameter for "eGetObjectDescription" &  "eGetEntryDescription" command assign  *)

                nIndex                     : UINT;                     (* Parameter for "eGetEntryDescription" command assign *)

                pDataStruct             : PVOID;                   (* Data pointer address *)

                cbBufLen                 : UDINT;                  (* Buffer size must  meet or >= request command return data type *)

                bExecute                 : BOOL;                    (* Function block execution is triggered by a rising edge at this input.*)

                tTimeout                 : TIME := DEFAULT_ADS_TIMEOUT;

END_VAR

 

VAR_OUTPUT

                bBusy      : BOOL;

                bError      : BOOL;

                nErrId      : UDINT;

                nReturnLen             : UDINT;                  (* Actual return data len *)

END_VAR

 

 

 

TYPE E_CoeCommand :

(

(* ==== Sdo access request ===== *)

(* ADS internal define Index group  0xF302 *)

                eSdo_Read := 1,                                      (* sdo download *)

                eSdo_ReadCompleteAccess,  (* assing 256 (0x100) to subindex as complete access *)

                eSdo_Write,                                            (* sdo upload *)

                eSdo_WriteCompleteAccess,

 

 

(* ==== Sdo Info access request ===== *)

(* ADS internal define Index group  0xF3FC *)

                eGetList_GetElementIndexNumber :=10,

                eGetList_GetIndex_All,

                eGetList_GetIndex_RxPDO,

                eGetList_GetIndex_TxPDO,

                eGetList_GetIndex_Backup,

                eGetList_GetIndex_Setting,

 

(* ADS internal define Index group  0xF3FD *)

                eGetObjectDescription,

 

(* ADS internal define Index group  0xF3FE *)

                eGetEntryDescription);

 

END_TYPE

 

[API/回傳資料導讀(Ads)]

列出OD 數量 & 並分類

SDO Information
Get Object list

/

eGetList_GetElementNumberInGroups

 

Return type 12byte(fix)

TYPE ST_SdoInfo_GetElementNumberInGroup :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nNoOf_All               :               UINT;                       (* Number of object in list  *)

                nNoOf_RxPDO        :               UINT;                       (* Number of object category in RxPDO *)

                nNoOf_TxPDO         :               UINT;                       (* Number of object category in TxPDO *)

                nNoOf_Backup        :               UINT;                       (* Number of object category in Backup *)

                nNoOf_Setting        :               UINT;                       (* Number of object category in Setting *)

END_STRUCT

END_TYPE

 

//////////////////////////////////////////////////////////////////////////////

列出 全部的Object Index number

SDO Information
Get Object list GetIndex_All

/

eGetList_GetIndex_All

 

Return type 2byte + NumberofElement * 2

TYPE ST_SdoInfo_GetObjectList :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nObjectIndexArray  :               ARRAY[0..nMaxListIndex] OF WORD;   (* Object index array *)

END_STRUCT

END_TYPE

//////////////////////////////////////////////////////////////////////////////

列出 RxPDO群裡的Object Index number

SDO Information
Get Object list GetIndex_RxPDO

/

eGetList_GetIndex_RxPDO

 

Return type 2byte + NumberofElement * 2

TYPE ST_SdoInfo_GetObjectList :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nObjectIndexArray  :               ARRAY[0..nMaxListIndex] OF WORD;   (* Object index array *)

END_STRUCT

END_TYPE

 


 

//////////////////////////////////////////////////////////////////////////////

列出 TxPDO群裡的Object Index number

SDO Information
Get Object list GetIndex_TxPDO

/

eGetList_GetIndex_TxPDO

 

Return type 2byte + NumberofElement * 2

TYPE ST_SdoInfo_GetObjectList :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nObjectIndexArray  :               ARRAY[0..nMaxListIndex] OF WORD;   (* Object index array *)

END_STRUCT

END_TYPE

 

//////////////////////////////////////////////////////////////////////////////

列出 Backup(斷電記憶)裡的Object Index number

SDO Information
Get Object list GetIndex_Backup

/

eGetList_GetIndex_ Backup

 

Return type 2byte + NumberofElement * 2

TYPE ST_SdoInfo_GetObjectList :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nObjectIndexArray  :               ARRAY[0..nMaxListIndex] OF WORD;   (* Object index array *)

END_STRUCT

END_TYPE

 

//////////////////////////////////////////////////////////////////////////////

列出 Setting群裡的Object Index number

SDO Information
Get Object list GetIndex_Setting

/

eGetList_GetIndex_ Setting

 

Return type 2byte + NumberofElement * 2

TYPE ST_SdoInfo_GetObjectList :

STRUCT

                nListType                 :               WORD;                    (* Like echo , same as request list  *)

                nObjectIndexArray  :               ARRAY[0..nMaxListIndex] OF WORD;   (* Object index array *)

END_STRUCT

END_TYPE


 

取得OD 敘述資訊

SDO Information
Get Object Description

/

eGetObjectDescription

 

Return type 6byte + Description String Length

TYPE ST_SdoInfo_GetObjectDescription :

STRUCT

                nIndex                     :               WORD;                                    (* Return object index *)

                eDataType               :               E_CoeSdoDataTypeCode;        (* data type eNum  *)

                nMaxSubIndex        :               BYTE;                       (* max subindex of object(If have) *)

                nObjectCode           :               BYTE;       (* 2 Domain , 5 DefType , 6 DefStruce , 7 Var , 8 Array , 9 Record *)

                sName                    :               T_OdInfoMaxString;               (* STRING(63)   object description string  *)

END_STRUCT

END_TYPE

//////////////////////////////////////////////////////////////////////////////

 

取得OD Entry敘述(取得OD 子元素/subindex敘述)

SDO Information
Get Entry Description

/

eGetEntryDescription

 

Return type 6byte + Description String Length

TYPE ST_SdoInfo_GetEntryDescription :

STRUCT

                nIndex                     :               WORD;                                    (* Return object index *)

                nSubIndex                :               BYTE;                                       (* Return object sub index *)

                nValueInfo              :               BYTE;                       (* The value info includes which elements are in the response:

Bit  0: reserved

Bit  1: reserved

Bit 2: reserved Bit 3: unit type

Bit 4: default  value Bit 5: minimum value Bit 6: maximum value

 *)

                eDataType               :               E_CoeSdoDataTypeCode;

                nBitLen                    :               UINT;

                nObjectAccess        :               WORD;                    (* Flag define R/W access right in Slave states , and support  PDO mapping or not

Bit 0: read access in Pre-Operational state

Bit 1: read access in Safe-Operational state

Bit 2: read access in Operational state

Bit 3: write access in Pre-Operational state

Bit 4: write access in Safe-Operational state

Bit 5: write access in Operational state

Bit 6: object is mappable in a RxPDO

Bit 7: object is mappable in a TxPDO

Bit 8: object can be used for backup

Bit 9: object can be used for settings

Bit 10-15: reserved

 *)

                sName                    :               T_OdInfoMaxString;                                (* Sub Index object description string *)

//////////////////////////////////////////////////////////////////////////////


 

 

TYPE E_CoeSdoDataTypeCode :

(

(*             Don't move & define  randomly

                code define from ETG1000.6 table 64 , table 65  *)

                Reserved0 := 0,                       (* 0 : test like elements not exist , > 0 elements  exist  *)

                Type_BOOLEAN,

                Type_INTEGER8,

                Type_INTEGER16,

                Type_INTEGER32,

                Type_UNSIGNED8,

                Type_UNSIGNED16,

                Type_UNSIGNED32,

                Type_REAL32,

                Type_VISIBLE_STRING,

                Type_OCTET_STRING,

                Type_UNICODE_STRING,

                Type_TIME_OF_DAY,

                Type_TIME_DIFFERENCE,

                Reserved14,

                Type_DOMAIN,

                Type_INTEGER24,

                Type_REAL64,

                Type_INTEGER40,

                Type_INTEGER48,

                Type_INTEGER56,

                Type_INTEGER64,

                Type_UNSIGNED24,

                Reserved23,

                Type_UNSIGNED40,

                Type_UNSIGNED48,

                Type_UNSIGNED56,

                Type_UNSIGNED64,

                Reserved28,

                Type_GUID,

                Type_BYTE,

                Reserved31,

                Reserved32,

                Struct_PDO_MAPPING,

                Reserved34,

                Struct_IDENTITY,

                Reserved36,

                Struct_COMMAND_PAR,

                Reserved38,

                Reserved39,

                Reserved40,

                Struct_SYNC_PAR,

                Reserved42,

                Reserved43,

                Reserved44,

                Reserved45,

                Reserved46,

                Reserved47,

                Type_BIT1,

                Type_BIT2,

                Type_BIT3,

                Type_BIT4,

                Type_BIT5,

                Type_BIT6,

                Type_BIT7,

                Type_BIT8,

                Reserved56,

                Reserved57,

                Reserved58,

                Reserved59,

                Reserved60,

                Reserved61,

                Reserved62,

                Reserved63,

                Type_ManufacturerSpecificComplexData_0x40,

                Type_ManufacturerSpecificComplexData_0x41,

                Type_ManufacturerSpecificComplexData_0x42,

                Type_ManufacturerSpecificComplexData_0x43,

                Type_ManufacturerSpecificComplexData_0x44,

                Type_ManufacturerSpecificComplexData_0x45,

                Type_ManufacturerSpecificComplexData_0x46,

                Type_ManufacturerSpecificComplexData_0x47,

                Type_ManufacturerSpecificComplexData_0x48,

                Type_ManufacturerSpecificComplexData_0x49,

                Type_ManufacturerSpecificComplexData_0x4A,

                Type_ManufacturerSpecificComplexData_0x4B,

                Type_ManufacturerSpecificComplexData_0x4C,

                Type_ManufacturerSpecificComplexData_0x4D,

                Type_ManufacturerSpecificComplexData_0x4E,

                Type_ManufacturerSpecificComplexData_0x4F,

                Type_ManufacturerSpecificComplexData_0x50,

                Type_ManufacturerSpecificComplexData_0x51,

                Type_ManufacturerSpecificComplexData_0x52,

                Type_ManufacturerSpecificComplexData_0x53,

                Type_ManufacturerSpecificComplexData_0x54,

                Type_ManufacturerSpecificComplexData_0x55,

                Type_ManufacturerSpecificComplexData_0x56,

                Type_ManufacturerSpecificComplexData_0x57,

                Type_ManufacturerSpecificComplexData_0x58,

                Type_ManufacturerSpecificComplexData_0x59,

                Type_ManufacturerSpecificComplexData_0x5A,

                Type_ManufacturerSpecificComplexData_0x5B,

                Type_ManufacturerSpecificComplexData_0x5C,

                Type_ManufacturerSpecificComplexData_0x5D,

                Type_ManufacturerSpecificComplexData_0x5E,

                Type_ManufacturerSpecificComplexData_0x5F);

END_TYPE

 

(*

================== Basic Data Type Area ==================

0001        DEFTYPE BOOLEAN

0002        DEFTYPE INTEGER8

0003        DEFTYPE INTEGER16

0004        DEFTYPE INTEGER32

0005        DEFTYPE UNSIGNED8

0006        DEFTYPE UNSIGNED16

0007        DEFTYPE UNSIGNED32

0008        DEFTYPE REAL32

0009        DEFTYPE VISIBLE_STRING

000A        DEFTYPE OCTET_STRING

000B        DEFTYPE UNICODE_STRING

000C        DEFTYPE TIME_OF_DAY

000D       DEFTYPE TIME_DIFFERENCE

000E                        Reserved

000F        DEFTYPE DOMAIN

0010        DEFTYPE INTEGER24

0011        DEFTYPE REAL64

0012        DEFTYPE INTEGER40

0013        DEFTYPE INTEGER48

0014        DEFTYPE INTEGER56

0015        DEFTYPE INTEGER64

0016        DEFTYPE UNSIGNED24

0017                        Reserved

0018        DEFTYPE UNSIGNED40

0019        DEFTYPE UNSIGNED48

001A        DEFTYPE UNSIGNED56

001B        DEFTYPE UNSIGNED64

001C                        Reserved

001D       DEFTYPE GUID

001E        DEFTYPE BYTE

001F-002C                               Reserved

002D       DEFTYPE BitARR8

002E        DEFTYPE BITARR16

002F        DEFTYPE BITARR32

================== Extended Data Type Area ==================

0020                        Reserved

0021        DEFSTRUCT            PDO_MAPPING

0022                        Reserved

0023        DEFSTRUCT            IDENTITY

0024                        Reserved

0025        DEFSTRUCT            COMMAND_PAR

0026-0028                               Reserved

0029        DEFSTRUCT            SYNC_PAR

002A-002F                              Reserved

0030        DEFTYPE BIT1

0031        DEFTYPE BIT2

0032        DEFTYPE BIT3

0033        DEFTYPE BIT4

0034        DEFTYPE BIT5

0035        DEFTYPE BIT6

0036        DEFTYPE BIT7

0037        DEFTYPE BIT8

0038-003F                               Reserved

0040-005F               DEFSTRUCT            Manufacturer Specific Complex Data Types

0060-007F               DEFTYPE Device Profile 0 Specific Standard Data Types

0080-009F               DEFSTRUCT            Device Profile 0 Specific Complex Data Types

00A0-00BF              DEFTYPE Device Profile 1 Specific Standard Data Types

00C0-00DF              DEFSTRUCT            Device Profile 1 Specific Complex Data Types

00E0-00FF               DEFTYPE Device Profile 2 Specific Standard Data Types

0100-011F               DEFSTRUCT            Device Profile 2 Specific Complex Data Types

0120-013F               DEFTYPE Device Profile 3 Specific Standard Data Types

0140-015F               DEFSTRUCT            Device Profile 3 Specific Complex Data Types

0160-017F               DEFTYPE Device Profile 4 Specific Standard Data Types

0180-019F               DEFSTRUCT            Device Profile 4 Specific Complex Data Types

01A0-01BF              DEFTYPE Device Profile 5 Specific Standard Data Types

01C0-01DF              DEFSTRUCT            Device Profile 5 Specific Complex Data Types

01E0-01FF               DEFTYPE Device Profile 6 Specific Standard Data Types

0200-021F               DEFSTRUCT            Device Profile 6 Specific Complex Data Types

0220-023F               DEFTYPE Device Profile 7 Specific Standard Data Types

0240-025F               DEFSTRUCT            Device Profile 7 Specific Complex Data Types

0260-07FF                               Reserved

 

0x800 to 0xFFF.      The Enumerated Data Type Area

*)

 

 


 [後記]

 

在使用FB_EcCoeSdoService 讀取CoEList 的所遇到的問題紀錄,將推敲測試結果整理如下。

·         對於不存在的元素做Data read/write,可能會收到 0x703, 0x705,0x706 的回傳碼,在TwinCAT log 會顯示SDO Abort codes,可否直接取得Ads abort code 仍然未知.(Same as Emergency message)

2023 8/1 更新=========================

Ads abort code 可藉由 TcEtherCAT.lib FB_EcGetLastProtErrInfo 取得,如下圖



Further test



 

ADS CoE Write OD to a ReadOnly obj (WriteLen > Obj Len)

ADS return code 0x070D  ADSERR_DEVICE_SYNTAX   Syntax error in file or command.

FB_EcGetLastProtErrInfo 取得16#06070010

EC_COE_PROTERR_DATA_SIZE : UDINT := 16#06070010; (* Data type does not match, length of service parameter does not match *)

 

                        ADS CoE Write OD to a ReadOnly obj (WriteLen = Obj Len)

ADS return code 0x0704  ADSERR_DEVICE_INVALIDACCESS   Reading or writing not permitted.

FB_EcGetLastProtErrInfo 取得16#06010002

EC_COE_PROTERR_READONLY : UDINT := 16#06010002; (* Attempt to write a read only object. *)

 

 

但尚無法取得Emergency message (無異常碼,回傳值為零)

=====================================================

 

 

·         對於eNum 列舉型別的內容,不知道如何取得eNum 文字內容。

 

·         對於含subIndex Object , Sub內容在記憶體的offset不知道如何取得。(即無法使用 Complete Access Read/Write(Upload/Download))

 

·         Subindex 不一定是連續的,過程Subindex可能會中斷,但都是從小到大做排列。

 

·         承上,eGetObjectDescription 中所取得的nMaxSubIndex 代表的是最大的Sub IndexID,不一定就是Subindex數量,實際數量要從Object Entry[0].Data中取得。

 

·         Entry.Data 存取,需考慮  nObjectAccess之權限屬性。

 

·         Subindex 存在與否,可由下列方式判斷,

DataType <> 0

BitLen > 0

 

·         承上,即便Subindex 存在,測起來並不代表可以Access Entry[0].Data,有些場合nMaxSubIndex 數值是大的,Entry 屬性也都符合(DataType <> 0, &  BitLen > 0),但符合的元素可能會大於Entry[0].Data 的數值,在此條件下,最大僅能Access Entry[n].Data 此時 n = Entry[0].Data. 如下圖




[應用場景]

 

·         針對附CoE裝置從站,參數備份&復原功能 發展成為可能(Setting )

·         Bridge & Getway 裝置偵測對向的Config Data 成為可能。



 


留言

這個網誌中的熱門文章

[補充資料] EtherCAT Slave 定址 & Protocol 解析

Access TwinCAT EtherCAT CoE / SoE Object via ADS