rusel1989 / react-native-bluetooth-serial

Port of https://github.com/don/BluetoothSerial for react native
476 stars 293 forks source link

Listener for receiving data #37

Open happierco opened 7 years ago

happierco commented 7 years ago

I need to read from a barcode scanner without using an input field. Is there a listener I can use?

rusel1989 commented 7 years ago

Hey @happierco , You can use BluetoothSerial.on('data', (data) => ...do something with data)

ibenben commented 7 years ago

BluetoothSerial.on('data', (data) => { console.log(data); });

Can not receive data.

ibenben commented 7 years ago

Hao can I read the byte from device.I do not want the string result.

babyinthesky commented 7 years ago

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

goldfishinsky commented 5 years ago

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

where should I put these codes?

hungtm84 commented 5 years ago

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); })

I have same question, did @goldfishinsky solve this problem ?

yalcinozer commented 4 years ago

I get the listener for receiving data working by the following way. Note that you have to replace the delimiter '\r\n' with the one upon your own case.

BluetoothSerial.withDelimiter('\r\n').then((res)=>{ console.log("delimiter setup",res); BluetoothSerial.on('read',(data)=>{ console.log('read',data); }) })

I know this issue is a little old but, Should we place on("read") listener in "withDelimiter" method

All I want actually, listening constantly for data from HC05 module to app. Only thing I can do is checking module manually with readFromDevice method.

ramacha7 commented 3 years ago

@yalcinozer Have been able to figure out how to do it. I actually have the same application goal. I need to constantly listen for data from a HC05 module.

yalcinozer commented 3 years ago

@ramacha7 using delimiters is a must be. You also should call functions repeatedly to read data. If you have any option use "BLE" devices. At some point I just gave up checking if data received or not.