-1

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

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
XTT
  • 177
  • 1
  • 3
  • 13
  • Its very specific to the device. TwinCAT was Beckhoffs attempt at an EtherCAT (realtime ethernet programmable logic controller) and is based on a dual-OS (a realtime one running side-by-side with Windows Embedded). TwinCAT exposed an API that allows you to read/write to memory directly since this is much faster than going through an API that uses named addresses and allows the type of packet transport they use (it accepts a packet, adds data to it, and forwards it on). What device are you talking about? – Ron Beyer Aug 14 '15 at 16:10
  • I'm trying to access an EtherCAt junction box. – XTT Aug 14 '15 at 18:42
  • @Chris It is actually a prototype the company I'm working for is developing. I am testing this prototype to see if I'm getting the values I'm expecting in the memory. – XTT Aug 14 '15 at 21:50
  • @XTT Ah, I see, interesting! Since the system manager can do it, you should be able to too. Perhaps you could use the ADS debugger (http://infosys.beckhoff.com/english.php?content=../content/1033/tcadsamsspec/html/tcadsamsspec_tcadsamsdebugger.htm&id=) to find out what and how it accesses the memory of the slave. – Chris Aug 14 '15 at 22:16

1 Answers1

1

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.

Chris
  • 5,442
  • 17
  • 30