Commit Graph

226 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
Cristian Maglie
f355dbf608 windows: correcly signal PortClosed error on blocked Read()
This commit fix regression test TestConcurrentReadAndWrite.

Even if the test checks purpose is another it has detected
anyway that the returned error is incorrect.

Another specific test for closing port detection will be added
in the future.
2021-06-29 15:23:40 +02:00
Cristian Maglie
383ed1cd2a Merge pull request #103 from cmaglie/windows-improve-usb-sernum-disc
Windows improve usb serial number discovery
2021-02-26 14:59:48 +01:00
Cristian Maglie
57ac200f98 windows: improved serial number detection on composite USB devices 2021-02-26 12:34:22 +00:00
Cristian Maglie
7183520fbb run of go-fmt 2021-02-26 12:34:22 +00:00
Cristian Maglie
388e793063 Merge pull request #102 from cmaglie/go-generate-rerun
Refresh run of go generate with the latest mksyscall
2021-02-26 13:25:56 +01:00
Cristian Maglie
233eb2a09b Refresh run of go generate with the latest mksyscall 2021-02-26 13:20:02 +01:00
Cristian Maglie
b6c28f76a4 Merge pull request #101 from cmaglie/big-sur-support
Added support for macosx 10.11+
2021-02-26 13:17:09 +01:00
Cristian Maglie
b62cd2386c Added support for macosx 10.11+
Seems like, starting from 10.11, IOUSBDevice has been renamed to IOUSBHostDevice.
2021-02-26 13:07:44 +01:00
Tomáš Polomský
e18766f4d1 update go generate
Replace old mkwinsyscall call by the new version which is recommended
by Go since version 1.13.3.
2021-02-26 12:26:27 +01:00
Cliff Brake
be77090773 update goselect to get riscv support 2021-02-26 12:24:20 +01:00
Tobias Kohlbau
57b513a432 add support for darwin arm64
Support arm64 which is used by the new lineup of computers
from apple.

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
2021-02-15 09:39:59 +01:00
Cristian Maglie
00e63fcc18 small cosmetic fix 2020-09-23 18:27:06 +02:00
Maddie Zhan
eb474d2569 Use golang.org/x/sys/unix provided ioctl functions 2020-09-22 00:20:59 +02:00
Lukas Becker
578b2ec832 only check for newline instead of newline and carraiage return
Co-authored-by: Cristian Maglie <c.maglie@bug.st>
2020-05-08 14:16:00 +02:00
Lukas Becker
b0154211af removed empty line
Co-authored-by: Cristian Maglie <c.maglie@bug.st>
2020-05-08 14:16:00 +02:00
Lukas Becker
f88d900804 changed the example_test.go so it stops reading when "\n\r" is received 2020-05-08 14:16:00 +02:00
Elliott Sales de Andrade
640e755b94 Wait for socat to be ready before running full test.
The -D option tells it to print something just before starting the
transfer phase, which should be enough to ensure that all the file
links are available without having to guess a suitable timeout.
2020-04-26 19:37:35 +02:00
Cristian Maglie
49ab90eff3 Updates to readme 2020-04-20 00:12:16 +02:00
Cristian Maglie
66bfcede42 Added test for port double close 2020-04-19 01:44:34 +02:00
Tobias Kaupat
f0282e0b50 Use mutex on Close() to avoid data races on windows 2020-04-19 01:25:10 +02:00
Tobias Kaupat
545e830e04 Allow multiple calls to close 2020-04-19 01:24:57 +02:00
Cristian Maglie
6500d68fc8 Added test to detect correct behaviour in Close and Read ops 2020-04-19 01:12:48 +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
f7a06a7c47 Merge remote-tracking branch 'origin/v1' 2020-04-18 23:46:54 +02:00
martin-zaber
9f6eea0188 Fixing getPortList on windows without any ports 2020-04-18 23:43:54 +02:00
Cristian Maglie
820cffa341 Added doc for new USB Product field (windows-only) 2020-04-18 22:22:31 +01:00
giacomoberlin
f0d91f6e0d Product in PortDetails struct
un-commented Product member of the struct PortDetails. This goes with the pull request "completed retrievePortDetailsFromDevInfo #40". Apologies for not submitting together...
2020-04-18 22:09:26 +01:00
giacomoberlin
4df0da8377 completed retrievePortDetailsFromDevInfo
in retrievePortDetailsFromDevInfo:
- updated call to setupDiGetDeviceRegistryProperty with the same style used elsewhere (first get the reqSize, then call)
- use of generic variable names, in case the function is extended to fetch other values than spdrpFriendlyName (or spdrpDeviceDesc)
- re-enabled the assignment of details.Product
2020-04-18 22:08:55 +01:00
giacomoberlin
900c828b75 fixed API procSetupDiGetDeviceRegistryPropertyW
confusingly, in this prototype Microsoft decided to split bufSize and reqSize
2020-04-18 22:08:08 +01: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
d1a463e324 Updated build-passing badge 2019-12-03 17:03:28 +01:00
Cristian Maglie
88e081691b Fixed enumerator build for openbsd (unsupported operation) 2019-12-03 17:03:28 +01:00
Cristian Maglie
96546e190f Added some cross-os builds 2019-12-03 17:03:28 +01:00
Cristian Maglie
15b0a663d5 Switch to gh-actions (WIP 1/2) (#67) 2019-12-03 16:39:18 +01:00
Cristian Maglie
f2a9ea925f Updates to readme 2019-12-02 20:00:32 +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
5f7892a7bb Merge pull request #52 from bugst/osx-fix-again
Fix osx build (again...)
2018-08-27 14:33:49 +02:00
Cristian Maglie
219de06186 Fixed darwin build for go1.10+ 2018-08-27 14:18:10 +02:00
Cristian Maglie
d3b8f81e83 Added go1.11 to travis build 2018-08-27 14:10:46 +02:00
Cristian Maglie
d759e28145 Merge pull request #51 from bugst/osx-fix
Fix 'darwin' build with latest releases of golang
2018-08-23 15:47:59 +02:00
Cristian Maglie
1c2446b92c Implementing compatibility with go latest
This should allow darwin to be compatible with all the latest

go1.7.x
go1.8.x
go1.9.x
2018-08-20 01:02:49 +02:00
Cristian Maglie
e42339511c Fixed wrong build tags... oops 2018-08-19 18:57:32 +02:00
Cristian Maglie
de1714d049 Added portlist cmd-line utility 2018-08-19 18:52:20 +02:00
Cristian Maglie
338c399730 Factored out C.IORegistryEntryCreateCFProperty method 2018-08-19 18:51:07 +02:00
Cristian Maglie
6085517433 Made error variable explicit in search loop 2018-08-19 18:41:24 +02:00
Cristian Maglie
cdac3b30e1 Removed extra parenthesis 2018-08-19 18:41:00 +02:00