-1

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

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
  • 1
    I have never used F# with the brick so I don't know if this is valid code, but have you seen: [Mindstorm API in F# with the lego computation expression.](https://gist.github.com/thinkbeforecoding/c6fe439b4908c61145f9) – Guy Coder Feb 20 '16 at 12:40
  • Crap! I sincerely thought I was going to be the first. I'm so depressed now. Can I be a pioneer of anything without people beating me to it? – Scott Nimrod Feb 20 '16 at 12:44
  • 1
    *"doing all of this in the constructor. Is that okay?"* From an OOD perspective: *no.* Constructors should mainly be used for initialisation; see e.g. [Implementation Patterns](http://amzn.to/1RTOD8V). Since this is F# code, however, why not expose it as a function instead? – Mark Seemann Feb 20 '16 at 12:50
  • @Mark - My question was in the context of troubleshooting my issue with commands not being observed. I should have phrased that better. – Scott Nimrod Feb 20 '16 at 13:03
  • @ Mark and Guy Coder - I plan to on implementing both versions (i.e. OOP and FP). However, I just want to get a Hello World up first using a path of least resistance. – Scott Nimrod Feb 20 '16 at 13:04
  • I found out the issue and posted the answer. – Scott Nimrod Feb 20 '16 at 13:25
  • See: [Tombstone diagram](https://en.wikipedia.org/wiki/Tombstone_diagram) – Guy Coder Feb 20 '16 at 13:57
  • Here is project I might do, has not been done, and is desired by many people. [tensorflow — is it or will it (sometime soon) be compatible with a windows workflow?](http://stackoverflow.com/q/33616094/1243762) The path I am taking for learning TensorFlow covers most of the same path, but I don't plan on doing that part at present. You could do it and could be first, unless I do decide to do it when I get done with what I need to learn. – Guy Coder Feb 20 '16 at 14:17
  • You can be a pioneer at something once you stop worrying about being a pioneer at something. This is not the right path. – Fyodor Soikin Feb 20 '16 at 15:52
  • @ Guy Coder - That's beyond my learning capacity. You can have that. https://www.tensorflow.org/ – Scott Nimrod Feb 20 '16 at 16:03
  • @FyodorSoikin `This is not the right path` Can you please explain. – Guy Coder Feb 20 '16 at 16:11
  • I had the same problem recently because the COM port for the blutooth connection changed... – thinkbeforecoding Feb 20 '16 at 23:06

1 Answers1

0

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.

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118