How to read the memory in a device using C# through TwinCAT?

2.7k views Asked by At

It is possible for me to access the memory of a device and read/write to it using C#? I know it is possible using TwinCAT. Is there a function in the library where I could access the memory through TwinCAT?

This is how I access the memory through TwinCAT

1

There are 1 answers

3
Chris On

Absolutely, there's a C# library called TwinCAT.Ads.dll that accesses almost any device via ADS. How you communicate depends a great deal on what kind of device you're accessing. Each device usually has documentation that tells you what ports, indices and subindices you need to deal with.

Example:

var ads = new TcAdsClient();                  
ads.Connect( "10.0.0.155.1.1", 800 );
ads.WriteAny( 0xF020, 0x1, (byte)0xC );

That code connects to a BC9050 PLC with AMSNetId 10.0.0.155.1.1 over the network and writes one byte with the value 0xC to the memory of runtime #1 at %IX1.*.

If you need high performance access to a task's memory of a local TwinCAT installation, there's also a library called R3IO that gives you very fast direct memory access. It only exists in Twincat 2, though.

Edit: Seems that you want to read slave memory directly (which isn't usually done). Since the System Manager can do it, I would assume you should be able to too. Using their unsupported ADS debugger you should be able to find out what ADS commands it issues to access the memory.

I would also think that, if you're using their ASICs, that the documentation for those might have more information regarding this.

When you have that information, writing up a C# program to read this should be pretty straight forward.