package eni // import "github.com/anviod/EtherCAT/eni" Package eni provides parsing of EtherCAT ESI (EtherCAT Slave Information) XML files. 包 eni 提供 EtherCAT ESI(EtherCAT 从站信息)XML 文件解析功能。 ESI files describe the configuration, PDO mapping, and sync manager setup for EtherCAT slave devices. This parser reads the standard EtherCATInfo XML schema defined in ETG.2000. ESI 文件描述了 EtherCAT 从站设备的配置、PDO 映射和同步管理器设置。 本解析器读取 ETG.2000 定义的标准 EtherCATInfo XML 模式。 # Usage info, err := eni.ReadEtherCATInfoFromFile("slave.xml") if err != nil { panic(err) } fmt.Printf("Vendor: %s\n", info.Vendor.Name) TYPES type Descriptions struct { Groups []Group `xml:"Groups>Group"` Devices []Device `xml:"Devices>Device"` } Descriptions holds groups and devices defined in the ESI file. type Device struct { Type DeviceType `xml:"Type"` Names []LcIdentifiedName `xml:"Name"` Sms []Sm `xml:"Sm"` Eeprom Eeprom `xml:"Eeprom"` } Device represents an EtherCAT slave device definition. type DeviceType struct { Name string `xml:",chardata"` ProductCodeRaw string `xml:"ProductCode,attr"` RevisionNoRaw string `xml:"RevisionNo,attr"` } DeviceType holds the device type name and its product/revision codes. func (dt DeviceType) ProductCode() uint32 ProductCode parses the hexadecimal ProductCode (with optional #x prefix) and returns it as uint32. func (dt DeviceType) RevisionNo() uint32 RevisionNo parses the hexadecimal RevisionNo (with optional #x prefix) and returns it as uint32. type Eeprom struct { ByteSize uint `xml:"ByteSize,attr"` ConfigDataRaw string `xml:"ConfigData,attr"` } Eeprom holds the EEPROM configuration data for a device. type EtherCATInfo struct { Vendor Vendor `xml:"Vendor"` Descriptions Descriptions `xml:"Descriptions"` } EtherCATInfo is the root element of an ESI XML file. func ReadEtherCATInfo(r io.Reader) (EtherCATInfo, error) ReadEtherCATInfo reads and parses ESI XML data from an io.Reader. func ReadEtherCATInfoFromFile(filename string) (EtherCATInfo, error) ReadEtherCATInfoFromFile reads and parses an ESI XML file from the given filename. type Group struct { Type string `xml:"Type"` Names []GroupName `xml:"GroupName"` } Group represents a logical grouping of devices. type GroupName struct { LcIdentifiedName } GroupName is a localized name for a group. type LcIdentifiedName struct { String string `xml:",chardata"` LcId uint `xml:"LcId,attr"` } LcIdentifiedName is a string with a language code identifier. type Sm struct { Name string `xml:",chardata"` MinSize uint `xml:"MinSize,attr"` MaxSize uint `xml:"MaxSize,attr"` DefaultSize uint `xml:"DefaultSize,attr"` StartAddressRaw string `xml:"StartAddress,attr"` ControlByteRaw string `xml:"ControlByte,attr"` } Sm represents a Sync Manager configuration. func (s Sm) ControlByte() uint8 ControlByte parses the hexadecimal ControlByte and returns it as uint8. func (s Sm) StartAddress() uint16 StartAddress parses the hexadecimal StartAddress and returns it as uint16. type Vendor struct { Id uint32 `xml:"Id"` Name string `xml:"Name"` } Vendor contains vendor identification information.