Commit graph

183 commits

Author SHA1 Message Date
Kirill Zhumarin
92230ebd59 fix: deliver poller events with MakeCallback 2026-06-30 00:56:43 +03:00
Francis Gulotta
4655cc1439
fix: close windows read handle when reading one byte (#197)
Makes sure we always close the event handle when we're done reading.

Finishes up #165
2024-12-23 15:12:00 -05:00
markw65
f8bfc1eed2
fix: single character reads on windows fail (#165)
I have a project using `@serialport/bindings-cpp` that works without
issues on MacOS and Linux, but on windows every read fails with

```
[Error: Reading from COM port (ReadFile): Unknown error code 1784]
```

The device I'm talking to has a binary protocol, and all exchanges begin
with a single character write to the device, a single character response
from the device, and then further, longer exchanges. The single
character read always fails.

This is because `ReadThread` does a single character read using
`ReadFileEx`, and then, unconditionally reads "the rest of the data"
using `ReadFile`. But in the case of a single character read there is no
"rest of the data". This pull request fixes it by checking for no more
data before issuing the `ReadFile`.

I don't know how to write a test that would fail without the fix.

Co-authored-by: markw65 <git@myosotissp.com>
2024-12-23 15:02:48 -05:00
Azq2
f3174ff804
fix: custom baudrate for OSX & Linux (#186) 2024-12-23 14:51:15 -05:00
Artur Morys - Magiera
b0a9aa1e86
fix: support wchar_t and Unicode encoding in .list() parameters (#63)
Fixes https://github.com/serialport/bindings-cpp/issues/62
2022-11-16 20:28:51 -05:00
Greg Van Aken
027529224a
feat: Allow for RTS to be explicitly enabled on windows (#23)
* Allow for RTS to be explicitly enabled
* Expose new option to windows types
2022-02-26 00:04:52 -05:00
Francis Gulotta
cf03d6ddd1
feat: new binding interface (#19)
- We now only return a port object if it's open and list and open methods are now exported on an interface
- hardware tests now work and only require a loopback (no ready event)
- Test pass on darwin (not on mock - it's not up to date yet and coverage is going to drop)
- cleanup up tests with modern javascript
- Breaking - change the names of the exported types
- No more constructors, now all binding specicific open options are specificd on open
- Arduino test file for loopback
2022-01-29 22:51:40 -05:00
Francis Gulotta
2a93f48ee6
feat: migrate to typescript (#3)
This change migrates to typescript. The tests have been modified to conform to typescript and to cleanup cases when they weren't actually working (only one or two cases).

I've defined the existing bindings interface for all platforms. There are changes I'd love to make but didn't here (update/set/get/getBaudRate etc are messy). This should in theory be a drop in for the existing bindings. If there are bugs I imagine they're type related not functionality.

I dropped abstract bindings as having it a separate package didn't make sense during the refactor. I'd like to iterate on the design a bit more before returning to that class. Mockbinding may also now be drifted slightly from this package. I'll clean those inconsistencies up when I upgrade the main repo.
2022-01-22 15:55:03 -05:00
Francis Gulotta
095b7c50be
chore: cleanup single package repository 2021-12-29 21:53:13 -05:00
Francis Gulotta
826545bd0a
chore: change to a monorepo structure with Lerna (#1586)
- move from istanbul to nyc and update coverage reporting
- global docs
- global linting
- global tests
2018-07-24 01:15:09 -04:00
shodan8192
9006bd61f4 fix: memory leak in unix serialport poller (#1572) 2018-06-23 21:37:42 -04:00
Francis Gulotta
a250f0983c
fix: a few warnings and deprecations (#1558)
- c++ string copies were potentially insecure
- sandboxes are now made differently
2018-04-28 21:22:40 -04:00
benpurdy
a1eef112d6 fix(windows): Reset Buffer after write operations are complete to free memory (#1547) 2018-04-09 22:57:17 -04:00
Per Kristian Schanke
45b3a2feb5 feat(windows): Fetch USB serial number by lookups in win registry (#1483)
Serial numbers in win32 from USB devices cannot be readily derived from the PnP ID.
This adds some logic to iterate through the win32 registry, as per the research in #1459.
2018-02-28 07:37:49 -05:00
Iván Sánchez Ortega
59960a3920 feat(linter): Added 'cc' to lint the C++ code on 'npm lint' (#1501) 2018-02-27 21:41:23 -05:00
Jade Bilkey
02e2bfecf0 fix(linux): Adds missing header file for musl libc (eg alpine) (#1487)
Fixes #1470  After adding the new custom baud rate implementation for Linux, a build breaking bug occurred on Alpine Linux due to musl's handling of the kernel header files involved with ioctls. This patch introduces a fix by using the solution found [here](https://github.com/tio/tio/pull/65) on a similar, serial oriented project.

Tested in an Alpine Linux docker container. Passing all hardware tests.
2018-02-15 16:58:22 -05:00
Jade Bilkey
910438c2ca feat(linux): Custom baud rates for linux (eg 250k baudrate) (#1464)
* 250k baudrate now works
* Generic linux non-standard baudrate setting using termios2
* Tested successfully with an FTDI usb chip with the tx and rx pins bridged. Previous solution using the B38400 hack returned gibberish in same setup.
* Test for linux and win32 baudrate setting. Darwin stubbed out.

The arbitrary baud interface has been working on darwin up to this point so it's
likely that it works properly. The GetBaudRate extension should still get
written to be thorough but for now, this will let the CI tests pass properly and
still throw a warning about the check being disabled.

That is, of course, if anyone's testing with the arduino hardware on darwin,
otherwise, these tests never run anyway.
2018-02-05 09:33:11 -05:00
jykim
602793dcd0 Add null check code 2018-01-15 13:14:46 -05:00
kimushu
6f3afbe5a1 fix(windows): bad parameter for ReadThread (windows) (#1377) 2017-10-24 10:43:09 -04:00
kimushu
c1d9d88aa6 fix(windows): Fix async handle leak (#1367)
Fixes event loop weirdness in #1363
2017-10-18 14:03:22 -04:00
kimushu
0e4b1f9fb4 fix(windows): Fix read & write bugs for windows (#1364)
* Fix OVERLAPPED initialization
* Fix buffer overrun for writing and reading
* Remove unsafe memset for non-POD structures
* Fix thread handle leak
2017-10-16 10:10:16 -04:00
Evgeni Milev
4ff9c67dc4 feat(windows): Add ERROR_INVALID_PARAMETER to supported bindings errors (#1354)
Error message according the Microsoft documentation:

ERROR_INVALID_PARAMETER = 87 -> The parameter is incorrect.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
2017-10-08 11:19:06 -04:00
Dustin Long
69de5950a6 fix(windows): Asynchronous callbacks for reading and writing (#1328)
Instead of ReadFile and WriteFile, which block and transfer data synchronously, use ReadFileEx and WriteFileEx, which both allow async callbacks. In addition, change how timeouts are used for ReadFile*, using an unlimited timeout for the first byte, and no timeout for the rest of the data in the input buffer. This removes the need to poll entirely, while still retrieving all data available in the input buffer. In both cases, the I/O operations happen in their own threads, since Windows requires IOCompletion callbacks to wait for their calling thread to be in an "alertable wait state".

Fixes #1221
2017-09-06 22:10:03 -04:00
Francis Gulotta
c7a3be4164 Revert "fix(windows): Asynchronous callbacks for reading and writing on Windows" (#1323)
This reverts commit 2c2a8b688c.
2017-09-02 18:21:47 -04:00
Dustin Long
2c2a8b688c fix(windows): Asynchronous callbacks for reading and writing on Windows (#1313)
Instead of ReadFile and WriteFile, which block and transfer data synchronously, use ReadFileEx and WriteFileEx, which both allow async callbacks. In addition, change how timeouts are used for ReadFile*, using an unlimited timeout for the first byte, and no timeout for the rest of the data in the input buffer. This removes the need to poll entirely, while still retrieving all data available in the input buffer. In both cases, the I/O operations happen in their own threads, since Windows requires IOCompletion callbacks to wait for their calling thread to be in an "alertable wait state".

Fixes #1221
2017-09-02 16:10:53 -04:00
Joshua Shireman
5b8d163861 fix(windows): Add option to disable RTS (#1277)
* Add option to disable RTS on Windows
* Add support for XON / XOFF on Windows.  This is probably not feature complete in terms of missing the XonChar, XoffChar, XonLim fields of DCB, but I am not as familiar with this aspect of serial comms.

BREAKING CHANGE:
We previously hard coded to have RTS On for windows at all times.
2017-08-06 14:57:33 -04:00
Francis Gulotta
4fc1404c8c [all] Unify the serialport.list output (#1266)
- [osx] remove the 0x from productID and locationId and vendorId
- [linux] remove the starting 0x from any values, small refactor
- [linux] Fixup output using the hex encoded fields
- [windows] Grab the serial number from the pnp id
- Isolate list functions to their own platform files (c++)
- Better ensure our serialports fields are present

closes #1220
2017-07-29 19:40:39 -04:00
Francis Gulotta
468dfc29d7 [osx] Return the tty instead of the cu for osx serialports
For the record, tty's are `DialinDevice`s and cu's are `CalloutDevice`s

Thanks to @kishinmanglani for helping me solve this!

The closest we could come to docs. https://opensource.apple.com/source/IOSerialFamily/IOSerialFamily-7/IOSerialFamily.kmodproj/IOSerialKeys.h
2017-07-18 21:14:25 -04:00
Francis Gulotta
9c67ee2a43 [unix] Move setting up the baudrate to the end of the open()
- Test 1000000 baud
2017-07-15 13:06:44 -04:00
Francis Gulotta
2ed7b119d0 Test flushing data
- [unix] small changes to flushing data during port open and setup to prevent bad data
- [all] mock binding flush now works
- cleanup on mock-binding pending reads
- add `serialport-repl` as a bin and npm command
2017-07-09 21:25:02 -04:00
Francis Gulotta
6455ecbb51 [unix] New read/write subsystem (#1212)
This has always been the dream. Use `fs.read` and `fs.write` to do reading and writing. To make that happen I've created a cross platform `Poller` object that notifies us once on `readable` and `writable` states.

- Reduce large write cpu usage from 100% to 1-2%
- Replace ReadPoller with a multi purpose poller because you can only have a single uv_poll_t on a fd at a time because reasons
- Experimented with doing this all in c++, maybe there are gains to doing that but I'd never finish.
- Some unrelated eslint changes
- Arduino echo should just echo, writing random bytes was messing it up
- use a file to disable tests in envs
- read and write errors can trigger disconnects
- disconnect event only happens if there are listeners, otherwise error events will be triggered
- a disconnect during write will always have a write error too
- win32 bindings seem to only trigger disconnects on writes
2017-07-05 09:12:31 -04:00
Francis Gulotta
4984943543 Pull out the c++ write queue (#1198) 2017-06-19 21:13:45 -04:00
Francis Gulotta
5b02ec869f Change the windows read timeouts for optimal reads
ReadIntervalTimeout

A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, specifies that the read operation is to return immediately with the bytes that have already been received, even if no bytes have been received.
2017-01-03 23:56:32 -05:00
Francis Gulotta
adccc6dfde [unix] Correct error messages on .set unix bindings 2016-12-11 18:48:43 -05:00
Francis Gulotta
b80025ea10 Merge pull request #1018 from munyirik/win32read
Adding WindowsBinding reading
2016-12-10 13:15:48 -05:00
Anton Litvinov
f24110b196
Refactoring of EIO_List for Windows: … (#1019)
* Refactoring of EIO_List for Windows:  …
1. use single API -- SetupAPI directly without COM-object
2. supply ResultItem with vendorId, productId and locationId (issue #877)
3. solve problem with pnpId not being returned on some systems
2016-11-27 22:09:24 -05:00
Munyiri Kamau
72768179df Fix build and test issues + updates based on review feedback
- Fix CI failure to build
- Tests (including read) now pass locally
- Changes based on review feedback
2016-11-21 16:30:24 -08:00
Munyiri Kamau
975b270ba3 Adding WindowsBinding reading 2016-11-16 19:30:47 -08:00
Francis Gulotta
672e8319c3 Conform to NodeJS error message formats (#998)
https://github.com/nodejs/node/pull/3374
2016-11-04 23:29:07 -04:00
Francis Gulotta
77c351e46a Remove v8 deprecation warnings 2016-11-04 22:54:09 -04:00
Francis Gulotta
39d0103937 Streams rewrite
This is a major change.  To reading, the poller and the bindings layer, there isn’t a great way to do this piecemeal. The goal here is to make bindings a plugin layer, our c++ bindings isolated and tested, and make Serialport a streams object.

- Move all bindings into platform specific modules DarwinBinding LinuxBinding, and WindowsBinding
- Separate out the bindings from the SerialPort class so it can be required by itself.
- Provide mock bindings as a tested first class bindings layer
- Mixin stream methods with `pushBindingWrap`, inspired from fs.readStream
- All integration tests now require an Arduino 
- Ditch sandboxed modules as we don't need to be that heavy handed to test anymore

TODO

- windows binding
- performance test
- memory leak test
- 🎉
2016-11-04 21:03:35 -04:00
Francis Gulotta
ecc4c31bd8 Fix memory-leaks in SerialPortParity and cleanup (#989)
This should stop a leak in bindings.open() which calls ToParityEnum().

Thanks to @indutny for walking me through the changes and teaching me about valgrind!
2016-11-03 15:24:20 -04:00
enami tsugutomo
f25563dded Plug windows handle leak when open failed. 2016-10-24 12:35:20 +09:00
Francis Gulotta
23de171055 Do error checking when getting modem control flags 2016-10-21 21:35:50 -04:00
Francis Gulotta
0d757fd72c Merge pull request #967 from jgillick/master
Get modem status bits (CTS, DSR, DCD)
2016-10-21 17:50:49 -04:00
Francis Gulotta
0018f0cd25 remove all read timeouts for windows (#974)
per #781
2016-10-19 23:17:49 -04:00
Francis Gulotta
d26991187d Use PurgeComm to flush all current reads and writes on windows (#973)
Fixes #962
2016-10-19 22:20:18 -04:00
Francis Gulotta
ebad161050 Merge pull request #972 from giseburt/master
Fix for issue #781
2016-10-19 21:50:19 -04:00
jgillick
d3dcac14fa Fix code typos (duplicate ->cts) 2016-09-28 02:56:09 -07:00
jgillick
71a069f447 Add get function and bindings for modem status bits 2016-09-19 09:10:43 -07:00