How to use the serialport/test.Binding function in serialport

To help you get started, we’ve selected a few serialport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serialport / node-serialport / packages / serialport / examples / mocking.js View on Github external
/* eslint-disable node/no-missing-require */

// Load Serialport with mock bindings
// const SerialPort = require('../test'); // from inside the serialport repo
const SerialPort = require('serialport/test') // when installed as a package
const MockBinding = SerialPort.Binding

const portPath = 'COM_ANYTHING'

// The mock bindings can pretend to be an arduino with the `arduinoEcho` program loaded.
// This will echo any byte written to the port and will emit "READY" data after opening.
// You enable this by passing `echo: true`

// Another additional option is `record`, if `record: true` is present all
// writes will be recorded into a single buffer for the lifetime of the port
// it can be read from `port.binding.recording`.

// Create a port
MockBinding.createPort(portPath, { echo: false, record: false })

const port = new SerialPort(portPath)
port.on('open', () => {
github automategreen / home-controller / test / Insteon-serial.js View on Github external
'use strict';

var Insteon = require('../').Insteon;
var should = require('should');

var SerialPort = require('serialport/test');
var MockBinding = SerialPort.Binding;
MockBinding.createPort('/dev/home-controller-mock', { echo: false, record: true, readyData: '' });

var mockSerial = require('../lib/Test/mockSerial');
var Plan = require('../lib/Test/Plan');

describe('Insteon Gateway (Serial Interface)', function () {
  this.timeout(5000);

  it('tests serial connection #1', function (done) {
    var gw = new Insteon();
    gw.SerialPort = SerialPort;

    gw.serial('/dev/home-controller-mock', {}, function () {
      gw.close();
      gw.serial('/dev/home-controller-mock', { baudRate: 19200, dataBits: 8, parity: 'none', stopBits: 1 }, function () {
        gw.close();

serialport

Node.js package to access serial ports. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!

MIT
Latest version published 11 months ago

Package Health Score

88 / 100
Full package analysis