You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-11Lines changed: 41 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,25 +2,21 @@
2
2
3
3
Cordovarduino is a Cordova/Phonegap plugin that enable you to use serial communication from an Android device to a serial over USB capable one.
4
4
5
-
It's a **work in progress** : Android to Arduino works, Arduino to Android now works.
6
-
7
-
8
5
## Change log
6
+
2014.08: [Zevero](https://github.com/zevero): Option to find device by VID and PID, that let you use "unrecognized" devices.
9
7
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.
13
9
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.
16
13
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
18
15
19
16
### Install it
20
17
From the root folder of your cordova project, run :
@@ -40,6 +36,7 @@ serial.open(opts, function success(), function error());
40
36
- dataBits: defaults to 8
41
37
- stopBits: defaults to 1
42
38
- parity: defaults to 0
39
+
- dtr: defaults to false (it may be needed to be true for some arduino)
43
40
44
41
You're now able to read and write:
45
42
```js
@@ -49,6 +46,26 @@ serial.read(function success(buffer), function error());
49
46
`data` is the string representation to be written to the serial port.
50
47
`buffer` is a JavaScript ArrayBuffer containing the data that was just read.
51
48
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 =newUint8Array(data);
60
+
console.log(view);
61
+
},
62
+
functionerror(){
63
+
newError("Failed to register read callback");
64
+
});
65
+
```
66
+
67
+
68
+
52
69
And finally close the port:
53
70
```js
54
71
serial.close(functionsuccess(), function error())
@@ -82,3 +99,16 @@ serial.requestPermission(
82
99
errorCallback
83
100
);
84
101
```
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'}, functionsuccess(), function error()); //hex strings
110
+
or
111
+
serial.requestPermission({vid:7504, pid:24701}, functionsuccess(), 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.
0 commit comments