Skip to content
Snippets Groups Projects
Commit 986110e0 authored by Ben Coombs's avatar Ben Coombs
Browse files

Added node.js server to communicate with Arduino device over serial port

parent 707e36dd
No related branches found
No related tags found
No related merge requests found
Showing
with 613 additions and 0 deletions
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../detect-libc/bin/detect-libc.js" "$@"
ret=$?
else
node "$basedir/../detect-libc/bin/detect-libc.js" "$@"
ret=$?
fi
exit $ret
@ECHO off
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
"%_prog%" "%dp0%\..\detect-libc\bin\detect-libc.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
$ret=$LASTEXITCODE
} else {
& "node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
$ret=$LASTEXITCODE
}
exit $ret
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../prebuild-install/bin.js" "$@"
ret=$?
else
node "$basedir/../prebuild-install/bin.js" "$@"
ret=$?
fi
exit $ret
@ECHO off
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
"%_prog%" "%dp0%\..\prebuild-install\bin.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/../prebuild-install/bin.js" $args
$ret=$LASTEXITCODE
} else {
& "node$exe" "$basedir/../prebuild-install/bin.js" $args
$ret=$LASTEXITCODE
}
exit $ret
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../rc/cli.js" "$@"
ret=$?
else
node "$basedir/../rc/cli.js" "$@"
ret=$?
fi
exit $ret
@ECHO off
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
"%_prog%" "%dp0%\..\rc\cli.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/../rc/cli.js" $args
$ret=$LASTEXITCODE
} else {
& "node$exe" "$basedir/../rc/cli.js" $args
$ret=$LASTEXITCODE
}
exit $ret
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../semver/bin/semver" "$@"
ret=$?
else
node "$basedir/../semver/bin/semver" "$@"
ret=$?
fi
exit $ret
@ECHO off
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
"%_prog%" "%dp0%\..\semver\bin\semver" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
& "$basedir/node$exe" "$basedir/../semver/bin/semver" $args
$ret=$LASTEXITCODE
} else {
& "node$exe" "$basedir/../semver/bin/semver" $args
$ret=$LASTEXITCODE
}
exit $ret
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [9.0.2](https://github.com/serialport/node-serialport/compare/v9.0.1...v9.0.2) (2020-10-16)
### Bug Fixes
* while validating for offset, check for offset's value for NaN instead length ([#2124](https://github.com/serialport/node-serialport/issues/2124)) ([4215122](https://github.com/serialport/node-serialport/commit/42151228240c5c818ac5327d6ff5c01398805564))
## [9.0.1](https://github.com/serialport/node-serialport/compare/v9.0.0...v9.0.1) (2020-08-08)
**Note:** Version bump only for package @serialport/binding-abstract
# [9.0.0](https://github.com/serialport/node-serialport/compare/v8.0.8...v9.0.0) (2020-05-10)
**Note:** Version bump only for package @serialport/binding-abstract
## [8.0.6](https://github.com/serialport/node-serialport/compare/v8.0.5...v8.0.6) (2019-12-25)
**Note:** Version bump only for package @serialport/binding-abstract
The MIT License (MIT)
Copyright 2010 Christopher Williams. All rights reserved.
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.
# @serialport/BindingAbstract
This Abstract binding class is the base for all serialport bindings. You wouldn't use this class directly but instead extend it to make a new binding for a different platform or underling technology.
This is currently used for the win32, linux, darwin and mock bindings.
This is how you use it.
```js
class MockBinding extends AbstractBinding {
constructor(opt) {
super(opt)
}
}
```
const debug = require('debug')('serialport/binding-abstract')
/**
* @name Binding
* @type {AbstractBinding}
* @since 5.0.0
* @description The `Binding` is how Node-SerialPort talks to the underlying system. By default, we auto detect Windows, Linux and OS X, and load the appropriate module for your system. You can assign `SerialPort.Binding` to any binding you like. Find more by searching at [npm](https://npmjs.org/).
Prevent auto loading the default bindings by requiring SerialPort with:
```js
var SerialPort = require('@serialport/stream');
SerialPort.Binding = MyBindingClass;
```
*/
/**
* You never have to use `Binding` objects directly. SerialPort uses them to access the underlying hardware. This documentation is geared towards people who are making bindings for different platforms. This class can be inherited from to get type checking for each method.
* @class AbstractBinding
* @param {object} options options for the binding
* @property {boolean} isOpen Required property. `true` if the port is open, `false` otherwise. Should be read-only.
* @throws {TypeError} When given invalid arguments, a `TypeError` is thrown.
* @since 5.0.0
*/
class AbstractBinding {
/**
* Retrieves a list of available serial ports with metadata. The `path` must be guaranteed, and all other fields should be undefined if unavailable. The `path` is either the path or an identifier (eg `COM1`) used to open the serialport.
* @returns {Promise} resolves to an array of port [info objects](#module_serialport--SerialPort.list).
*/
static async list() {
debug('list')
}
constructor(opt = {}) {
if (typeof opt !== 'object') {
throw new TypeError('"options" is not an object')
}
}
/**
* Opens a connection to the serial port referenced by the path.
* @param {string} path the path or com port to open
* @param {openOptions} options openOptions for the serialport
* @returns {Promise} Resolves after the port is opened and configured.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async open(path, options) {
if (!path) {
throw new TypeError('"path" is not a valid port')
}
if (typeof options !== 'object') {
throw new TypeError('"options" is not an object')
}
debug('open')
if (this.isOpen) {
throw new Error('Already open')
}
}
/**
* Closes an open connection
* @returns {Promise} Resolves once the connection is closed.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async close() {
debug('close')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Request a number of bytes from the SerialPort. This function is similar to Node's [`fs.read`](http://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) except it will always return at least one byte.
The in progress reads must error when the port is closed with an error object that has the property `canceled` equal to `true`. Any other error will cause a disconnection.
* @param {buffer} buffer Accepts a [`Buffer`](http://nodejs.org/api/buffer.html) object.
* @param {integer} offset The offset in the buffer to start writing at.
* @param {integer} length Specifies the maximum number of bytes to read.
* @returns {Promise} Resolves with the number of bytes read after a read operation.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async read(buffer, offset, length) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('"buffer" is not a Buffer')
}
if (typeof offset !== 'number' || isNaN(offset)) {
throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`)
}
if (typeof length !== 'number' || isNaN(length)) {
throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`)
}
debug('read')
if (buffer.length < offset + length) {
throw new Error('buffer is too small')
}
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Write bytes to the SerialPort. Only called when there is no pending write operation.
The in progress writes must error when the port is closed with an error object that has the property `canceled` equal to `true`. Any other error will cause a disconnection.
* @param {buffer} buffer - Accepts a [`Buffer`](http://nodejs.org/api/buffer.html) object.
* @returns {Promise} Resolves after the data is passed to the operating system for writing.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async write(buffer) {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError('"buffer" is not a Buffer')
}
debug('write', buffer.length, 'bytes')
if (!this.isOpen) {
debug('write', 'error port is not open')
throw new Error('Port is not open')
}
}
/**
* Changes connection settings on an open port. Only `baudRate` is supported.
* @param {object=} options Only supports `baudRate`.
* @param {number=} [options.baudRate] If provided a baud rate that the bindings do not support, it should reject.
* @returns {Promise} Resolves once the port's baud rate changes.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async update(options) {
if (typeof options !== 'object') {
throw TypeError('"options" is not an object')
}
if (typeof options.baudRate !== 'number') {
throw new TypeError('"options.baudRate" is not a number')
}
debug('update')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Set control flags on an open port.
* @param {object=} options All options are operating system default when the port is opened. Every flag is set on each call to the provided or default values. All options are always provided.
* @param {Boolean} [options.brk=false] flag for brk
* @param {Boolean} [options.cts=false] flag for cts
* @param {Boolean} [options.dsr=false] flag for dsr
* @param {Boolean} [options.dtr=true] flag for dtr
* @param {Boolean} [options.rts=true] flag for rts
* @returns {Promise} Resolves once the port's flags are set.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async set(options) {
if (typeof options !== 'object') {
throw new TypeError('"options" is not an object')
}
debug('set')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Get the control flags (CTS, DSR, DCD) on the open port.
* @returns {Promise} Resolves with the retrieved flags.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async get() {
debug('get')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Get the OS reported baud rate for the open port.
* Used mostly for debugging custom baud rates.
* @returns {Promise} Resolves with the current baud rate.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async getBaudRate() {
debug('getbaudRate')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Flush (discard) data received but not read, and written but not transmitted.
* @returns {Promise} Resolves once the flush operation finishes.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async flush() {
debug('flush')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
/**
* Drain waits until all output data is transmitted to the serial port. An in progress write should be completed before this returns.
* @returns {Promise} Resolves once the drain operation finishes.
* @rejects {TypeError} When given invalid arguments, a `TypeError` is rejected.
*/
async drain() {
debug('drain')
if (!this.isOpen) {
throw new Error('Port is not open')
}
}
}
module.exports = AbstractBinding
{
"_from": "@serialport/binding-abstract@^9.0.2",
"_id": "@serialport/binding-abstract@9.0.2",
"_inBundle": false,
"_integrity": "sha512-kyMX6usn+VLpidt0YsDq5JwztIan9TPCX6skr0XcalOxI8I7w+/2qVZJzjgo2fSqDnPRcU2jMWTytwzEXFODvQ==",
"_location": "/@serialport/binding-abstract",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@serialport/binding-abstract@^9.0.2",
"name": "@serialport/binding-abstract",
"escapedName": "@serialport%2fbinding-abstract",
"scope": "@serialport",
"rawSpec": "^9.0.2",
"saveSpec": null,
"fetchSpec": "^9.0.2"
},
"_requiredBy": [
"/@serialport/binding-mock",
"/@serialport/bindings"
],
"_resolved": "https://registry.npmjs.org/@serialport/binding-abstract/-/binding-abstract-9.0.2.tgz",
"_shasum": "f06f1859b59875632cd263d3f3bb0711c885c78f",
"_spec": "@serialport/binding-abstract@^9.0.2",
"_where": "F:\\vent-display\\node_modules\\@serialport\\binding-mock",
"bugs": {
"url": "https://github.com/serialport/node-serialport/issues"
},
"bundleDependencies": false,
"dependencies": {
"debug": "^4.1.1"
},
"deprecated": false,
"description": "This Abstract binding class is the base for all serialport bindings. You wouldn't use this class directly but instead extend it to make a new binding for a different platform or underling technology.",
"engines": {
"node": ">=8.6.0"
},
"gitHead": "df482d3af7660fd13a4ecc2de5ddcb70a02417f4",
"homepage": "https://github.com/serialport/node-serialport#readme",
"keywords": [
"serialport-binding"
],
"license": "MIT",
"main": "lib",
"name": "@serialport/binding-abstract",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git://github.com/serialport/node-serialport.git"
},
"version": "9.0.2"
}
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [9.0.2](https://github.com/serialport/node-serialport/compare/v9.0.1...v9.0.2) (2020-10-16)
**Note:** Version bump only for package @serialport/binding-mock
## [9.0.1](https://github.com/serialport/node-serialport/compare/v9.0.0...v9.0.1) (2020-08-08)
**Note:** Version bump only for package @serialport/binding-mock
# [9.0.0](https://github.com/serialport/node-serialport/compare/v8.0.8...v9.0.0) (2020-05-10)
**Note:** Version bump only for package @serialport/binding-mock
## [8.0.6](https://github.com/serialport/node-serialport/compare/v8.0.5...v8.0.6) (2019-12-25)
### Bug Fixes
* bindings.close() should cause a canceled read error ([#1972](https://github.com/serialport/node-serialport/issues/1972)) ([50f967e](https://github.com/serialport/node-serialport/commit/50f967e788f362da57d782829712542c8f15f8c8))
The MIT License (MIT)
Copyright 2010 Christopher Williams. All rights reserved.
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.
# @serialport/BindingMock
This stream does some neat stuff.
This is why you'd use it.
This is how you use it.
```js
const bindingMock = new BindingMock()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment