Skip to content

Commit 90d9d84

Browse files
committed
Merge remote-tracking branch 'xseignard/master'
2 parents b6b3c96 + 9bfc431 commit 90d9d84

File tree

10 files changed

+848
-281
lines changed

10 files changed

+848
-281
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/bin
2+
cordovarduino.iml
3+
src/cordovarduino.iml

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2013 Stereolux. http://www.stereolux.org
3+
Copyright (c) 2015 Xavier Seignard. http://drangies.fr
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
21+
THE SOFTWARE.

README.md

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22

33
Cordovarduino is a Cordova/Phonegap plugin that enable you to use serial communication from an Android device to a serial over USB capable one.
44

5-
It's a **work in progress** : Android to Arduino works, Arduino to Android now works.
6-
7-
85
## Change log
6+
2014.08: [Zevero](https://github.com/zevero): Option to find device by VID and PID, that let you use "unrecognized" devices.
97

10-
2014.03: Ed. Lafargue
11-
Implemented read(). The success callback returns a Javascript ArrayBuffer which is the best way to handle binary data
12-
in Javascript. It is straightforward to convert this to a string if required - a utility function could be implemented in this plugin.
8+
2014.07: [Hendrik Maus](https://github.com/hendrikmaus): Implemented writeHex for working with RS232 protocol, i.e. javascript can now pass "ff", java turns it into a 1 byte array and writes to the serial port - naturally, java, and the existing write method here, would create a 2 byte array from the input string.
139

14-
### Context
15-
This work was made during an art residency hosted at the [Stereolux, Laboratoire Arts et Technologies](http://www.stereolux.org/laboratoire-arts-et-technologies) with [Coup de foudre](https://www.facebook.com/coup.defoudre.716) and [Xavier Seignard](http://drangies.fr).
10+
2014.04: [Derek K](https://github.com/etx): Implemented registerReadCallback for evented reading and Android onPause/onResume
11+
12+
2014.03: [Ed. Lafargue](https://github.com/elafargue): Implemented read(). The success callback returns a Javascript ArrayBuffer which is the best way to handle binary data in Javascript. It is straightforward to convert this to a string if required - a utility function could be implemented in this plugin.
1613

17-
The goal was to create a tablet app to control a [tesla coil](http://www.youtube.com/watch?v=X2elQ6RR7lw) with an [Arduino](http://arduino.cc). The chosen technology ([Cordova](http://cordova.io)) had no capabilities to handle such serial over usb communication.
14+
2013.11: [Xavier Seignard](https://github.com/xseignard): First implementation
1815

1916
### Install it
2017
From the root folder of your cordova project, run :
2118
```
22-
cordova plugin add https://github.com/stereolux/cordovarduino.git
23-
cp plugins/org.stereolux.cordova.serial/lib/usbseriallibrary.jar platforms/android/libs
19+
cordova plugin add https://github.com/xseignard/cordovarduino.git
2420
```
2521

2622
### How to use it
@@ -40,6 +36,7 @@ serial.open(opts, function success(), function error());
4036
- dataBits: defaults to 8
4137
- stopBits: defaults to 1
4238
- parity: defaults to 0
39+
- dtr: defaults to false (it may be needed to be true for some arduino)
4340

4441
You're now able to read and write:
4542
```js
@@ -49,6 +46,26 @@ serial.read(function success(buffer), function error());
4946
`data` is the string representation to be written to the serial port.
5047
`buffer` is a JavaScript ArrayBuffer containing the data that was just read.
5148

49+
Apart from using `serial.write`, you can also use `serial.writeHex` to have an easy way to work with **RS232 protocol** driven hardware from your javascript by using **hex-strings**.
50+
51+
In a nutshell, `serial.writeHex('ff')` would write just a single byte where `serial.write('ff')` would let java write 2 bytes to the serial port.
52+
53+
Apart from that, `serial.writeHex` works the same way as `serial.write` does.
54+
55+
Register a callback that will be invoked when the driver reads incoming data from your serial device. The success callback function will recieve an ArrayBuffer filled with the data read from serial:
56+
```js
57+
serial.registerReadCallback(
58+
function success(data){
59+
var view = new Uint8Array(data);
60+
console.log(view);
61+
},
62+
function error(){
63+
new Error("Failed to register read callback");
64+
});
65+
```
66+
67+
68+
5269
And finally close the port:
5370
```js
5471
serial.close(function success(), function error())
@@ -82,3 +99,16 @@ serial.requestPermission(
8299
errorCallback
83100
);
84101
```
102+
103+
### Your Device is not (yet) known?
104+
105+
Your device might not be listed over at https://github.com/mik3y/usb-serial-for-android .
106+
If you know your devices VID (Vendor ID) and PID (Product ID) you could however try
107+
108+
```js
109+
serial.requestPermission({vid: '1d50', pid: '607d'}, function success(), function error()); //hex strings
110+
or
111+
serial.requestPermission({vid: 7504, pid: 24701}, function success(), function error()); //integers
112+
```
113+
114+
You can find your devices VID and PID on linux or android using "lsusb" (returning VID:PID in hex) or by looking at your dmesg log.

plugin.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
4-
id="org.stereolux.cordova.serial"
5-
version="0.0.1">
4+
id="fr.drangies.cordova.serial"
5+
version="0.0.2">
66
<name>Serial</name>
77
<description>Cordova plugin to communicate with the android USB serial port</description>
88
<license>MIT</license>
@@ -17,10 +17,17 @@
1717
<platform name="android">
1818
<config-file target="res/xml/config.xml" parent="/*">
1919
<feature name="Serial">
20-
<param name="android-package" value="org.stereolux.cordova.serial.Serial"/>
20+
<param name="android-package" value="fr.drangies.cordova.serial.Serial"/>
2121
</feature>
2222
</config-file>
23-
<source-file src="src/android/org/stereolux/cordova/serial/Serial.java" target-dir="src/org/stereolux/cordova/serial" />
24-
<source-file src="src/android/org/stereolux/cordova/serial/UsbBroadcastReceiver.java" target-dir="src/org/stereolux/cordova/serial" />
23+
<source-file src="src/android/fr/drangies/cordova/serial/Serial.java" target-dir="src/fr/drangies/cordova/serial" />
24+
<source-file src="src/android/fr/drangies/cordova/serial/UsbBroadcastReceiver.java" target-dir="src/fr/drangies/cordova/serial" />
25+
<source-file src="lib/usbseriallibrary.jar" target-dir="libs" />
2526
</platform>
26-
</plugin>
27+
28+
<!-- ubuntu -->
29+
<platform name="ubuntu">
30+
<header-file src="src/ubuntu/serial.h" />
31+
<source-file src="src/ubuntu/serial.cpp" />
32+
</platform>
33+
</plugin>

0 commit comments

Comments
 (0)