2

I'm trying to access data from a PLC input variable through an ADS Client using the variable's IndexGroup and IndexOffset. I used the SymbolLoaderFactory to get access to the symbol. With the symbol, I can use an ADS client to read it's data. But, I would like to read it's data through it's IndexGroup and IndexOffset. When I use the symbol's IndexGroup and IndexOffset, I cannot get the expected data. The IndexGroup and IndexOffset (and port) do not match what I see for the variable in TwinCAT. Why do they not match? How can I get the correct IndexGroup and IndexOffset so I can read the data correctly?

Additional Details: I created a PLC variable called MAIN.Input1. The ADS Info defined in TwinCAT is Port: 350, IGrp: 0x8502000, IOffs: 0x8005DFEA, Len: 1

Using the SymbolLoaderFactory (with client on port 851), the MAIN.Input1 symbol says it has an IndexGroup and IndexOffset of IGrp: 0x0000F020, IOffs: 0x0005DFEA

Vic
  • 55
  • 7
  • I'm not sure why it is not working, but likely because you have the wrong IndexGroup and IndexOffset. As you can read in the [docs](https://infosys.beckhoff.com/english.php?content=../content/1033/tcadsnetref/7312582795.html&id=) there are some things you need to take into account when using the index. Why don't you want to use the SymbolLoader? From what I read that seems like a much more fail safe approach. – Roald Jun 04 '21 at 08:37
  • @Roald, I'm getting the IndexGroup and IndexOffset from the symbol using the SymbolLoader. They just don't match what is shown for the ADS Info in TwinCAT (I left more details on the values I found in the post). I plan to read and write a lot of variables using the client. Each read is about 5-10ms, so using the symbols directly to write a lot of symbols would take too long. – Vic Jun 04 '21 at 16:35
  • I was confusing it with the [`ReadAny`](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsnetref/7313469579.html&id=) method. Have you tried that one? No need for indices. Or the [`ReadSymbol`](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsnetref/7313469579.html&id=) one. – Roald Jun 04 '21 at 16:52
  • I have looked at those methods and they do return the correct values. The issue is that using ReadAny with handles or using symbols to read data is too slow when trying to read multiple values; using index groups and offsets can be faster for multiple objects. For example, when I want to get all of the data for physical inputs, I read the 0xF020 group and grab all of the bytes in the image. That one read is 5ms and summarizes 120 physical input devices. I'm hoping to accomplish something similar for PLC variables. – Vic Jun 04 '21 at 20:23
  • 1
    "what I see for the variable in TwinCAT" Where do you see this in TwinCAT? With code below I can do what you want; dynamic counter_var = dynamicSymbols.MAIN.counter; dynamic counter_group = counter_var.IndexGroup; dynamic counter_offset = counter_var.IndexOffset; dynamic counter_value = dynamicSymbols.MAIN.counter.ReadValue(); UInt64 valueToRead = (UInt64)client.ReadAny(counter_group, counter_offset, typeof(uint)); – owillebo Jun 07 '21 at 13:13
  • 1
    @owillebo, what you posted works. And it made me realize what the issue is. When I use groups and offsets for physical devices, I'll switch the group to the Input group, e.g. 0xF021 to 0xF020, and divide the offset by 8 to get the correct byte to grab. I assumed, at least for the offset, you had to divide by 8 to grab the appropriate byte for PLC variables, which is why I couldn't grab the correct data. Do you know why physical devices have different values for groups and offsets? – Vic Jun 07 '21 at 22:04

0 Answers0