Skip to content

Read and write multiple values with one request #15

@Herbstein

Description

@Herbstein

Reasoning

As it stands now reading and writing multiple values at once can be quite slow. Writing a digit to a 7-digit display takes around 85 ms. That is a long time taken just to write output to seven pins.

General proposal

I propose that new options are added to the protocol. The names are unimportant so I'll refer to the additions as ExtendedRead and ExtendedWrite. These cover both analog and digital operations.

The protocol extensions would be similar to the current implementations. The extensions would send the amount of operations (operation referring to reading or writing a pin) to the board, along with the needed pin information to complete the operations.

Reading

Request

For reading this would simply be a number, eg. 3, and a list of the pins to read. An example could look like this:

var response = driver.Send(new ExtendedDigitalReadRequest(3, 4, 5);

The only parameter to the ExtendedDigitalReadRequest constructor would be a single params parameter containing all the pins.

Response

The response to a ExtendedReadRequest would be similar to the current ones. Instead of containing the readings for a single operation it would contain an array with an entry for every operation requested. The type of the array depends on the type of ExtendedReadRequest. The type would be DigitalValue for digital and byte for analog. The ordering of the response would have to match the ordering of the original request.

Another option is wrapping the pin information in a struct. That would make the relationship between pin and reading more explicit, but would also require more protocol overhead.

Writing

Request

Writing to multiple pins is slightly trickier. I suggest wrapping the pin and DigitalValue value in a struct.

struct DigitalWriteInfo { byte Pin { get; set; } DigitalValue Value { get; set; } }

The constructor is omitted from the above declaration. An example call with three values would then look like this:

var response = driver.Send(new ExtendedDigitalWriteRequest(new DigitalWriteInfo(2, DigitalValue.High), new DigitalWriteInfo(3, DigitalValue.Low), new DigitalWriteInfo(4, DigitalValue.Low)));

The syntax is very verbose, and there might be a better way to handle it, but I believe the intention is clear.

Response

The response to a ExtendedWriteRequest is similar to the response to a ExtendedReadReqeuest. I believe the explanation and reasoning in that section also covers the current section.

Feel free to ask for clarification if you need it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions