Commit Graph

37 Commits

Author SHA1 Message Date
Cristian Maglie
2cb14f049c SetReadTimeout: unix implementation 2021-06-29 15:24:40 +02:00
Cristian Maglie
a63b28875f linux: detect port disconnection during Read
See https://stackoverflow.com/a/34945814/1655275

> pselect signals that file descriptor is ready and
> ioctl(fd, FIONREAD, &len) returns zero len.

Failure to detect this condition has been revealed by
the testsuite:

=== RUN   TestDisconnectingPortDetection
2017/07/27 13:56:37 PR - Connecting to Probe
2017/07/27 13:56:37      > Searching for port 2341:8037
2017/07/27 13:56:37        Detected port '/dev/ttyACM0' 2341:8037
2017/07/27 13:56:37        Using '/dev/ttyACM0'
2017/07/27 13:56:37 Starting test (timeout 20s)
2017/07/27 13:56:37 PR - Turn ON target
2017/07/27 13:56:37 TR - Connecting to Target
2017/07/27 13:56:37      > Searching for port 2341:8036
2017/07/27 13:56:37        Detected port '/dev/ttyACM0' 2341:8037
[...cut...]
2017/07/27 13:56:46      > Searching for port 2341:8036
2017/07/27 13:56:46        Detected port '/dev/ttyACM0' 2341:8037
2017/07/27 13:56:46        Detected port '/dev/ttyACM1' 2341:8036
2017/07/27 13:56:46        Using '/dev/ttyACM1'
2017/07/27 13:56:46 T2 - Make a Read call
2017/07/27 13:56:46 T1 - Delay 200ms before disconnecting target
2017/07/27 13:56:46 T1 - Disconnect target
2017/07/27 13:56:46 PR - Turn OFF target
2017/07/27 13:56:46 T2 - Read returned: n=0 err=nil
--- FAIL: TestDisconnectingPortDetection (9.18s)
        Error Trace:    serial_test.go:100
	Error:		An error is expected but got nil. %s
	Messages:	Read returned no errors

this commit fix the problem above.
2021-06-29 15:24:32 +02:00
Maddie Zhan
eb474d2569 Use golang.org/x/sys/unix provided ioctl functions 2020-09-22 00:20:59 +02:00
Cristian Maglie
66bfcede42 Added test for port double close 2020-04-19 01:44:34 +02:00
angri
1b760a82af allow Close() to be called from other goroutine than Read
The only way to interrupt running Read() method of io.Reader is to call
Close from another goroutine. What happens is that go runtime builtin
race detector complains about unsynchronised access to "opened" member,
which is set in Close and checked in Read.

It doesn't seem to be dangerous, but 1) you never know, and 2) it makes
your life more difficult when you need to debug some other data races in
a complex project that uses serial.

Proposed fix changes simple access to "opened" to atomic operations.
It's also supposed to fix #38
2020-04-19 01:12:48 +02:00
Andrey Demenev
1131ba52fd Do not return -1 from Read() and Write()
Closes #55
2020-04-18 23:52:30 +02:00
Cristian Maglie
6a673bf917 Transparently handle EINTR during Read
This has been observed in particular on MacOS, in this case just retry
the call without throwing the error back to the user.

Related to:
https://github.com/arduino/arduino-cli/issues/504
https://github.com/arduino/arduino-pro-ide/issues/157
2019-12-03 20:26:03 +01:00
Cristian Maglie
df95023074 Introducing go.mod for dep management 2019-12-02 19:51:36 +01:00
Cristian Maglie
24a6610f05 Updated license years
Updated to 2020 even if we are less than one month ahead.
2019-12-02 19:27:10 +01:00
Cristian Maglie
4366d1c449 Tentative support for OpenBSD
See #27
2017-03-12 22:41:52 +01:00
Veniamin Albaev
8b7629bfe1 Added buffer flush methods
+ serial.Port.ResetInputBuffer()
+ serial.Port.ResetOutputBuffer()
2017-03-09 11:47:38 +03:00
Veniamin Albaev
4d886c1028 Unix: move from syscall to golang.org/x/sys/unix
Prepare to using `unix.TCFLSH`/`unix.TIOCFLUSH`
which is missing in `syscall` package
2017-03-09 11:04:37 +03:00
Cristian Maglie
970475ed06 Updated licenses 2017-03-04 16:29:55 +01:00
Cristian Maglie
e9103998c3 Merge remote-tracking branch 'cmaglie/fix-read-close-deadlock' into v1 2016-11-27 21:30:58 +01:00
Cristian Maglie
d50de5cbaf unix: Fixed race condition while closing serial port. Added PortClosed error 2016-11-14 00:36:30 +01:00
Cristian Maglie
6eedab17b4 Added wrapper around goselect library.
This simplifies handling of select syscall.
2016-11-14 00:34:51 +01:00
Cristian Maglie
152558831e Moved Pipe{} into own sub-package
It may be moved into a separate project at some point, who knows...
2016-11-13 23:44:15 +01:00
Cristian Maglie
eee219b43f posix: added check for port closing 2016-11-08 12:31:18 +01:00
Cristian Maglie
12cc48dd24 unix: avoid Read blocking forever if called before Close 2016-11-06 18:30:49 +01:00
Cristian Maglie
a736b8f7b9 Modem signals implementation (posix) 2016-10-31 18:02:38 +01:00
Cristian Maglie
5be0087bd5 Added interface methods for RS232 signals 2016-10-31 18:02:38 +01:00
Cristian Maglie
cb166b5b85 Improved error reporting on setting stop bits 2016-10-22 18:32:51 +02:00
Cristian Maglie
c534e6fb45 Improved error reporting for parity settings 2016-10-22 18:32:51 +02:00
Cristian Maglie
a3909960d3 Removed termiosMask(..) and use the correct bitmask type
This requires a bit of copying in darwin 386/amd64 but simplifies
the overall design.
2016-10-22 18:32:51 +02:00
Cristian Maglie
50993cc77b Factorize a function to enable/disable of RTS/CTS handshake for unix 2016-10-20 23:57:09 +02:00
Cristian Maglie
9398f35b69 Use unsigned values for termios setting
This allows the last (most significant) bit to be set without
overflow errors. The error becomes visible after adding the
CRTSCTS constant on linux/386:

   const tcCRTSCTS uint = 0x80000000
2016-10-20 23:55:06 +02:00
Cristian Maglie
7178181a28 Disable RTS/CTS handshake by default
Fix #3
2016-10-20 23:17:26 +02:00
Cristian Maglie
85dc492d83 Merge branch 'v0' into v1 2016-09-17 19:48:20 +02:00
Franz Bettag
a0fe3b8b02 Works on FreeBSD (even on armv6 and armv7 when cross compiled). 2016-09-15 17:46:58 +02:00
Cristian Maglie
b89deafa1c Change import path to "go.bug.st/serial.v1"
This is needed when there are breaking changes in the API.
2016-09-05 01:05:22 +02:00
Cristian Maglie
f5be203394 Created interface Port. Rationalized documentation. 2016-04-24 17:20:49 +02:00
Cristian Maglie
88e647775e Rename serial.SerialPort to serial.Port
another lint suggestion.
2016-04-24 17:20:49 +02:00
Cristian Maglie
485b2f86a8 Fixed a bunch of golint warnings (this needs an API change) 2016-04-24 17:20:49 +02:00
Cristian Maglie
e90aca32c8 Updates to documentation 2016-01-01 21:14:05 +01:00
Cristian Maglie
55b609d095 Added first draft of documentation 2015-01-02 03:08:31 +01:00
Cristian Maglie
9c18e832ce Fixed unchecked array access 2015-01-01 17:46:14 +01:00
Cristian Maglie
da42d3809e Added implementation for darwin x86_64 2014-12-31 19:43:47 +01:00