npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apoxusbcan

v0.2.1

Published

Apox Controls USB-CAN module driver

Downloads

13

Readme

node-apoxusbcan

A node.js module for Apox Controls USB-CAN devices. Most important features of this device are supported (e.g. switching to main code, and ability to send/receive CAN Bus messages).

This project has been developed with node-xanbus in mind. However, it would probably be useful for something else, hence the reason I'm releasing this module independently.

build status

Installation

From npm:

$ npm install apoxcanusb

From source:

$ git clone https://github.com/legege/node-apoxusbcan.git
$ cd node-apoxusbcan
$ npm install

Example

To receive CAN Bus messages:

var usbcan = new ApoxUsbCan();

usbcan.on('canbusmessage', function(timestamp, rtr, id, extended, flags, data) {
  console.log('CANBus message: timestamp =', timestamp, 'rtr =', rtr, 'id =', id, 'extended =', extended, 'flags =', flags, 'data =', data);
});

usbcan.open();

usbcan.switchToMainCode(function(err) {
  if (err) {
    console.log('Failed to switch to main code:', err);
    return;
  }
});

API

ApoxUsbCan

var usbcan = new ApoxUsbCan();

usbcan.open()

usbcan.open();
  • ignored if usbcan is already opened

usbcan.close()

usbcan.close();
  • ignored if usbcan is not opened or already closed

usbcan.reset(callback)

usbcan.reset(function(err) {
  if (err) {
    console.log('Failed to reset:', err);
    return;
  }
});
  • usbcan must be opened

usbcan.isMainCodeRunning(callback)

usbcan.isMainCodeRunning(function(err) {
  if (err) {
    console.log('Failed to determine if main code is running:', err);
    return;
  }
});
  • usbcan must be opened

usbcan.switchToMainCode(callback)

usbcan.switchToMainCode(function(err, mainCodeRunning) {
  if (err) {
    console.log('Failed to switch to main code:', err);
    return;
  }
  console.log('Is main code running?', mainCodeRunning);
});
  • usbcan must be opened

usbcan.getHardwareVersion(callback)

usbcan.getHardwareVersion(function(err, version) {
  if (err) {
    console.log('Failed to get hardware version:', err);
    return;
  }
  console.log('Hardware version:', version);
});
  • usbcan must be opened

usbcan.getFirmwareVersion(callback)

usbcan.getFirmwareVersion(function(err, version) {
  if (err) {
    console.log('Failed to get firmware version:', err);
    return;
  }
  console.log('Firmware version:', version);
});
  • usbcan must be opened

usbcan.sendBoardMessage(requestCommand)

usbcan.sendBoardMessage(0x43);
  • It's not recommanded to use this method directly. The list of supported request commands is provided in source code.
  • usbcan must be opened

usbcan.sendBoardMessageAndReceive(requestCommand, callback, [retryCount, responseMatcher])

usbcan.sendBoardMessageAndReceive(0x43, function(err, data) {
  if (err) {
    console.log('Failed to send board message:', err);
    return;
  }
});
  • It's not recommanded to use this method directly. The list of supported request commands is provided in source code.
  • retryCount is optional, but not if responseMatcher is provided
  • responseMatcher is optional. Example of signature below.
function(id, responseCommand, data) {
  return id == 0xFF && data[0] == 0x63;
}

usbcan.sendCanBusMessage([rtr], canId, [extendedCanId], [canData])

usbcan.sendCanBusMessage(418053888, Buffer.from([0x00, 0xee, 0x00]));
usbcan.sendCanBusMessage(418053888, true, Buffer.from([0x00, 0xee, 0x00]));
usbcan.sendCanBusMessage(false, 418053888, true, Buffer.from([0x00, 0xee, 0x00]));
  • usbcan must be opened
  • rtr is optional (default: false)
  • extendedCanId is optional (default: detected based on canId length)
  • canData is optional (default: empty Buffer)

Event: 'canbusmessage'

function(timestamp, rtr, id, extended, flags, data) { }

Event: 'boardmessage'

function(id, command, data) { }

Event: 'error'

function(message) { }

References

  • http://www.apoxcontrols.com/USBCANmenu.htm

License

(The MIT License)

Copyright (C) 2012, Georges-Etienne Legendre [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A different license may apply to other software included in this package, including libftdi and libusb. Please consult their respective license files for the terms of their individual licenses.