Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and write multiple values with one request #15

Open
Herbstein opened this issue Mar 28, 2017 · 3 comments
Open

Read and write multiple values with one request #15

Herbstein opened this issue Mar 28, 2017 · 3 comments

Comments

@Herbstein
Copy link

Herbstein commented Mar 28, 2017

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.

@christophediericx
Copy link
Owner

That sounds like a reasonable request. Thanks for providing the write-up.

I'll try to make some time somewhere in the next week to implement this.

@christophediericx
Copy link
Owner

Hi Herbstein,

As I had to travel for work, I will only have time to implement this next weekend. Sorry for the delay.

Thanks,

Christophe

@Herbstein
Copy link
Author

Hi Christophe.

That isn't a problem. I'm using the library for a project, but it's not that time sensitive. Thanks for the effort you're putting in!

Herbstein

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants