sharpbrick/powered-up

"System.NullReferenceException: Object reference not set to an instance of an object." during "Discover Ports. Receiving Messages ..." when using CLI

voomdoon opened this issue · 4 comments

There is a NullReferenceException during Discover Ports. Receiving Messages ... using latest master branch

>poweredup device list
Scan Started. Please select the Hub (using a number keys or 'q' to terminate):
1: DuploTrainBase (with address <ADDRESS>)
1
Selected DuploTrainBase with key 1
Discover Ports. Receiving Messages ...
System.NullReferenceException: Object reference not set to an instance of an object.
   at SharpBrick.PoweredUp.Bluetooth.BluetoothKernel.ConnectAsync() in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp/Bluetooth/BluetoothKernel.cs:line 29
   at SharpBrick.PoweredUp.Protocol.LegoWirelessProtocol.ConnectAsync(SystemType knownSystemType) in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs:line 49
   at SharpBrick.PoweredUp.Cli.DevicesList.ExecuteAsync(SystemType knownSystemType) in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs:line 29
   at SharpBrick.PoweredUp.Cli.Program.<>c__DisplayClass4_2.<<Main>b__6>d.MoveNext() in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp.Cli/Program.cs:line 78

Environment:

on second attempt its working, not sure how to reproduce

hah ... probably the device switched or just did not do what it should or the data was gliberrish in the air of during the wireless connection .... which is all fine. The code deserves some more love at

https://github.com/sharpbrick/powered-up/blob/master/src/SharpBrick.PoweredUp/Bluetooth/BluetoothKernel.cs#L29

Basically we do three calls to external resources and follow the happy path ... pretty stupid and not very defensively programmed.

I am a bit tired right now due to private stuff .... do you want to take a shot at improving this function?

I am just doing my first steps with C#, so would need some time...

no worries. I have time ;) and can review code ;)