Giter Club home page Giter Club logo

Comments (15)

PLCHome avatar PLCHome commented on August 20, 2024 1

Global symname must start with a dot: .engine, program symname must start with the programname: MAIN.UpTyp.timerUp.PT.

There is also a problem with special characters, because node-ads pass the texts as UTF8 to the PLC and not as ASCII. Do you want to tell us the symname name?

You can use getSymbols to trace the known names.

client = ads.connect(options, function() {
    this.getSymbols(function(err, symbols) {
        if (err) console.log(err)
        console.log(symbols)
        this.end()
    })
})

        client.end(function (){ resolve() })
        resolve()

better you remove the second resolve() ;-)

from node-ads.

PLCHome avatar PLCHome commented on August 20, 2024 1

So you mean the old value of synhandle is persisting through the multiple calls?

yes that's javascript

from node-ads.

acidos avatar acidos commented on August 20, 2024

This is the failing handle

var validityHandle = {
    symname: 'MAIN.PKG.bEnable',
    bytelength: ads.BOOL,  
    propname: 'value',
    value: true
}

The successful ones are MAIN.PKG.BLA_BLA matching exactly to the ones declared in PLC. The type of others are mixed, including float, bool, though I don't think it's related. As I stated, the error "symbol not found" happens occasionally, but with some pattern. If I just start my node app, first(or first few) times everything is successful. The program is running on setInterval of 5 minutes. On consequent timer events, the exception occurs.

from node-ads.

acidos avatar acidos commented on August 20, 2024

better you remove the second resolve() ;-)

ah, dankeschön :)

from node-ads.

acidos avatar acidos commented on August 20, 2024

So what I tried is moved then(() => WriteAds(client, validityHandle)). to the top, to see if the failure is related to the last Write, but it failed again on exactly this handle. If something wrong with the name of the handle, why it's writing successfully always very first time?

from node-ads.

PLCHome avatar PLCHome commented on August 20, 2024

I think the second resolve() is not the problem here.

I am puzzled about:

The last one only received ADSIGRP_SYM_VALBYHND without prior ADSIGRP_SYM_HNDBYNAME.

node-ads has a peculiarity, it writes all information into the transferred object validityHandle. ADSIGRP_SYM_HNDBYNAME is not called when a handle is handed over. But then the symname is forbidden.
I am confused

from node-ads.

acidos avatar acidos commented on August 20, 2024

So I have bunch of ADSIGRP_SYM_HNDBYNAME calls like below for all handles in values array:

image

Then all of the sudden I see ADSIGRP_SYM_VALBYHND to read the value for bEnable I guess, not sure where it got index/offset:
image

Then an error:
image

Tomorrow I'm going to do getSymbols, to see if the index/offset is matching. Second, I'm going to capture the first successful operation and compare.

from node-ads.

acidos avatar acidos commented on August 20, 2024

I did a quick capture of successful call and I see ADSIGRP_SYM_HNDBYNAME

image

from node-ads.

PLCHome avatar PLCHome commented on August 20, 2024

this is a part of var getHandle = function

    if (typeof handle.symhandle === 'undefined') {
      var commandOptions = {
        indexGroup: ADSIGRP.GET_SYMHANDLE_BYNAME,
        indexOffset: 0x00000000,
        writeBuffer: buf,
        readLength: 4,
        symname: handle.symname
      }

      writeReadCommand.call(ads, commandOptions, function (err, result) {
      .....
}

plase try only for a test:

function WriteAds(client, h)
{
    return new Promise(function(resolve, reject){
        client.write(h, function(err) {
           delete(h.symhandle)
           if (err) 
            {
                reject(err)
            }
            else
            {
                resolve()
            }
        })
    })
}

or use a clean object:

function WriteAds(client, h)
{
    return new Promise(function(resolve, reject){
        var newH = Object.assign({},h)
        client.write(newH, function(err) {
           if (err) 
            {
                reject(err)
            }
            else
            {
                resolve()
            }
        })
    })
}

because client.end releases all symhandle you got in the session

var end = function (cb) {
 ...
  releaseSymHandles.call(ads, function () {
   ...

Did you slove the connection problem on the localhost?

from node-ads.

acidos avatar acidos commented on August 20, 2024

So you mean the old value of symhandle is persisting through the multiple calls? Can be true, because only that object is static and I never reset it. I'll try it tomorrow morning, off to bed now. Thanks!

from node-ads.

PLCHome avatar PLCHome commented on August 20, 2024

If I look at the code, it looks like you would pick up a value via http-get and send it to the PLC.
Ever thought about NODE-RED?

Timer Node -> HTTP Request Node -> ADS Write Node

from node-ads.

acidos avatar acidos commented on August 20, 2024

Did you slove the connection problem on the localhost?

I'll update previous topic in a moment

from node-ads.

acidos avatar acidos commented on August 20, 2024

If I look at the code, it looks like you would pick up a value via http-get and send it to the PLC.
Ever thought about NODE-RED?

Timer Node -> HTTP Request Node -> ADS Write Node

My web request is pretty complex and requires login, cookies, cheerio, header case normalization to extract data. The function is already there(around 200 lines of code) and I'm not sure if I can easily do it with HTTP Request Node.

Also for ADS I need to write float values, extracted from the web, then at the end put validity flag, before invalidation timer expires in PLC. Not sure if this can be achieved in NR as flexible as I do it in single js file.

Currently I installed it as windows service, using node-windows and it's running smoothly. Thanks to you, the problem with symbol not found solved (though I think lib should not keep the state in user object).

With that said, I love NR and always looking for opportunities to use it. But for this task it feels like shooting bird with canon.

from node-ads.

PLCHome avatar PLCHome commented on August 20, 2024

Thanks to you, the problem with symbol not found solved

Added note in the readme.md
@roccomuso please close

from node-ads.

roccomuso avatar roccomuso commented on August 20, 2024

ok thanks!

from node-ads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.