jisotalo/ads-client

Proposal ReadSymbolInfo SumCommand

Closed this issue · 4 comments

Hi,

What about to have a sumComman to read multiple symbolInfo in one shot?

Something like:

`
const plcSymbolNames = ["Main.test_1", "Main.test_2"]
const totalVariableNamesLength = plcSymbolNames.reduce((total, target) => total + target.length + 1, 0)

  const data = Buffer.alloc(plcSymbolNames.length * 16 + totalVariableNamesLength)

  let pos = 0

  plcSymbolNames.forEach(target => {

    data.writeUInt32LE(61449, pos)      // SymbolInfoByName
    pos += 4

    //4..7 IndexOffset
    data.writeUInt32LE(0, pos)
    pos += 4

    //8..11 Read data length
    data.writeUInt32LE(658, pos)
    pos += 4

    //12..15 Write data length
    data.writeUInt32LE(target.length + 1, pos) //Note: String end delimeter
    pos += 4
  })

  //All write data
  plcSymbolNames.forEach(target => {
    //16..n Data
    iconv.encode(target, 'cp1252').copy(data, pos)
    pos += target.length + 1 //Note: string end delimeter
  })

  let res = await this.adsClient.readWriteRaw(
    61570,                                                      // ReadWrite
    plcSymbolNames.length,
    666 * plcSymbolNames.length,
    data
  )`

and use _parseSymbolInfo to decode the subcommnads

Hi!

I will check this in few days, but it could be doable.

One way would be to use readAndCacheSymbols() once in the beginning and the get the symbol info from local cache using getSymbolInfo().

I tried this but not all the PLC varaibles are retrived. Maybe I'm wrong, I will make other tests.

Hi!
I made some tests and in my case readAndCacheSymbols() get "specific informations" only for global variables.
If a PLC variables is declared inside a FB instantiated in a PRG, readAndCacheSymbols() does not ge "specific informations" on it, since it retrives information only of the PRG.
So if I use getSymbolInfo(), the info are requested to PLC and not to the cached symbols.
For this reason if yuo have a lot of "nested symbols", better to use a sumCommand in order to avoid the overflow of the Ads router mailbox.

I'm closing this for now but please open it if you have anything new or new ideas!