TJForc / risco-lan-bridge

risco-lan-bridge is a "bridge" between a node.js application and a Risco Panel
Other
21 stars 12 forks source link

undefined response on LightSys with multisocket card #3

Closed Lukino2000 closed 2 years ago

Lukino2000 commented 2 years ago

Hi,

I'm trying using "risco-lan-bridge" on LightSys with multisocket card but it gives me this "undefined error"

index.mjs content:

import RiscoTCPPanel from 'risco-lan-bridge'

let Options = {
    Panel_IP: '192.168.10.115',
    Panel_Port: 1000
};

let RPanel  = new RiscoTCPPanel.LightSys(Options);

let GetPartitionState = (() => {
    if ((RPanel.Partitions.ById(1)).Arm) {
        console.log('Partition is Armed State');
    } else {
        console.log('Partition is Disarmed State');
    }
});

GetPartitionState();

error message:

> node .\index.mjs
Local GMT Timezone is : +01:00
Start Connection to Panel
TCP Socket is not already created, Create It
Pseudo Buffer Created for Panel Id(0001):
[2,5,11,23,47,94,189,122,244,232,208,161,66,133,11,22,45,90,181,107,214,173,90,180,104,208,161,67,135,15,31,63,126,253,251,247,239,223,191,127,255,255,254,252,249,242,229,202,149,43,86,172,88,176,96,193,131,6,12,25,50,100,200,144,32,65,130,5,11,23,47,95,190,125,250,245,234,213,170,85,170,84,168,81,162,68,136,17,35,70,140,24,49,98,197,138,21,42,85,171,87,175,94,188,121,243,230,204,152,49,98,197,138,21,43,86,172,88,177,99,198,141,27,54,109,218,180,105,210,165,74,149,42,85,171,86,173,90,181,106,212,168,80,160,64,129,2,4,9,19,39,78,157,58,117,234,213,170,85,170,85,171,87,175,95,190,124,248,240,225,195,135,15,30,60,120,240,224,193,131,6,12,25,51,102,205,154,53,107,215,175,94,189,122,245,235,215,175,95,190,125,251,246,236,216,176,96,192,129,2,4,8,17,34,68,137,19,39,78,156,56,113,227,199,143,30,61,122,245,234,213,171,86,172,89,179,102,205,154,53,107,215,174,92,185,115,231,207,158,61,123,247,239,223,191]
TCP Socket must be connected now
Process Exit, Disconnecting
Disconnecting from Panel.
Sending Command : DCN
Command CRC Value : A5E8
Command Sent.
Sequence : 1 - Data Sent : DCN
SendCommand receive this response : undefined
file:///D:/Temp/testRiscoLanBridge/index.mjs:11
    if ((RPanel.Partitions.ById(1)).Arm) {
                           ^

TypeError: Cannot read property 'ById' of undefined
    at GetPartitionState (file:///D:/Temp/testRiscoLanBridge/index.mjs:11:28)
    at file:///D:/Temp/testRiscoLanBridge/index.mjs:18:1
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
    at async handleMainPromise (node:internal/modules/run_main:63:12)
TJForc commented 2 years ago

That's what I thought.

Your implementation is incorrect, but not much is missing.

When you instantiate your RPanel object, all of its devices are undefined until the connection is established and the configuration is retrieved.

Once this step is completed, your RPanel object will emit a 'SystemInitComplete' event to inform that the object is ready to operate.

So you have to define and call your 'GetPartitionState' function within this event:

RPanel.on('SystemInitComplete', () => {
    let GetPartitionState = (() => {
        if ((RPanel.Partitions.ById(1)).Arm) {
            console.log('Partition is Armed State');
        } else {
            console.log('Partition is Disarmed State');
        }
    });

    GetPartitionState();
});

For a LighSys with 50 zones, it takes about a minute to connect and read the configuration.

Lukino2000 commented 2 years ago

Hi @TJForc , you're right! now it works correctly, thanks