Network samples?

So if I were adding this I’d probably do it like so:

public delegate void CommandCallback(SPWF04SxCommand cmd);

public void ReadConfiguration(string variable, CommandCallback callback) {
    var cmd = this.GetCommand()
                  .AddParameter(variable)
                  .Finalize(SPWF04SxCommandIds.GCFG);

    this.EnqueueCommand(cmd);

    callback.Invoke(cmd);

    this.FinishCommand(cmd);
}

public string ReadSerialNumber() {
    var res = "";

    this.ReadConfiguration("nv_serial", cmd => {
        res = cmd.ReadString();
        cmd.ReadBuffer();
    });

    return res.Split('=')[1].TrimEnd('\r', '\n');
}

I’ve not actually ran the above code, but it’s the rough idea. If we had generics the delegate could be generic over the return type and I could return directly instead of using shared state like I do.

2 Likes