Search code examples
f#lego-mindstorms

Lego Mindstorm: Unable to observe operations after connecting to Lego Brick object


I am unable to observe any operations after I successfully connect to the Lego Brick.

This code works:

let brick = Brick(BluetoothCommunication "COM3")
let result = brick.ConnectAsync().RunSynchronously

However, I am unable to observe any confirmations for successive commands (i.e. sound and motor).

Client Code:

open MyLego.Core

[<EntryPoint>]
let main argv = 

    let example = LegoExample()
    0 // return an integer exit code

Domain Logic

namespace MyLego.Core

open Lego.Ev3.Core
open Lego.Ev3.Desktop

type LegoExample() = 

    let volume = 100
    let frequency = 1000
    let duration = 300
    let power = 50
    let breakSetting = false

    let brick = Brick(BluetoothCommunication "COM3")
    do brick.BrickChanged.Add(fun e -> printfn "Brick changed")

    let result = brick.ConnectAsync().RunSynchronously

    let move = brick.DirectCommand.TurnMotorAtPowerForTimeAsync(
                    OutputPort.B ||| OutputPort.C, power, uint32 duration, breakSetting).RunSynchronously

    let playTone = brick.DirectCommand.PlayToneAsync(
                        volume, uint16 frequency, uint16 duration).RunSynchronously

Note that I am doing all of this in the constructor. Is that okay?

I am referencing the following documentation:

Video

Windows client


Solution

  • It turns out that I have a Bluetooth connection issue.

    When I use the USB, I observe the expected behavior.

    Apparently the following exception gets swallowed:

    "there is no user session key for the specified logon session"

    However, this exception is only observed within a C# implementation.