├── .gitmodules
├── LICENSE.md
├── README.md
├── compile_freebsd.sh
├── compile_linux.sh
├── compile_mac.sh
├── compile_win.sh
├── jnilib.c
├── main.c
├── pack_and_release.sh
└── win32_jni
└── jni_md.h
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "libserialport"]
2 | path = libserialport
3 | url = https://github.com/facchinm/libserialport.git
4 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | _Simple environment to test libserialport in a single build machine fashion_
2 |
3 | Prerequisites:
4 | * An [osxcross](https://github.com/tpoechtrager/osxcross) installation
5 | * An updated mingw32 environment
6 |
7 | TLTR:
8 | ```bash
9 | dpkg --add-architecture i386
10 | apt-get install build-essential gcc-multilib g++-multilib mingw-w64 xz-utils libxml2-dev clang patch git gcc-4.8-arm-linux-gnueabihf g++-4.8-arm-linux-gnueabihf autoconf libtool linux-libc-dev:i386 gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu zip
11 | #setup osxcross + add binaries to PATH
12 | git clone https://github.com/facchinm/listSerialPortsC --recursive
13 | ./pack_and_release.sh
14 | ```
15 |
16 | TODO:
17 | * Add a golang wrapper
18 |
--------------------------------------------------------------------------------
/compile_freebsd.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -xe
2 |
3 | # REQUIRES: devel/openjdk8
4 | JAVA_INCLUDE_PATH=/usr/local/openjdk8/include
5 |
6 | # Only compile for native architecture -- no cross-compiling here
7 | mkdir -p distrib/freebsd
8 | cd libserialport
9 | ./autogen.sh
10 | CC=clang ./configure
11 | make clean
12 | make
13 | cd ..
14 | clang main.c libserialport/freebsd.c libserialport/serialport.c -Ilibserialport/ -lusb -o listSerialC
15 | cp listSerialC distrib/freebsd/listSerialC
16 | clang jnilib.c libserialport/freebsd.c libserialport/serialport.c -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/freebsd/ -shared -fPIC -o liblistSerialsj.so
17 | cp liblistSerialsj.so distrib/freebsd/
18 |
--------------------------------------------------------------------------------
/compile_linux.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -xe
2 |
3 | JAVA_INCLUDE_PATH=/opt/jvm/jdk1.8.0/include/
4 |
5 | mkdir -p distrib/linux64
6 | cd libserialport
7 | ./autogen.sh
8 | ./configure
9 | make clean
10 | make
11 | cd ..
12 | gcc main.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -o listSerialC
13 | cp listSerialC distrib/linux64/listSerialC
14 | gcc jnilib.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/linux/ -shared -fPIC -o liblistSerialsj.so
15 | cp liblistSerialsj.so distrib/linux64/
16 |
17 | mkdir -p distrib/linux32
18 | cd libserialport
19 | ./autogen.sh
20 | CFLAGS=-m32 ./configure
21 | make clean
22 | make
23 | cd ..
24 | gcc -m32 main.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -o listSerialC
25 | cp listSerialC distrib/linux32/listSerialC
26 | gcc -m32 jnilib.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/linux/ -shared -fPIC -o liblistSerialsj.so
27 | cp liblistSerialsj.so distrib/linux32
28 |
29 | mkdir -p distrib/arm
30 | cd libserialport
31 | ./autogen.sh
32 | ./configure --host=arm-linux-gnueabihf
33 | make clean
34 | make
35 | cd ..
36 | arm-linux-gnueabihf-gcc main.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -o listSerialC
37 | cp listSerialC distrib/arm/listSerialC
38 | arm-linux-gnueabihf-gcc jnilib.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/linux/ -shared -fPIC -o liblistSerialsj.so
39 | cp liblistSerialsj.so distrib/arm/
40 |
41 | mkdir -p distrib/aarch64
42 | cd libserialport
43 | ./autogen.sh
44 | ./configure --host=aarch64-linux-gnu
45 | make clean
46 | make
47 | cd ..
48 | aarch64-linux-gnu-gcc main.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -o listSerialC
49 | cp listSerialC distrib/aarch64/listSerialC
50 | aarch64-linux-gnu-gcc jnilib.c libserialport/linux_termios.c libserialport/linux.c libserialport/serialport.c -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/linux/ -shared -fPIC -o liblistSerialsj.so
51 | cp liblistSerialsj.so distrib/aarch64/
52 |
--------------------------------------------------------------------------------
/compile_mac.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -xe
2 |
3 | JAVA_INCLUDE_PATH=/opt/jvm/jdk1.8.0/include/
4 |
5 | mkdir -p distrib/osx
6 | cd libserialport
7 | ./autogen.sh
8 | CC=o64-clang ./configure --host=x86_64-apple-darwin13
9 | make clean
10 | make
11 | cd ..
12 | o64-clang main.c libserialport/serialport.c libserialport/macosx.c -Ilibserialport -framework IOKit -framework CoreFoundation -o listSerialC
13 | cp listSerialC distrib/osx/
14 | o64-clang jnilib.c libserialport/macosx.c libserialport/serialport.c -framework IOKit -framework CoreFoundation -Ilibserialport/ -I$JAVA_INCLUDE_PATH -I$JAVA_INCLUDE_PATH/linux/ -shared -o liblistSerialsj.dylib
15 | cp liblistSerialsj.dylib distrib/osx/
16 |
--------------------------------------------------------------------------------
/compile_win.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -xe
2 |
3 | JAVA_INCLUDE_PATH=/opt/jvm/jdk1.8.0/include/
4 |
5 | mkdir -p distrib/windows
6 | cd libserialport
7 | ./autogen.sh
8 | ./configure --host=i686-w64-mingw32
9 | make clean
10 | make
11 | cd ..
12 | i686-w64-mingw32-gcc main.c -Llibserialport/.libs/ -Ilibserialport/ -lserialport -lsetupapi -static -o listSerialC.exe
13 | cp listSerialC.exe distrib/windows/
14 | i686-w64-mingw32-gcc -D_JNI_IMPLEMENTATION_ -Wl,--kill-at jnilib.c libserialport/.libs/libserialport.a -lsetupapi -Ilibserialport/ -I/opt/jvm/jdk1.8.0/include/ -Iwin32_jni -shared -o listSerialsj.dll
15 | cp listSerialsj.dll distrib/windows/
--------------------------------------------------------------------------------
/jnilib.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | JNIEXPORT jstring JNICALL Java_processing_app_Platform_resolveDeviceAttachedToNative
7 | (JNIEnv * env, jobject jobj, jstring serial)
8 | {
9 | struct sp_port *port;
10 |
11 | char vid_pid_iserial[256] = " ";
12 | const char *portname = (*env)->GetStringUTFChars(env, serial, NULL);
13 | jstring result;
14 |
15 | if (sp_get_port_by_name(portname, &port) != SP_OK) {
16 | return (*env)->NewStringUTF(env, "");
17 | }
18 |
19 | int vid, pid;
20 | if (sp_get_port_usb_vid_pid(port, &vid, &pid) == SP_OK) {
21 | snprintf(vid_pid_iserial, sizeof(vid_pid_iserial), "0x%04X_0x%04X_%s_%s", vid, pid, sp_get_port_usb_serial(port), sp_get_port_description(port));
22 | }
23 |
24 | sp_free_port(port);
25 | (*env)->ReleaseStringUTFChars(env, serial, portname);
26 |
27 | return (*env)->NewStringUTF(env, vid_pid_iserial);
28 | }
29 |
30 | JNIEXPORT jobjectArray JNICALL Java_processing_app_Platform_listSerialsNative
31 | (JNIEnv * env, jobject jobj)
32 | {
33 | struct sp_port **ports;
34 | jobjectArray ret;
35 | int i;
36 |
37 | char portname_vid_pid[256] = " ";
38 |
39 | if (sp_list_ports(&ports) != SP_OK) {
40 | return (jobjectArray)(*env)->NewObjectArray(env, 0, (*env)->FindClass(env, "java/lang/String"), (*env)->NewStringUTF(env, ""));
41 | }
42 |
43 | // like ports.size()
44 | for (i = 0; ports[i]; i++) {};
45 |
46 | ret = (jobjectArray)(*env)->NewObjectArray(env, i, (*env)->FindClass(env, "java/lang/String"), (*env)->NewStringUTF(env, ""));
47 |
48 | int vid, pid;
49 | for (i = 0; ports[i]; i++) {
50 | int vid, pid;
51 | if (sp_get_port_usb_vid_pid(ports[i], &vid, &pid) == SP_OK) {
52 | snprintf(portname_vid_pid, sizeof(portname_vid_pid), "%s_%04X_%04X", sp_get_port_name(ports[i]), vid, pid);
53 | } else {
54 | snprintf(portname_vid_pid, sizeof(portname_vid_pid), "%s_%04X_%04X", sp_get_port_name(ports[i]), 0, 0);
55 | }
56 | (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, portname_vid_pid));
57 | }
58 |
59 | sp_free_port_list(ports);
60 |
61 | return ret;
62 | }
63 |
--------------------------------------------------------------------------------
/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | int i;
7 | struct sp_port **ports;
8 | enum sp_return ret;
9 |
10 | ret = sp_list_ports(&ports);
11 | if (ret != SP_OK) {
12 | return 0;
13 | }
14 |
15 | struct sp_port *port;
16 | char vid_pid_iserial[256] = " ";
17 |
18 | for (i = 0; ports[i]; i++) {
19 | sp_get_port_by_name(sp_get_port_name(ports[i]), &port);
20 |
21 | int vid, pid;
22 | if (sp_get_port_usb_vid_pid(port, &vid, &pid) == SP_OK) {
23 | printf("%s | %04X:%04X | %s %s %s %s\n", sp_get_port_name(ports[i]), vid, pid, sp_get_port_usb_serial(port), sp_get_port_usb_product(port), sp_get_port_usb_manufacturer(port), sp_get_port_description(port));
24 | }
25 | sp_free_port(port);
26 | }
27 | sp_free_port_list(ports);
28 | }
29 |
--------------------------------------------------------------------------------
/pack_and_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -xe
2 |
3 | VERSION=$1
4 |
5 | if [ x$VERSION = "x" ]
6 | then
7 | echo "Please provide a version number"
8 | exit 1
9 | fi
10 |
11 | ./compile_win.sh
12 | ./compile_linux.sh
13 | ./compile_mac.sh
14 |
15 | mv distrib liblistSerials-$VERSION
16 | zip -r liblistSerials-$VERSION.zip liblistSerials-$VERSION
17 |
18 | echo scp liblistSerials-$VERSION.zip root@downloads-02.arduino.cc:/var/www/files/liblistSerials/
19 | shasum liblistSerials-$VERSION.zip
20 |
21 | rm -rf liblistSerials-$VERSION
22 |
--------------------------------------------------------------------------------
/win32_jni/jni_md.h:
--------------------------------------------------------------------------------
1 | /*
2 | * @(#)jni_md.h 1.13 03/01/23
3 | *
4 | * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
5 | * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6 | */
7 |
8 | #ifdef MSW
9 | #include
10 | #endif
11 |
12 | #ifndef _JAVASOFT_JNI_MD_H_
13 | #define _JAVASOFT_JNI_MD_H_
14 |
15 | #define JNIEXPORT __declspec(dllexport)
16 | #define JNIIMPORT __declspec(dllimport)
17 | #define JNICALL __stdcall
18 |
19 | typedef long jint;
20 | typedef __int64 jlong;
21 | typedef signed char jbyte;
22 |
23 | #endif /* !_JAVASOFT_JNI_MD_H_ */
24 |
--------------------------------------------------------------------------------