This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from pycom/develop
fix broken bindings
- Loading branch information
Showing
50 changed files
with
6,020 additions
and
1,566 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# @serialport/bindings-cpp | ||
|
||
[![Backers on Open Collective](https://opencollective.com/serialport/backers/badge.svg)](#backers) | ||
[![Sponsors on Open Collective](https://opencollective.com/serialport/sponsors/badge.svg)](#sponsors) | ||
[![codecov](https://codecov.io/gh/serialport/bindings-cpp/branch/main/graph/badge.svg?token=rsGeOmdnsV)](https://codecov.io/gh/serialport/bindings-cpp) | ||
[![Test / Lint](https://github.com/serialport/bindings-cpp/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/serialport/bindings-cpp/actions/workflows/test.yml) | ||
|
||
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them! | ||
|
||
> Go to https://serialport.io/ to learn more, find guides and api documentation. | ||
## Quick Links | ||
|
||
- 📚 [**Guides**](https://serialport.io/docs/) | ||
- [**API Docs**](https://serialport.io/docs/api-serialport) | ||
- [`@serialport/bindings-cpp`](https://www.npmjs.com/package/@serialport/bindings-cpp) | ||
- 🐛 [Help and Bugs](https://github.com/serialport/node-serialport/issues/new/choose) All serialport issues are pointed to the main serialport repo. | ||
|
||
### Bindings | ||
|
||
The Bindings provide a low level interface to work with your serialport. It is possible to use them alone but it's usually easier to use them with an interface. | ||
|
||
- [`@serialport/bindings`](https://serialport.io/docs/api-bindings) bindings for Linux, Mac and Windows | ||
- [`@serialport/binding-interface`](https://serialport.io/docs/api-bindings-interface) as an interface to use if you're making your own bindings | ||
- [`@serialport/binding-mock`](https://serialport.io/docs/api-binding-mock) for a mock binding package for testing | ||
|
||
## Developing | ||
|
||
### Developing node serialport projects | ||
|
||
1. Clone this repo `git clone git@github.com:serialport/bindings-cpp.git` | ||
1. Run `npm install` to setup local package dependencies (run this any time you depend on a package local to this repo) | ||
1. Run `npm test` to ensure everything is working properly | ||
1. If you have a serial loopback device (TX to RX) you can run run `TEST_PORT=/path/to/port npm test` for a more comprehensive test suite. (Defaults to 115200 baud customize with the TEST_BAUD env.) You can use an arduino with the `test/arduino-echo` sketch. | ||
|
||
### Developing Docs | ||
|
||
See https://github.com/serialport/website | ||
|
||
## License | ||
|
||
SerialPort packages are all [MIT licensed](LICENSE) and all it's dependencies are MIT licensed. | ||
|
||
## Code of Conduct | ||
|
||
SerialPort follows the [Nodebots Code of Conduct](http://nodebots.io/conduct.html). While the code is MIT licensed participation in the community has some rules to make this a good place to work and learn. | ||
|
||
### TLDR | ||
|
||
- Be respectful. | ||
- Abusive behavior is never tolerated. | ||
- Data published to NodeBots is hosted at the discretion of the service administrators, and may be removed. | ||
- Don't build evil robots. | ||
- Violations of this code may result in swift and permanent expulsion from the NodeBots community. | ||
|
||
## Governance and Community | ||
|
||
SerialPort is currently employees a [governance](https://medium.com/the-node-js-collection/healthy-open-source-967fa8be7951) with a group of maintainers, committers and contributors, all fixing bugs and adding features and improving documentation. You need not apply to work on SerialPort, all are welcome to join, build, and maintain this project. | ||
|
||
- A Contributor is any individual creating or commenting on an issue or pull request. By participating, this is you. | ||
- Committers are contributors who have been given write access to the repository. They can review and merge pull requests. | ||
- Maintainers are committers representing the required technical expertise to resolve rare disputes. | ||
|
||
If you have a PR that improves the project people in any or all of the above people will help you land it. | ||
|
||
**Maintainers** | ||
|
||
- [Francis Gulotta](https://twitter.com/reconbot) | [reconbot](https://github.com/reconbot) | ||
- [Nick Hehr](https://twitter.com/hipsterbrown) | [hipsterbrown](https://github.com/hipsterbrown) | ||
|
||
### Contributors | ||
|
||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. | ||
<a href="https://github.com/serialport/node-serialport/graphs/contributors"><img src="https://opencollective.com/serialport/contributors.svg?width=890&button=false" /></a> | ||
|
||
### Backers | ||
|
||
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/serialport#backer)] | ||
|
||
<a href="https://opencollective.com/serialport#backers" target="_blank"><img src="https://opencollective.com/serialport/backers.svg?width=890"></a> | ||
|
||
### Sponsors | ||
|
||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/serialport#sponsor)] | ||
|
||
<!-- <a href="https://opencollective.com/serialport/sponsor/0/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/0/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/1/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/1/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/2/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/2/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/3/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/3/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/4/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/4/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/5/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/5/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/6/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/6/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/7/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/7/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/8/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/8/avatar.svg"></a> | ||
<a href="https://opencollective.com/serialport/sponsor/9/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/9/avatar.svg"></a> --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
'targets': [{ | ||
'target_name': 'bindings', | ||
'sources': [ | ||
'src/serialport.cpp' | ||
], | ||
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"], | ||
'cflags!': [ '-fno-exceptions' ], | ||
'cflags_cc!': [ '-fno-exceptions' ], | ||
"defines": ["NAPI_CPP_EXCEPTIONS"], | ||
'conditions': [ | ||
['OS=="win"', | ||
{ | ||
'defines': ['CHECK_NODE_MODULE_VERSION'], | ||
'sources': [ | ||
'src/serialport_win.cpp' | ||
], | ||
'msvs_settings': { | ||
'VCCLCompilerTool': { | ||
'ExceptionHandling': '1', | ||
'DisableSpecificWarnings': [ '4530', '4506' ], | ||
} | ||
} | ||
} | ||
], | ||
['OS=="mac"', | ||
{ | ||
'sources': [ | ||
'src/serialport_unix.cpp', | ||
'src/poller.cpp', | ||
'src/darwin_list.cpp' | ||
], | ||
'xcode_settings': { | ||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', | ||
'MACOSX_DEPLOYMENT_TARGET': '10.9', | ||
'OTHER_CFLAGS': [ | ||
'-arch x86_64', | ||
'-arch arm64' | ||
], | ||
'OTHER_LDFLAGS': [ | ||
'-framework CoreFoundation', | ||
'-framework IOKit', | ||
'-arch x86_64', | ||
'-arch arm64' | ||
] | ||
} | ||
} | ||
], | ||
['OS=="linux"', | ||
{ | ||
'sources': [ | ||
'src/serialport_unix.cpp', | ||
'src/poller.cpp', | ||
'src/serialport_linux.cpp' | ||
] | ||
} | ||
], | ||
['OS=="android"', | ||
{ | ||
'sources': [ | ||
'src/serialport_unix.cpp', | ||
'src/poller.cpp', | ||
'src/serialport_linux.cpp' | ||
] | ||
} | ||
], | ||
['OS!="win"', | ||
{ | ||
'sources': [ | ||
'src/serialport_unix.cpp', | ||
'src/poller.cpp' | ||
] | ||
} | ||
] | ||
] | ||
}], | ||
} |
39 changes: 39 additions & 0 deletions
39
preinstalled_modules/@serialport/bindings-cpp/dist/darwin.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/// <reference types="node" /> | ||
import { BindingPortInterface } from '.'; | ||
import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from '@serialport/bindings-interface'; | ||
import { Poller } from './poller'; | ||
export interface DarwinOpenOptions extends OpenOptions { | ||
/** Defaults to none */ | ||
parity?: 'none' | 'even' | 'odd'; | ||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 1 */ | ||
vmin?: number; | ||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 0 */ | ||
vtime?: number; | ||
} | ||
export declare type DarwinBindingInterface = BindingInterface<DarwinPortBinding, DarwinOpenOptions>; | ||
export declare const DarwinBinding: DarwinBindingInterface; | ||
/** | ||
* The Darwin binding layer for OSX | ||
*/ | ||
export declare class DarwinPortBinding implements BindingPortInterface { | ||
readonly openOptions: Required<DarwinOpenOptions>; | ||
readonly poller: Poller; | ||
private writeOperation; | ||
fd: null | number; | ||
constructor(fd: number, options: Required<DarwinOpenOptions>); | ||
get isOpen(): boolean; | ||
close(): Promise<void>; | ||
read(buffer: Buffer, offset: number, length: number): Promise<{ | ||
buffer: Buffer; | ||
bytesRead: number; | ||
}>; | ||
write(buffer: Buffer): Promise<void>; | ||
update(options: UpdateOptions): Promise<void>; | ||
set(options: SetOptions): Promise<void>; | ||
get(): Promise<PortStatus>; | ||
getBaudRate(): Promise<{ | ||
baudRate: number; | ||
}>; | ||
flush(): Promise<void>; | ||
drain(): Promise<void>; | ||
} |
148 changes: 148 additions & 0 deletions
148
preinstalled_modules/@serialport/bindings-cpp/dist/darwin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DarwinPortBinding = exports.DarwinBinding = void 0; | ||
const debug_1 = __importDefault(require("debug")); | ||
const load_bindings_1 = require("./load-bindings"); | ||
const poller_1 = require("./poller"); | ||
const unix_read_1 = require("./unix-read"); | ||
const unix_write_1 = require("./unix-write"); | ||
const debug = (0, debug_1.default)('serialport/bindings-cpp'); | ||
exports.DarwinBinding = { | ||
list() { | ||
debug('list'); | ||
return (0, load_bindings_1.asyncList)(); | ||
}, | ||
async open(options) { | ||
if (!options || typeof options !== 'object' || Array.isArray(options)) { | ||
throw new TypeError('"options" is not an object'); | ||
} | ||
if (!options.path) { | ||
throw new TypeError('"path" is not a valid port'); | ||
} | ||
if (!options.baudRate) { | ||
throw new TypeError('"baudRate" is not a valid baudRate'); | ||
} | ||
debug('open'); | ||
const openOptions = Object.assign({ vmin: 1, vtime: 0, dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options); | ||
const fd = await (0, load_bindings_1.asyncOpen)(openOptions.path, openOptions); | ||
return new DarwinPortBinding(fd, openOptions); | ||
}, | ||
}; | ||
/** | ||
* The Darwin binding layer for OSX | ||
*/ | ||
class DarwinPortBinding { | ||
constructor(fd, options) { | ||
this.fd = fd; | ||
this.openOptions = options; | ||
this.poller = new poller_1.Poller(fd); | ||
this.writeOperation = null; | ||
} | ||
get isOpen() { | ||
return this.fd !== null; | ||
} | ||
async close() { | ||
debug('close'); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
const fd = this.fd; | ||
this.poller.stop(); | ||
this.poller.destroy(); | ||
this.fd = null; | ||
await (0, load_bindings_1.asyncClose)(fd); | ||
} | ||
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'); | ||
} | ||
return (0, unix_read_1.unixRead)({ binding: this, buffer, offset, length }); | ||
} | ||
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'); | ||
} | ||
this.writeOperation = (async () => { | ||
if (buffer.length === 0) { | ||
return; | ||
} | ||
await (0, unix_write_1.unixWrite)({ binding: this, buffer }); | ||
this.writeOperation = null; | ||
})(); | ||
return this.writeOperation; | ||
} | ||
async update(options) { | ||
if (!options || typeof options !== 'object' || Array.isArray(options)) { | ||
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'); | ||
} | ||
await (0, load_bindings_1.asyncUpdate)(this.fd, options); | ||
} | ||
async set(options) { | ||
if (!options || typeof options !== 'object' || Array.isArray(options)) { | ||
throw new TypeError('"options" is not an object'); | ||
} | ||
debug('set', options); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
await (0, load_bindings_1.asyncSet)(this.fd, options); | ||
} | ||
async get() { | ||
debug('get'); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
return (0, load_bindings_1.asyncGet)(this.fd); | ||
} | ||
async getBaudRate() { | ||
debug('getBaudRate'); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
throw new Error('getBaudRate is not implemented on darwin'); | ||
} | ||
async flush() { | ||
debug('flush'); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
await (0, load_bindings_1.asyncFlush)(this.fd); | ||
} | ||
async drain() { | ||
debug('drain'); | ||
if (!this.isOpen) { | ||
throw new Error('Port is not open'); | ||
} | ||
await this.writeOperation; | ||
await (0, load_bindings_1.asyncDrain)(this.fd); | ||
} | ||
} | ||
exports.DarwinPortBinding = DarwinPortBinding; |
Oops, something went wrong.