Hello folks,
There are some opportunities for improvement on the website documentation.
I am an experienced embedded C programmer and have had a chance to connect to Processing with the Processing Serial library (and others) and have been challenged with the documentation on this at times.
A thorough review and relevant updates to the site documentation are needed to ensure accuracy and clarity. And the source code?
As I like to say “Please be perspicuous in your communication”. < Humorous juxtaposition.
Example 1
The serial library documentation can be a challenge.
Consider two links (old and new):
-
Serial::readBytes()\ serial \ Language (API) \ Processing 1.0
This has byteBuffer as a parameter in the description and syntax. -
readBytes() / Libraries / Processing.org
*This has byteBuffer as a parameter in the description but NOT in the syntax.
The syntax uses a dest parameter with NO description.
The description would benefit from NOT being a paragraph and in separate lines:
Reads a group of bytes from the buffer or null if there are none available.
The serial.readBytes() version with no parameters returns a byte array of all data in the buffer. This is not efficient, but is easy to use.
The serial.readBytes(byteBuffer) version with the byteBuffer parameter is more memory and time efficient. It grabs the data in the buffer and puts it into the byte array passed in and returns an int value for the number of bytes read. If more bytes are available than can fit into the byteBuffer , only those that fit are read.
It would also benefit from discussing what the buffer is; there is the serial buffer and also additional buffers (Windows and hardware that may be beyond the scope of this discussion).
Keeping in mind there is the serial buffer that has incoming data and there are the references to byteBuffer and inBuffer as well.
These are redundant calls and should be used separately and each have their own example:
byte[] inBuffer = new byte[7];
inBuffer = myPort.readBytes(); // This
myPort.readBytes(inBuffer); // Or this but not both.
Some possible corrections:
Example 1
byte[] inBuffer = new byte[7];
while (myPort.available() > 0) {
byte[] inBuffer = myPort.readBytes();
if (inBuffer != null) {
String myString = new String(inBuffer);
println(myString);
}
}
Example 2
byte[] inBuffer = new byte[7];
if (myPort.available() > 0) { //or while() ?
myPort.readBytes(inBuffer);
String myString = new String(inBuffer);
println(myString);
}
I have explored the above ad nauseum in the past and would have to revisit this again.
And revisit the source code:
processing4/java/libraries/serial at main · processing/processing4 · GitHub
I will leave that one for another day.
I may be able to contribute to this in the future.
How to get started on this?
Related:
:)