Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

no onData after disconnect #191

Closed
pacmac opened this Issue · 11 comments

3 participants

@pacmac

Been trying to debug this for several days, and I think it may be a bug.

After the port is disconnected (by the device being removed) the onData function does not appear to get invoked after the open().

After an open(), data is being transmitted to the device, and data is sent back from the device, however the ondata() function does not appear to be firing.

@voodootikigod
@pacmac

In this application I have the host computer, which connects to several microcontrollers via bluetooth serial ports.

The host sends a request to each BT device, and the microcontroller replies with the data requested. This all works fine until one of the ports disconnects due to the bluetooth devices going out of range or being switched off etc etc.

I use the diconnect callback to echo the disconnection to the console and when I power off the device, the disconnect callback fires and the port gets closed.

But when the device is reconnected, it opens the ports and the data request is transmitted using the write() function, however the data transmitted back by the microcontroller in response to the request is not heard by the serialPort onData() function.

Let me know if you need anything else ?

@voodootikigod
@pacmac

My apologies, MAC, I can post some code if needed ?

@pacmac

Here's the log, there are 2 serial ports:
1) /dev/tty.OmniTek_Bluetooth-DevB - this is the connected bluetooth serial port
2) /dev/tty.SLAB_USBtoUART] - this is a USB > Serial adapter with nothing connected.

Device 1, sends and receives data and updates @ 83223 (seconds since midnight). Then I power off and on again device 1 and the disconnect callback registers the disconnect.

It then opens the port and writes to it again but never receives a reply.

Express server listening on port 3000
adding:/dev/tty.OmniTek_Bluetooth-DevB
adding:/dev/tty.SLAB_USBtoUART
error: { '0': [Error: Cannot open /dev/tty.SLAB_USBtoUART] }
open & write > /dev/tty.OmniTek_Bluetooth-DevB
83222:/dev/tty.OmniTek_Bluetooth-DevB SEND:83222:0:1410:1500:1560:1620
83223:/dev/tty.OmniTek_Bluetooth-DevB RECV:19:5d:ee3da0,4,1,1387,,,,2237
UPDATE: 19:5d:ee3da0:4:22.37

Disconnect:/dev/tty.OmniTek_Bluetooth-DevB

error: { '0': [Error: Cannot open /dev/tty.SLAB_USBtoUART] }
open & write > /dev/tty.OmniTek_Bluetooth-DevB
83282:/dev/tty.OmniTek_Bluetooth-DevB SEND:83282:0:1410:1500:1560:1620

write only > /dev/tty.OmniTek_Bluetooth-DevB
83340:/dev/tty.OmniTek_Bluetooth-DevB SEND:83340:0:1410:1500:1560:1620

error: { '0': [Error: Cannot open /dev/tty.SLAB_USBtoUART] }
write only > /dev/tty.OmniTek_Bluetooth-DevB
83400:/dev/tty.OmniTek_Bluetooth-DevB SEND:83400:0:1410:1500:1560:1620

error: { '0': [Error: Cannot open /dev/tty.SLAB_USBtoUART] }
write only > /dev/tty.OmniTek_Bluetooth-DevB
83460:/dev/tty.OmniTek_Bluetooth-DevB SEND:83460:0:1410:1500:1560:1620

@voodootikigod
@pacmac

Ok, I think I have fixed it and discovered the cause.

I assumed that I needed to bind the onData() event when the port is initially declared, and that it would survive connects and disconnects, however it appears that each time the port is closed / opened, I have to re-define the onData() event again.

Is this working as designed ??

Thanks

@voodootikigod
@pacmac

OK, great, I think that might be the same for the other callbacks too.

Many Thanks, at least I can continue now

@reconbot
Collaborator

It seems that possibly the C bindings remove references to the callbacks after the disconnect. There's nothing in our JS that prohibits this use. The event emitter isn't cleared out or anything.

@voodootikigod

Closing due to age, if still issue, please resubmit ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.