The callback function receives an object containing all information about the
connection. The statement above prints a text representation of the serial
connection object that has been created:
Object {
bitrate: 38400
bufferSize: 4096
connectionId: 13
ctsFlowControl: false
dataBits: "eight"
name: ""
parityBit: "no"
paused: false
persistent: false
receiveTimeout: 0
sendTimeout: 0
stopBits: "one"
}
This object contains all properties you d expect in an object representing a
serial connection. It contains properties for the parity bit and stop bit settings.
One of its most important properties is
successful, its value is greater than zero.
In a next step, you can add a receive listener that gets called whenever data
arrives at the serial port:
var
listener = function(r) { console.log(r.data); }
chrome.serial.onReceive.addListener(listener)
This listener outputs the data it receives on the console. Its output looks like
this:
ArrayBuffer {}
ArrayBuffer {}
ArrayBuffer {}
...
This probably isn t what you expected. The problem is that the Chrome Serial
API stores the data it receives in an
you can transmit not only textual, but also binary data over a serial connec-
tion. JavaScript doesn t support binary data out of the box, so you have to
use a few helper classes, such as
Using the following function, you can turn the content of an
into a JavaScript string:
Exploring the Chrome Serial API
connectionId
. If the call to
ArrayBuffer
object. This is necessary because
ArrayBuffer
.
www.it-ebooks.info
273
connect
was
ArrayBuffer
object
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?