0.0.5 • Published 4 years ago

tp-rs232 v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

TpSeries

Library written in node.js for TOP Vending Machine tp products

Supported devices: TP1, TP11, TP2, TP3

Installation

Install from npm:

npm install tp-rs232
const TpSeries = require('tp-rs232');

let tp = new TpSeries({
  debug: true,
  timeout: 5000
});

Methods

All methods use Promise

  • tp.open('COM1') - Connect device
  • tp.close() - Disconnect device
  • tp.command('COMMAND_NAME') - Execute command and get answer
  • tp.enabled - Validator status
  • tp.openPort - Port status
  • tp.powerUp - Power Up (Bill Acceptor Active)

Command

tp.command('ENABLE')
.then(result => {
    console.log('status:', result.status)
    return;
})

tp.command('ACCEPT_BANKNOTE')

See all supported commands

Event

eSSP.on('READ_NOTE', result => {
    console.log(result)
})

See all supported events

Example

const TpSeries = require('tp-rs232');

let serialPortConfig = {
  baudrate: 9600,
  databits: 8,
  stopbits: 1,
  parity: 'even'
};

let tp = new TpSeries({
  debug: false,
  timeout: 5000
});

tp.on('OPEN', () => {
  console.log('Port opened!');
});

tp.on('CLOSE', () => {
  console.log('Port closed!');
});

tp.on('READ_NOTE', (result) => {
  console.log('READ_NOTE');
  console.log(result);

  if (result.channel === 2) {
    tp.command('REJECT_BANKNOTE');
  } else {
    tp.command('ACCEPT_BANKNOTE');
  }
});

tp.on('STACKING', (result) => {
  console.log(result);

  if (result.channel === 1) {
    tp.command('DISABLE').then((result) => {
      console.log(result);
      tp.close();
    });
  }

  if (result.channel === 3) {
    tp.removeAllListeners();
  }
});

tp.on('CLOSE', () => {
  console.log('CLOSE');
});
tp.on('POWER_UP', () => {
  console.log('POWER_UP');
});
tp.on('MOTOR_FAILURE', () => {
  console.log('MOTOR_FAILURE');
});
tp.on('CHECKSUM_ERROR', () => {
  console.log('CHECKSUM_ERROR');
});
tp.on('BILL_JAM', () => {
  console.log('BILL_JAM');
});
tp.on('BILL_REMOVE', () => {
  console.log('BILL_REMOVE');
});
tp.on('STACKER_OPEN', () => {
  console.log('STACKER_OPEN');
});
tp.on('SENSOR_PROBLEM', () => {
  console.log('SENSOR_PROBLEM');
});
tp.on('BILL_FISH', () => {
  console.log('BILL_FISH');
});
tp.on('STACKER_PROBLEM', () => {
  console.log('STACKER_PROBLEM');
});
tp.on('BILL_REJECT', () => {
  console.log('BILL_REJECT');
});
tp.on('INVALID_COMMAND', () => {
  console.log('INVALID_COMMAND');
});
tp.on('RESERVED', () => {
  console.log('RESERVED');
});
tp.on('RESPONSE_WHEN_ERROR', () => {
  console.log('RESPONSE_WHEN_ERROR');
});
tp.on('ENABLE', (result) => {
  console.log('ENABLE');
  console.log(result);
});
tp.on('DISABLE', (result) => {
  console.log('DISABLE');
  console.log(result);
});
tp.on('REJECT', () => {
  console.log('REJECT');
});
tp.on('COMMAND_NOT_FOUND', () => {
  console.log('COMMAND_NOT_FOUND');
});

tp.open('/dev/tty.usbserial-14330', serialPortConfig)
  .then(() => {
    console.log('GO!!!');

    tp.command('POWER_UP')
      .then(() => tp.command('ENABLE'))
      .then((result) => {
        console.log(result);
      });
  })
  .catch((error) => {
    console.log(error);
  });

Supported Commands:

Command nameInformation returnNeed promiseDescription
POWER_UPyesnoPower Up (Bill Acceptor Active)
ACCEPT_BANKNOTEyesnoCommand to accept a banknote
REJECT_BANKNOTEyesnoCommand to reject a banknote
HOLD_ESCROWyesnoHold in Escrow
STATUSyesyesReturns the current status of the device
ENABLEyesyesCommand to enable the banknote validator
DISABLEyesyesCommand to disable the banknote validator
RESETyesnoCommand to reset the device

Example commands with options:

POWER_UP
tp.command('POWER_UP').then((result) => console.log(result););
ACCEPT_BANKNOTE
tp.command('ACCEPT_BANKNOTE').then((result) => console.log(result););
REJECT_BANKNOTE
tp.command('REJECT_BANKNOTE').then((result) => console.log(result););
HOLD_ESCROW
tp.command('HOLD_ESCROW').then((result) => console.log(result););
RESET
tp.command('RESET').then((result) => console.log(result););
STATUS
tp.command('STATUS').then((result) => console.log(result););
ENABLE
tp.command('ENABLE').then((result) => console.log(result););
DISABLE
tp.command('DISABLE').then((result) => console.log(result););

Supported Events:

Event nameDescription
OPENEvent that detects that the device was opened successfully
CLOSEEvent that detects that the device was closed
POWER_UPPower Up (Bill Acceptor Active).
MOTOR_FAILUREAn motor fault was found.
CHECKSUM_ERRORChecksum error.
BILL_JAMThe device has detected that coins are jammed in its mechanism and cannot be removed other than by manual intervention. The value paid at the jam point is given in the event data.
BILL_REMOVEReported when a note float unit has been detected as removed from its validator.
STACKER_OPENThe device has detected that the stacked has been opened.
SENSOR_PROBLEMThe device has encountered a problem with the sensor.
BILL_FISHBILL FISH
STACKER_PROBLEMThe device has encountered a stacker problem.
BILL_REJECTThe note has been rejected from the validator and is available for the user to retrieve.
INVALID_COMMANDInvalid command encountered.
RESERVEDReserved
RESPONSE_WHEN_ERRORResponse when Error
ENABLEThe device is enabled.
DISABLEThe device is disabled.
READ_NOTEA note has been detected by the device.
STACKINGA note has been stacked.
REJECTA note has been rejected.
COMMAND_NOT_FOUNDThe command was not found.

Errors and contributions

For an error write the problem directly on github issues or submit it to the mail miguel@lomeli.io. If you want to contribute to the project please send an email.

#TP1 , #TP11 , #TP2 , #TP3 , #TOP Vending Machine

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago