Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ObjectDisposedException: The object has been closed. after a few seconds #189

Open
thetestgame opened this issue Oct 1, 2022 · 11 comments

Comments

@thetestgame
Copy link

After a few seconds and one command being sent to a Lego hub it abruptly closes the connection. Is there a heartbeat step that needs to occur? This is currently guaranteed to happen every time I try with my current codebase.

System.ObjectDisposedException: The object has been closed. (0x80000013)
   at SharpBrick.PoweredUp.WinRT.WinRTPoweredUpBluetoothCharacteristic.WriteValueAsync(Byte[] data)
   at SharpBrick.PoweredUp.Bluetooth.BluetoothKernel.SendBytesAsync(Byte[] data)
   at SharpBrick.PoweredUp.Protocol.LegoWirelessProtocol.SendMessageAsync(LegoWirelessMessage message)
   at SharpBrick.PoweredUp.Protocol.ILegoWirelessProtocolExtensions.SendMessageReceiveResultAsync[TResultMessage](ILegoWirelessProtocol self, LegoWirelessMessage message, Func`2 filter)
   at SharpBrick.PoweredUp.Protocol.ILegoWirelessProtocolExtensions.SendPortOutputCommandAsync(ILegoWirelessProtocol self, PortOutputCommandMessage message)
   at SharpBrick.PoweredUp.BasicMotor.StartPowerAsync(SByte power)
@tthiery
Copy link
Member

tthiery commented Oct 1, 2022

In the protocol there is no concept of heartbeat. The hubs have a very strange initial connection mode but aside of that it is a very simple protocol on the frame layer.

@tthiery
Copy link
Member

tthiery commented Oct 1, 2022

This is a bit strange considering that StartPower is one of the most basic commands.

@tthiery
Copy link
Member

tthiery commented Oct 1, 2022

I guess this is the hub shutting down. Question is why:

  • command wrong encoded: i do not believe so
  • too many commands at once (have you tried with throttling/waiting in between or is your code multi-threaded
  • do you have esoteric BT hardware? Does it work otherwise/default Lego app?

@thetestgame
Copy link
Author

thetestgame commented Oct 1, 2022

This is repeatable after sending only one command after the initial connect call. Also the Hubs I've tested with work fine otherwise with the controller or the Lego app. Far as I know I have a standard BT setup. Its stock with my DELL machine if its worth mentioning.

@tthiery
Copy link
Member

tthiery commented Oct 1, 2022

Have you had the chance to test it on another device? I have no trains, it worked last time I used it (tm) with a technic hub and motor and right now I am in an actual train so hard time supporting you 😂

@tthiery
Copy link
Member

tthiery commented Oct 1, 2022

Creating a trace file would be helpful. I could verify the correct encoding there and check the exact place the thing fails

@thetestgame
Copy link
Author

Have you had the chance to test it on another device? I have no trains, it worked last time I used it (tm) with a technic hub and motor and right now I am in an actual train so hard time supporting you 😂

I have not. I'll try that later today.

Creating a trace file would be helpful. I could verify the correct encoding there and check the exact place the thing fails

Do you have a preferred tool for trace files?

@thetestgame
Copy link
Author

Additional bit of information. It seems to disconnect/stop on its own regardless if I send any new commands. Also sometimes it keeps working flawlessly but its rare. When the abrupt stop happens the light on the hub is still on like its connected but the object has been disposed from .NET.

@tthiery
Copy link
Member

tthiery commented Oct 3, 2022

Which Hub ist it exactly? The train one with the motors or the default Lego two port hub?

@thetestgame
Copy link
Author

I'm using the Lego two port hubs from the RC trains.

@tthiery
Copy link
Member

tthiery commented Oct 3, 2022

I do not have any and I do not remember special behavior for them. They are a late product like the technic hubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants