Skip to content

Sequence Break after Alarm Subscription #4

@tloftis

Description

@tloftis

After subscribing to the alarm event (MID 70) if another call is made without waiting there will be an out of sequence error that will happen.

This is done using 1.0.3 of this library, with the PF4000 Torque tool, the tool is running open protocol version 2.5, controller software version 10.17.12.SR1.

This code will generate an error after calling the line "await op.subscribe('alarm');", during the "await op.subscribe('psetSelected');" function, the code will end with the error "close Result received! Error: [LinkLayer] sequence number invalid, MID[4]". If "await op.subscribe('alarm');" is not called, the code works properly.

'use strict';

// Create a socket
const openProtocol = require('node-open-protocol');

let options = {
    linkLayerActivate: undefined,
    genericMode: false,
    keepAlive: 1000,
    rawData: false,
    timeOut: 3000,
    retryTimes: 3,
    disableMidParsing: {}
};

let createClient = async function (port, ip, opt) {
  let run = false; //Run Once Var
  return new Promise ((resolve, reject) => {
      let op = openProtocol.createClient(port, ip, opt, () => {
          if (run) return;
          run = true;
          resolve(op);
      });
      op.on('error', () => {  });
      op.on('close', err => {
          if (!run) {
              run = true;
              return reject(err);
          }
      });
  })
};

async function onClientConnected(port, ip, opt) {
    let op = await createClient(port, ip, opt);
    op.on('close', (stat) => {
        console.log(`close Result received!`, stat);
    });
    await op.subscribe('lastTightening');
    await op.subscribe('alarm');
    await op.subscribe('psetSelected');
    await op.command('disableTool');
    return op.close();
}

onClientConnected(4545, '10.1.203.133', options).catch( err => {
  console.log('Error happened', err);
}).then(() =>{
  console.log('Running');
},err =>{
    console.log('Failed!', err);
});

This is the same code, but with a slight delay using 'setTimeoutAsync' between the alarm subscription and a call to subscribe to pset events, this code works properly with our tool and will receive alarm events.

'use strict';

// Create a socket
const openProtocol = require('node-open-protocol');

let options = {
    linkLayerActivate: undefined,
    genericMode: false,
    keepAlive: 1000,
    rawData: false,
    timeOut: 3000,
    retryTimes: 3,
    disableMidParsing: {}
};

let createClient = async function (port, ip, opt) {
  let run = false; //Run Once Var
  return new Promise ((resolve, reject) => {
      let op = openProtocol.createClient(port, ip, opt, () => {
          if (run) return;
          run = true;
          resolve(op);
      });
      op.on('error', () => {  });
      op.on('close', err => {
          if (!run) {
              run = true;
              return reject(err);
          }
      });
  })
};

let setTimeoutAsync = t => new Promise(res=>setTimeout(res, t));

async function onClientConnected(port, ip, opt) {
    let op = await createClient(port, ip, opt);
    op.on('close', (stat) => {
        console.log(`close Result received!`, stat);
    });
    await op.subscribe('lastTightening');
    await op.subscribe('alarm');
    await setTimeoutAsync(500); //Delay 500 milliseconds
    await op.subscribe('psetSelected');
    await op.command('disableTool');
    return op.close();
}

onClientConnected(4545, '10.1.203.133', options).catch( err => {
  console.log('Error happened', err);
}).then(() =>{
  console.log('Running');
},err =>{
    console.log('Failed!', err);
});

I've capture all the messages sent between the two examples and provide them below

These are the messages sent using the code that generates errors. It should be noted that it is on sequence number 4 that causes the error

Data Out:	00200001006001010000 
Data In:	01790002006     0500010000020003                         04ACT052.5                0610.17.12.SR1       077.16.45            08Silver (Ag)             09D857104   1000111001121130 
Data Out:	00200060007001010100 
Data In:	00249997        02000060 
Data In:	00260004        0100006097 
Data Out:	002499970010010102000004 
Data Out:	00200060006001010200 
Data In:	00249997        03000060 
Data In:	00240005        02000060 
Data Out:	002499970010010103000005 
Data Out:	00200070002001010300 
Data In:	00249997        04000070 
Data In:	00240005        03000070 
Data Out:	002499970010010104000005 
Data Out:	00200014002001010400 
Data In:	00560076        040001002E544031041052018-10-01:15:16:12 
Data Out:	002499970010010105000076 
Data In:	00249997        05000014 
Data In:	00260004        0400001497 
Data Out:	0028999800100101050000040003 
close Result received! Error: [LinkLayer] sequence number invalid, MID[4]
    at LinkLayer._onDataOpParser (/home/timothy/Git/driver-node-torque-tool/node_modules/node-open-protocol/src/linkLayer.js:279:48)
    at OpenProtocolParser.LinkLayer.opParser.on (/home/timothy/Git/driver-node-torque-tool/node_modules/node-open-protocol/src/linkLayer.js:105:49)
    at emitOne (events.js:116:13)
    at OpenProtocolParser.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at OpenProtocolParser.Readable.push (_stream_readable.js:208:10)
    at OpenProtocolParser.Transform.push (_stream_transform.js:147:32)
    at OpenProtocolParser._transform (/home/timothy/Git/driver-node-torque-tool/node_modules/node-open-protocol/src/openProtocolParser.js:245:18)

These are all messages sent in the code that works using the Delay.

Data Out:	00200001006001010000 
Data In:	01790002006     0800010000020003                         04ACT052.5                0610.17.12.SR1       077.16.45            08Silver (Ag)             09D857104   1000111001121130 
Data Out:	00200060007001010100 
Data In:	00249997        02000060 
Data In:	00260004        0100006097 
Data Out:	002499970010010102000004 
Data Out:	00200060006001010200 
Data In:	00249997        03000060 
Data In:	00240005        02000060 
Data Out:	002499970010010103000005 
Data Out:	00200070002001010300 
Data In:	00249997        04000070 
Data In:	00240005        03000070 
Data Out:	002499970010010104000005 
Data In:	00560076        040001002E544031041052018-10-01:15:16:12 
Data Out:	002499970010010105000076 
Data Out:	00200014002001010400 
Data In:	00249997        05000014 
Data In:	00260004        0500001497 
Data Out:	002499970010010106000004 
Data Out:	00200014001001010500 
Data In:	00249997        06000014 
Data In:	00240005        06000014 
Data Out:	002499970010010107000005 
Data Out:	00200042001001010600 
Data In:	00420015        07000012018-09-25:17:32:15 
Data Out:	002499970010010108000015 
Data In:	00249997        07000042 
Data In:	00240005        08000042 
Data Out:	002499970010010109000005 
close Result received! undefined
Running

I spent some time debugging this issue but had to move on. This also seems to have issue with RC Focus tools, but I only had very temporary access to that device and can no longer test against it.
I have gotten around the issue on both devices by just not subscribing to alarms.

If you want more information/clarification or for me to test any fixes, just let me know

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions