Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 8f465ae

Browse files
author
Jakob Rosenberg
authored
Merge pull request #301 from pycom/develop
fix broken bindings
2 parents 35d5615 + 136d780 commit 8f465ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6020
-1566
lines changed

package-lock.json

Lines changed: 1858 additions & 1565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
},
6060
"scripts": {
6161
"watch": "onchange '**/*.js' '**/*.html' '**/*.less' -- sh scripts/restart-atom.sh",
62-
"postinstall": "node scripts/post-install.js",
62+
"@preinstall": "bindings-ccp needs to be preinstalled for Unix. Don't know why. : makes Windows ignore the command",
63+
"preinstall": ":; cp preinstalled_modules node_modules -r",
64+
"_postinstall": "node scripts/post-install.js",
6365
"test-electron": "pwsh -nop -f ./test-electron/runtest.ps1",
6466
"download-native": "node scripts/download-binaries.js",
6567
"semantic-release": "semantic-release"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright 2010 Christopher Williams. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to
7+
deal in the Software without restriction, including without limitation the
8+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9+
sell copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
IN THE SOFTWARE.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# @serialport/bindings-cpp
2+
3+
[![Backers on Open Collective](https://opencollective.com/serialport/backers/badge.svg)](#backers)
4+
[![Sponsors on Open Collective](https://opencollective.com/serialport/sponsors/badge.svg)](#sponsors)
5+
[![codecov](https://codecov.io/gh/serialport/bindings-cpp/branch/main/graph/badge.svg?token=rsGeOmdnsV)](https://codecov.io/gh/serialport/bindings-cpp)
6+
[![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)
7+
8+
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
9+
10+
> Go to https://serialport.io/ to learn more, find guides and api documentation.
11+
12+
## Quick Links
13+
14+
- 📚 [**Guides**](https://serialport.io/docs/)
15+
- [**API Docs**](https://serialport.io/docs/api-serialport)
16+
- [`@serialport/bindings-cpp`](https://www.npmjs.com/package/@serialport/bindings-cpp)
17+
- 🐛 [Help and Bugs](https://github.com/serialport/node-serialport/issues/new/choose) All serialport issues are pointed to the main serialport repo.
18+
19+
### Bindings
20+
21+
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.
22+
23+
- [`@serialport/bindings`](https://serialport.io/docs/api-bindings) bindings for Linux, Mac and Windows
24+
- [`@serialport/binding-interface`](https://serialport.io/docs/api-bindings-interface) as an interface to use if you're making your own bindings
25+
- [`@serialport/binding-mock`](https://serialport.io/docs/api-binding-mock) for a mock binding package for testing
26+
27+
## Developing
28+
29+
### Developing node serialport projects
30+
31+
1. Clone this repo `git clone git@github.com:serialport/bindings-cpp.git`
32+
1. Run `npm install` to setup local package dependencies (run this any time you depend on a package local to this repo)
33+
1. Run `npm test` to ensure everything is working properly
34+
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.
35+
36+
### Developing Docs
37+
38+
See https://github.com/serialport/website
39+
40+
## License
41+
42+
SerialPort packages are all [MIT licensed](LICENSE) and all it's dependencies are MIT licensed.
43+
44+
## Code of Conduct
45+
46+
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.
47+
48+
### TLDR
49+
50+
- Be respectful.
51+
- Abusive behavior is never tolerated.
52+
- Data published to NodeBots is hosted at the discretion of the service administrators, and may be removed.
53+
- Don't build evil robots.
54+
- Violations of this code may result in swift and permanent expulsion from the NodeBots community.
55+
56+
## Governance and Community
57+
58+
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.
59+
60+
- A Contributor is any individual creating or commenting on an issue or pull request. By participating, this is you.
61+
- Committers are contributors who have been given write access to the repository. They can review and merge pull requests.
62+
- Maintainers are committers representing the required technical expertise to resolve rare disputes.
63+
64+
If you have a PR that improves the project people in any or all of the above people will help you land it.
65+
66+
**Maintainers**
67+
68+
- [Francis Gulotta](https://twitter.com/reconbot) | [reconbot](https://github.com/reconbot)
69+
- [Nick Hehr](https://twitter.com/hipsterbrown) | [hipsterbrown](https://github.com/hipsterbrown)
70+
71+
### Contributors
72+
73+
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
74+
<a href="https://github.com/serialport/node-serialport/graphs/contributors"><img src="https://opencollective.com/serialport/contributors.svg?width=890&button=false" /></a>
75+
76+
### Backers
77+
78+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/serialport#backer)]
79+
80+
<a href="https://opencollective.com/serialport#backers" target="_blank"><img src="https://opencollective.com/serialport/backers.svg?width=890"></a>
81+
82+
### Sponsors
83+
84+
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)]
85+
86+
<!-- <a href="https://opencollective.com/serialport/sponsor/0/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/0/avatar.svg"></a>
87+
<a href="https://opencollective.com/serialport/sponsor/1/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/1/avatar.svg"></a>
88+
<a href="https://opencollective.com/serialport/sponsor/2/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/2/avatar.svg"></a>
89+
<a href="https://opencollective.com/serialport/sponsor/3/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/3/avatar.svg"></a>
90+
<a href="https://opencollective.com/serialport/sponsor/4/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/4/avatar.svg"></a>
91+
<a href="https://opencollective.com/serialport/sponsor/5/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/5/avatar.svg"></a>
92+
<a href="https://opencollective.com/serialport/sponsor/6/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/6/avatar.svg"></a>
93+
<a href="https://opencollective.com/serialport/sponsor/7/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/7/avatar.svg"></a>
94+
<a href="https://opencollective.com/serialport/sponsor/8/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/8/avatar.svg"></a>
95+
<a href="https://opencollective.com/serialport/sponsor/9/website" target="_blank"><img src="https://opencollective.com/serialport/sponsor/9/avatar.svg"></a> -->
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
'targets': [{
3+
'target_name': 'bindings',
4+
'sources': [
5+
'src/serialport.cpp'
6+
],
7+
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
8+
'cflags!': [ '-fno-exceptions' ],
9+
'cflags_cc!': [ '-fno-exceptions' ],
10+
"defines": ["NAPI_CPP_EXCEPTIONS"],
11+
'conditions': [
12+
['OS=="win"',
13+
{
14+
'defines': ['CHECK_NODE_MODULE_VERSION'],
15+
'sources': [
16+
'src/serialport_win.cpp'
17+
],
18+
'msvs_settings': {
19+
'VCCLCompilerTool': {
20+
'ExceptionHandling': '1',
21+
'DisableSpecificWarnings': [ '4530', '4506' ],
22+
}
23+
}
24+
}
25+
],
26+
['OS=="mac"',
27+
{
28+
'sources': [
29+
'src/serialport_unix.cpp',
30+
'src/poller.cpp',
31+
'src/darwin_list.cpp'
32+
],
33+
'xcode_settings': {
34+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
35+
'MACOSX_DEPLOYMENT_TARGET': '10.9',
36+
'OTHER_CFLAGS': [
37+
'-arch x86_64',
38+
'-arch arm64'
39+
],
40+
'OTHER_LDFLAGS': [
41+
'-framework CoreFoundation',
42+
'-framework IOKit',
43+
'-arch x86_64',
44+
'-arch arm64'
45+
]
46+
}
47+
}
48+
],
49+
['OS=="linux"',
50+
{
51+
'sources': [
52+
'src/serialport_unix.cpp',
53+
'src/poller.cpp',
54+
'src/serialport_linux.cpp'
55+
]
56+
}
57+
],
58+
['OS=="android"',
59+
{
60+
'sources': [
61+
'src/serialport_unix.cpp',
62+
'src/poller.cpp',
63+
'src/serialport_linux.cpp'
64+
]
65+
}
66+
],
67+
['OS!="win"',
68+
{
69+
'sources': [
70+
'src/serialport_unix.cpp',
71+
'src/poller.cpp'
72+
]
73+
}
74+
]
75+
]
76+
}],
77+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// <reference types="node" />
2+
import { BindingPortInterface } from '.';
3+
import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from '@serialport/bindings-interface';
4+
import { Poller } from './poller';
5+
export interface DarwinOpenOptions extends OpenOptions {
6+
/** Defaults to none */
7+
parity?: 'none' | 'even' | 'odd';
8+
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 1 */
9+
vmin?: number;
10+
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 0 */
11+
vtime?: number;
12+
}
13+
export declare type DarwinBindingInterface = BindingInterface<DarwinPortBinding, DarwinOpenOptions>;
14+
export declare const DarwinBinding: DarwinBindingInterface;
15+
/**
16+
* The Darwin binding layer for OSX
17+
*/
18+
export declare class DarwinPortBinding implements BindingPortInterface {
19+
readonly openOptions: Required<DarwinOpenOptions>;
20+
readonly poller: Poller;
21+
private writeOperation;
22+
fd: null | number;
23+
constructor(fd: number, options: Required<DarwinOpenOptions>);
24+
get isOpen(): boolean;
25+
close(): Promise<void>;
26+
read(buffer: Buffer, offset: number, length: number): Promise<{
27+
buffer: Buffer;
28+
bytesRead: number;
29+
}>;
30+
write(buffer: Buffer): Promise<void>;
31+
update(options: UpdateOptions): Promise<void>;
32+
set(options: SetOptions): Promise<void>;
33+
get(): Promise<PortStatus>;
34+
getBaudRate(): Promise<{
35+
baudRate: number;
36+
}>;
37+
flush(): Promise<void>;
38+
drain(): Promise<void>;
39+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.DarwinPortBinding = exports.DarwinBinding = void 0;
7+
const debug_1 = __importDefault(require("debug"));
8+
const load_bindings_1 = require("./load-bindings");
9+
const poller_1 = require("./poller");
10+
const unix_read_1 = require("./unix-read");
11+
const unix_write_1 = require("./unix-write");
12+
const debug = (0, debug_1.default)('serialport/bindings-cpp');
13+
exports.DarwinBinding = {
14+
list() {
15+
debug('list');
16+
return (0, load_bindings_1.asyncList)();
17+
},
18+
async open(options) {
19+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
20+
throw new TypeError('"options" is not an object');
21+
}
22+
if (!options.path) {
23+
throw new TypeError('"path" is not a valid port');
24+
}
25+
if (!options.baudRate) {
26+
throw new TypeError('"baudRate" is not a valid baudRate');
27+
}
28+
debug('open');
29+
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);
30+
const fd = await (0, load_bindings_1.asyncOpen)(openOptions.path, openOptions);
31+
return new DarwinPortBinding(fd, openOptions);
32+
},
33+
};
34+
/**
35+
* The Darwin binding layer for OSX
36+
*/
37+
class DarwinPortBinding {
38+
constructor(fd, options) {
39+
this.fd = fd;
40+
this.openOptions = options;
41+
this.poller = new poller_1.Poller(fd);
42+
this.writeOperation = null;
43+
}
44+
get isOpen() {
45+
return this.fd !== null;
46+
}
47+
async close() {
48+
debug('close');
49+
if (!this.isOpen) {
50+
throw new Error('Port is not open');
51+
}
52+
const fd = this.fd;
53+
this.poller.stop();
54+
this.poller.destroy();
55+
this.fd = null;
56+
await (0, load_bindings_1.asyncClose)(fd);
57+
}
58+
async read(buffer, offset, length) {
59+
if (!Buffer.isBuffer(buffer)) {
60+
throw new TypeError('"buffer" is not a Buffer');
61+
}
62+
if (typeof offset !== 'number' || isNaN(offset)) {
63+
throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`);
64+
}
65+
if (typeof length !== 'number' || isNaN(length)) {
66+
throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`);
67+
}
68+
debug('read');
69+
if (buffer.length < offset + length) {
70+
throw new Error('buffer is too small');
71+
}
72+
if (!this.isOpen) {
73+
throw new Error('Port is not open');
74+
}
75+
return (0, unix_read_1.unixRead)({ binding: this, buffer, offset, length });
76+
}
77+
async write(buffer) {
78+
if (!Buffer.isBuffer(buffer)) {
79+
throw new TypeError('"buffer" is not a Buffer');
80+
}
81+
debug('write', buffer.length, 'bytes');
82+
if (!this.isOpen) {
83+
debug('write', 'error port is not open');
84+
throw new Error('Port is not open');
85+
}
86+
this.writeOperation = (async () => {
87+
if (buffer.length === 0) {
88+
return;
89+
}
90+
await (0, unix_write_1.unixWrite)({ binding: this, buffer });
91+
this.writeOperation = null;
92+
})();
93+
return this.writeOperation;
94+
}
95+
async update(options) {
96+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
97+
throw TypeError('"options" is not an object');
98+
}
99+
if (typeof options.baudRate !== 'number') {
100+
throw new TypeError('"options.baudRate" is not a number');
101+
}
102+
debug('update');
103+
if (!this.isOpen) {
104+
throw new Error('Port is not open');
105+
}
106+
await (0, load_bindings_1.asyncUpdate)(this.fd, options);
107+
}
108+
async set(options) {
109+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
110+
throw new TypeError('"options" is not an object');
111+
}
112+
debug('set', options);
113+
if (!this.isOpen) {
114+
throw new Error('Port is not open');
115+
}
116+
await (0, load_bindings_1.asyncSet)(this.fd, options);
117+
}
118+
async get() {
119+
debug('get');
120+
if (!this.isOpen) {
121+
throw new Error('Port is not open');
122+
}
123+
return (0, load_bindings_1.asyncGet)(this.fd);
124+
}
125+
async getBaudRate() {
126+
debug('getBaudRate');
127+
if (!this.isOpen) {
128+
throw new Error('Port is not open');
129+
}
130+
throw new Error('getBaudRate is not implemented on darwin');
131+
}
132+
async flush() {
133+
debug('flush');
134+
if (!this.isOpen) {
135+
throw new Error('Port is not open');
136+
}
137+
await (0, load_bindings_1.asyncFlush)(this.fd);
138+
}
139+
async drain() {
140+
debug('drain');
141+
if (!this.isOpen) {
142+
throw new Error('Port is not open');
143+
}
144+
await this.writeOperation;
145+
await (0, load_bindings_1.asyncDrain)(this.fd);
146+
}
147+
}
148+
exports.DarwinPortBinding = DarwinPortBinding;

0 commit comments

Comments
 (0)