Skip to content

Commit f2d67e3

Browse files
committed
modify example and readme
1 parent 0056695 commit f2d67e3

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,28 @@ find serial port channel
7171
```js
7272
device.findSerialPortChannel(address, function(channel){
7373
console.log('Found RFCOMM channel for serial port on %s: ', name, channel);
74-
74+
7575
// make bluetooth connect to remote device
7676
bluetooth.connect(address, channel, function(err, connection){
7777
if(err) return console.error(err);
7878
connection.write(new Buffer('Hello!', 'utf-8'));
7979
});
80-
80+
81+
});
82+
```
83+
84+
create connection to device, read and write
85+
86+
```js
87+
// make bluetooth connect to remote device
88+
bluetooth.connect(address, channel, function(err, connection){
89+
if(err) return console.error(err);
90+
91+
connection.on('data', (buffer) => {
92+
console.log('received message:', buffer.toString());
93+
});
94+
95+
connection.write(new Buffer('Hello!', 'utf-8'));
8196
});
8297
```
8398

example/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ var list = [];
88
device
99
.on('finished', console.log.bind(console, 'finished'))
1010
.on('found', function found(address, name){
11-
11+
1212
console.log('Found: ' + address + ' with name ' + name);
13-
13+
1414
// find serial port channel
1515
device.findSerialPortChannel(address, function(channel){
1616
console.log('Found RFCOMM channel for serial port on %s: ', name, channel);
17-
17+
1818
// make bluetooth connect to remote device
1919
bluetooth.connect(address, channel, function(err, connection){
2020
if(err) return console.error(err);
21+
22+
connection.on('data', (buffer) => {
23+
console.log('received message:', buffer.toString());
24+
});
25+
2126
connection.write(new Buffer('Hello!', 'utf-8'));
2227
});
23-
28+
2429
});
25-
30+
2631
}).inquire();

0 commit comments

Comments
 (0)