TwinCAT3 automation script(C#) for I/O scan devices

1k views Asked by At

I want to implement TwinCAT3 automation script(C#) for scanning I/O devices. I want to scan CANOpen devices which are connected to TwinCAT3 coupler and select from the appropriate CANOpen device from GUI.

I did not find any information about scanning I/O devices from Beckhoff documentation. I just found some information for scanning the CANOpen devices from Beckhoff documentation. But, It is not well documented.

ITcSmTreeItem5 can_master = (ITcSmTreeItem5)io.CreateChild("Device 2 (EL6751)", 87, "", null);  

String availableMaster = can_master .ResourceCount;

can_master.ClaimResources(1);

They did not specify where can we save scanned devices. They just simply activating the device with index.

Please suggest me, How can I scan CANopen devices and save the available devices through automation C# scripting?

2

There are 2 answers

0
Seth On

You are correct in observing that the Beckhoff Automation Interface leaves something to be desired :D

The documentation suggests importing a CAN Database (.dbc) file to configure the CAN-BUS. If the bus will always have the same configuration, this is the easier way to go. You can export a DBC from the TwinCAT GUI.

If you need to scan the bus, what you might be able to do is consume an XML string with <ScanBoxes>true</ScanBoxes>. An example of this is shown in the documentation at 4.3.5.7 Scanning for devices and boxes. That might look something like:

string xml = "<TreeItem><DeviceDef><ScanBoxes>1</ScanBoxes></DeviceDef></TreeItem>"; 
can_slave.ProduceXml(xml);

You could then browse the IO tree to see what devices were discovered.

ITcSmTreeItem ioDevices = systemManager.LookupTreeItem("TIID");
string foundDevices = ioDevices.ProduceXml();
0
SeungYeop Oh On

I also get this problem. And I found the solution.

refer to: https://infosys.beckhoff.com/index.php?content=../content/1031/tcautomationinterface/html/TcSysMan_HowTo_Scan.htm&id=

From above URL, You need the instance of inferface named "systemManager". You can get systemManager instance from the url. (https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_automationinterface/45035996516426763.html&id=)

From above URL, you should create or open Visual-Studio by EnvDTE.DTE. And get systemManager instance from the DTE.