EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #289 background imageLoading...
Page #289 background image
First of all, you should note that we define all methods on the
prototype
prop-
erty of the
SerialDevice
object. I wont go into the details here, but you should
know that this is one way to add new methods to objects in JavaScript.
The
connect
method delegates its work to the
chrome.serial.connect
function that
you saw in the previous section already. The only thing worth noting is the
callback function we pass in the function call. Again we use
bind
to set the
callback functions context explicitly. This way, we make sure that
onConnect-
Complete
has access to the properties of the
SerialDevice
object.
We benefit from that in the
onConnectComplete
method. Here we can set the
con-
nectionId
property of our
SerialDevice
object as soon as weve successfully connect-
ed to a serial device. If we hadnt bound
onConnectComplete
before,
this
would
have a completely different meaning in this function, and we couldnt access
the properties of the
SerialDevice
object.
In lines 14 and 15, we use the same technique to add receive and error listen-
ers to the
chrome.serial
object. Here we use the listeners weve prepared in the
constructor function before. After weve established the connection success-
fully, we call the
onConnect
objects
dispatch
method to spread the good news to
all listeners outside.
Eventually, we have to implement the actual listener functions that deal with
incoming and outgoing data and with errors:
ChromeApps/SerialDevice/js/serial_device.js
SerialDevice.prototype.onReceive = function(receiveInfo) {
if (receiveInfo.connectionId !== this.connectionId) {
return;
}
this.readBuffer += this.arrayBufferToString(receiveInfo.data);
var n;
while ((n = this.readBuffer.indexOf('\n')) >= 0) {
var line = this.readBuffer.substr(0, n + 1);
this.onReadLine.dispatch(line);
this.readBuffer = this.readBuffer.substr(n + 1);
}
};
SerialDevice.prototype.onReceiveError = function(errorInfo) {
if (errorInfo.connectionId === this.connectionId) {
this.onError.dispatch(errorInfo.error);
}
};
SerialDevice.prototype.send = function(data) {
report erratum discuss
Writing a SerialDevice Class 277
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals