Commit graph

167 commits

Author SHA1 Message Date
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
Francis Gulotta
71f7fb317a strip whitespace (#913) 2016-08-22 11:29:45 -04:00
Francis Gulotta
3400822e80 [unix] Flush now gives errors and flushes tx and rx (#900)
- Bonus less structs as many functions return nothing or error
2016-08-08 15:13:04 -04:00
Rob Giseburt
1162513bfb Change windows write timeouts to 0 (never). 2016-07-25 20:51:27 -05:00
Francis Gulotta
7eca965961 Enable locking and sharing of the serialport (#840) 2016-06-11 22:34:07 -04:00
Francis Gulotta
e986563c75 Make sure .drain and .set error on all platforms. (#834) 2016-05-29 16:03:18 -04:00
Francis Gulotta
18b59eff3e Implement .update() on windows (#831) 2016-05-29 00:26:02 -04:00
Francis Gulotta
901c026ed6 whitespace and spelling 2016-05-28 23:24:58 -04:00
Roger Hardiman
19fb6f9e21 Add GetCommState to fix Error 87 on a Virtual Comm Port (#824)
* Add GetCommState to support a Virtual Comm Port
2016-05-24 22:20:37 -04:00
Francis Gulotta
67e84d950e Dry up serialport.cpp (#818) 2016-05-23 21:39:50 -04:00
Francis Gulotta
4b984e8995 write binding tests and cleanup (#808)
- Fix bug where write callback was being called multiple times when write operations blocked
 - [windows] refactored write code to be less complex
 - [unix] refactored write code to be less complex
 - added arduino required integration tests
2016-05-16 21:33:00 -04:00
Francis Gulotta
0063e13364 Make update cross platform for baud rates (#763)
- Errors should always be an error or null
 - bindings.close doesn't throw with proper args so why are we catching?
 - throw on update if given bad options
 - support and test updating and opening with custom baud rates
2016-05-12 13:03:59 -04:00
Francis Gulotta
cf41ef76bd Update the errors for unix to always include the err string and tests for close (#790) 2016-05-06 23:38:17 -04:00
Francis Gulotta
cf678e6f0b Small Update for windows bindings (#785)
- Error with the provided com port name instead of the mess we use under the hood to talk to the apis
 - update _snprintf calls to _snprintf_s as the former is depreciated 
 - Add a binding test for bad ports
2016-05-05 10:30:50 -04:00
fivdi
cb64745486 Avoid deprecation warnings 2016-05-01 17:43:40 -04:00
Francis Gulotta
7b815fd6a4 Using clang and cpplint lint our c++ as much as I can (#762)
The `src/win/" vendor files are scary
2016-04-24 00:19:35 -04:00
Francis Gulotta
1bd3e06c58 SerialportList updates (#761)
- Errors are now consistent across platforms
 - List is now completely async and promise ready
 - Test the bindings abstraction not the bindings itself
2016-04-23 12:43:31 -04:00