Martin Ling [Mon, 20 Jan 2020 01:42:00 +0000 (01:42 +0000)]
windows: Handle the case where there are no serial ports at all.
It's possible for the HARDWARE\DEVICEMAP\SERIALCOMM key to not exist in
the registry if there are no serial ports at all and never have been, as
discovered on my rather minimalist gaming machine.
Handle that case gracefully and return an empty list.
RegOpenKeyEx() and RegQueryInfoKey() return system error codes directly,
not by setting the thread-local errno equivalent that is returned by
GetLastError().
When returning SP_ERR_FAIL, our API specifies that sp_last_error_code()
may be called immediately afterwards to get the system error code. In
this case that would not work, as it would call GetLastError() and miss
the directly-returned result.
We therefore need to call SetLastError() with the error code before
returning with SP_ERR_FAIL.
Martin Ling [Sat, 4 Jan 2020 23:00:17 +0000 (23:00 +0000)]
android: Fix build compatibility with NDK platform 21 and up.
In platforms 21 and higher of the NDK, linux/serial.h is available,
which it was not before. This broke the build, because the configure
script would detect the availability of 'struct serial_struct' in that
header and set HAVE_STRUCT_SERIAL_STRUCT, but the #ifndef __ANDROID__
in libserialport_internal.h stopped us actually including the header.
This change fixes things to build with all versions of the NDK, and is
tested with builds for arm from versions 9 to 24.
Version 21 also added availability of tcdrain(), so we also use that
where available, and only use the direct ioctl() method on NDK < 21.
Uwe Hermann [Sat, 28 Dec 2019 22:39:15 +0000 (23:39 +0100)]
windows: Fix a build error.
serialport.c: In function 'get_time':
serialport.c:64:6: warning: implicit declaration of function 'clock_gettime' [-Wimplicit-function-declaration]
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
^
serialport.c:64:20: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
^
serialport.c:64:20: note: each undeclared identifier is reported only once for each function it appears in
serialport.c:65:17: error: 'CLOCK_REALTIME' undeclared (first use in this function)
clock_gettime(CLOCK_REALTIME, &ts);
^
serialport.c: At top level:
serialport.c:60:13: warning: 'get_time' defined but not used [-Wunused-function]
static void get_time(struct timeval *time)
^
Martin Jackson [Sat, 9 Sep 2017 22:37:48 +0000 (00:37 +0200)]
windows: wc_to_utf8(): Fix a WCHAR related issue causing crashes.
In wc_to_utf8() in windows.c, the zero terminator is written to an invalid
array index, which results in 2 bytes being zeroed in a random place in the
stack. This sometimes causes a crash when running sp_list_ports() (depending
on string length and compiler optimisation settings).
sizeof(wc_str) returns the size in bytes, so cannot be used directly as an
index into that array, it should be divided by sizeof(WCHAR). Otherwise the
zero terminator index is approximately twice what it should be.
Aurelien Jacobs [Fri, 14 Oct 2016 21:50:08 +0000 (23:50 +0200)]
use readdir() instead of the deprecated readir_r()
readir() is threadsafe on both linux and freebsd anyway.
The rationale behind the readdir_r() deprecation is in the glibc manual:
https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html
This fixes the following warning with recent glibc:
linux.c: In function ‘list_ports’:
linux.c:197:2: warning: ‘readdir_r’ is deprecated [-Wdeprecated-declarations]
while (!readdir_r(dir, &entry, &result) && result) {
^~~~~
Uwe Hermann [Sat, 9 Jan 2016 00:13:45 +0000 (01:13 +0100)]
Bump libtool version (not package version) to 1:0:1.
The last release (0.1.0) had the libtool version (current:revision:age)
set to 0:0:0. Since this release doesn't change/remove any
interfaces (it does *add* new interfaces, though), 'current' and 'age'
are increased and 'revision' is set to 0, resulting in 1:0:1.
Martino Facchin [Wed, 16 Dec 2015 18:07:49 +0000 (19:07 +0100)]
windows: Fix iSerial for composite devices.
USB composite devices can contain an ACM serial interface.
On Windows, the correct iSerial descriptor field is assigned to the parent
(composite) device instead of to the actual serial interface. A bogus
value is returned if the serial interface is asked to provide the S/N.
This patch provides a fallback for this kind of device (tested on Android
with adb + cdc gadgets and on Arduino Zero Programming Port)
Martino Facchin [Fri, 18 Dec 2015 11:40:58 +0000 (12:40 +0100)]
macosx: Fix port listing on ElCapitan.
On OSX 10.11 (ElCapitan) the query for IOProviderClass fails to list ACM
devices as USB.
Add a fallback query using IOClass to correctly recognize these devices.
The fix has no effect on previous OSX versions (tested on Mavericks)
Daniel Elstner [Wed, 26 Aug 2015 17:46:43 +0000 (19:46 +0200)]
Build: Reduce autogen.sh to trivial stub
Use autoreconf instead of invoking the various Auto tools
separately. Get rid of the Darwin-specific guesswork -- it does
not make sense to handle this at the level of libserialport.
People should set up their ACLOCAL_PATH themselves as appropriate
for their own system; just as they already need to set up various
other paths.