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

@mangar2/rs485interface

v1.0.2

Published

Arduino connection over RS485

Downloads

1

Readme

Abstract

Interface service to communicate with several arduino or similar microcontroller based on a RS485 bus The underlying protocol is token based . Tokens are send from one arduino to the other . The arduino having the token may send . Data is send in an internal message format . The message contains :

  • Byte : Sender address
  • Byte : Receiver address
  • Byte : Reply ( bit 1 ) and message format version ( bit 2 . . 8 )
  • Byte : Message length
  • Byte : Command to handle
  • Word : ( 2 bytes ) value , usual positive integer
  • Word : CRC16 for error handling

Contents

Meta

| | | | --- | --- | | File | index.js | | Abstract | Interface service to communicate with several arduino or similar microcontroller based on a RS485 bus The underlying protocol is token based . Tokens are send from one arduino to the other . The arduino having the token may send . Data is send in an internal message format . The message contains :

  • Byte : Sender address
  • Byte : Receiver address
  • Byte : Reply ( bit 1 ) and message format version ( bit 2 . . 8 )
  • Byte : Message length
  • Byte : Command to handle
  • Word : ( 2 bytes ) value , usual positive integer
  • Word : CRC16 for error handling | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

Callback definitions

Publish

Callback to publish messages to the mqtt broker

Publish Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | message | Message | message to publish | |

Send

Callback to send an array of bytes to a receiver

Send Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | byteArray | Array | Array of bytes | |

Global functions

prepare

prepare (config, rs485Interface)

Creates a new rs485Interface object , if not already existing

prepare Parameters

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | config | Object | | | configuration for the rs485 interface | | | rs485Interface | RS485Interface | optional | null | already existing interface object | |

Class AddressChain

new AddressChain()

Contains an ordered chain of addresses

AddressChain Methods

insert

insert (address, version)

Inserts an address , version pair to an ordered address chain

insert Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | address | number | address of the element to insert | | | version | number | version of the element to insert | |

Class RS485Interface

new RS485Interface(options)

Creates a service class to communicate with several arduino over a RS485 bus Most options are preset ( see "configuration . js" for all presets ) . You must provide the serial port name in operating system format and a list of addresses as object

Example

const serialPortName = 'COM1'
// Do not use 0 or 1 as addresses. 0 is used for broadcast events and 1 is the
// default address of this service.
const addresses = {
   myFloor/myRoom/myDevice: 2,
   myOtherFloor/myOtherRoom/myDevice: 3
   ...
}
const arduinoService = new ArduinoRS485({ serialPortName, addresses })

RS485Interface Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | options | Object | configuration options | |

options properties

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | serialPortName | string | | | name of the port to use | | | baudrate | integer | optional | 57600 | baud rate to be used | | | myAddress | integer | optional | 1 | address of this rs485 server | | | maxVersion | integer | optional | 1 | maximal suported interface version | | | tickDelay | integer | optional | 100 | inner clock managing the token , every action is calculated | | | timeOfDayDelayInSeconds | integer | optional | 60 | delay between sending the time of day | | | qos | 0, 1, 2 | optional | 1 | quality of service to send messages | | | trace | string | optional | 'messages' | trace level , supported errors , messages , token | |

RS485Interface Methods

close

async close ()

Stops the service

getSubscriptions

getSubscriptions () => {Array.<Object.<topic:string, qos:number>>}

Gets the list of required subscriptions for this service

getSubscriptions returns

| Type | Description | | ---- | ----------- | | Array.<Object.<topic:string, qos:number>> | list of subscription strings |

handleMessage

handleMessage (message)

Processes an incoming mqtt message

handleMessage Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | message | Message | mqtt message | |

on

on (event, callback)

Sets a callback .

on Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | event | string | event name ( not case sensitive ) for the callback ( supported : 'publish' ) | | | callback | Publish | function ( . . . parameter ) | |

on throws

| Type | Description | | ---- | ----------- | | Error | if the event is not supported | | Error | if the callback is not 'function' |

run

async run ()

Starts the server