Skip to content

Fetch Ethercat Master Device Data in TwinCAT Solutions

License

Notifications You must be signed in to change notification settings

seehma/DeviceInfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Read Ethercat-Master Device names

This small library acts as a sample project to show how to read Ethercat-Master names in TwinCAT.

Dependencies

It references ZCore library from Zeugwerk Framework. This can be easily installed via Twinpack library Package Manager.

Usage

  • instantiate GetDeviceData function block
  • call Cyclic() method on every PLC cycle
  • start reading by calling method DeviceNamesAsync('');, leave AmsNetId empty to read from a local PLC
  • Fetch result from VAR_INPUT arrays of the object

deviceinfo

Example

PROGRAM MAIN
VAR
  _deviceInfo : DeviceInfo.DeviceInfo;
  _slaveInfo : DeviceInfo.SlaveInfo;
  _step : ZCore.Step(0, 50);
  _start : BOOL;
  _ecatMasterCount : UINT;
  _ecatName : ZCore.ZString;
  _ecatAmsNetId : Tc2_System.T_AmsNetID;
END_VAR
----------------------------------
_deviceInfo.Cyclic();
_slaveInfo.Cyclic();

CASE _step.Index OF
  0:
    IF _start 
    THEN 
      _start := FALSE;
      _step.SetNext(10);
    END_IF
    
  10:
    IF _step.OnEntry()
    THEN
      _deviceInfo.ReadDeviceNamesAsync('');
    END_IF

    IF _deviceInfo.Done 
    THEN
      _ecatMasterCount := _deviceInfo.EthercatMasterCount;
      _ecatName := _deviceInfo.NameArray[0];
      _ecatAmsNetId := _deviceInfo.NetIdArray[0];
      _step.SetNext(20);
    END_IF  
    
  20:
    IF _step.OnEntry()
    THEN
      _slaveInfo.ReadSlaveNamesAsync('', _deviceInfo.DeviceIdArray[0]);
    END_IF
    
    IF _slaveInfo.Done
    THEN
      _step.SetNext(0);
    END_IF
    
END_CASE

About

Fetch Ethercat Master Device Data in TwinCAT Solutions

Resources

License

Stars

Watchers

Forks

Packages

No packages published