A question about a function

the code " protected Request<byte[]> createReadRequest(List<? extends ReadItem> items)" in the example of Ignition-ModuleSDK-7.2.8\example\ModbusDriver-v2.

there is no explanation of function  createReadRequest in javadoc, can you give me some help about it ?thank you

Sorry, our build was generating javadoc only on the public level instead of public+protected.

The next build of the SDK that goes online will have javadoc for all protected methods as well, which should explain things like createReadRequest() and optimizeRead().

Cuold you explain this function now? thank you

Oops, I meant to do that…

	/**
	 * Create a read {@link Request} with the given items. These items are guaranteed to be a
	 * sub-list previously generated by a call to {@link #optimizeRead(List)} and should therefore
	 * fit into single {@link Request}.
	 * 
	 * @param items
	 *            The items that make up this read {@link Request}.
	 * 
	 * @return A read {@link Request} for the given items.
	 */
	protected abstract Request<M> createReadRequest(List<? extends ReadItem> items);
	/**
	 * <p>
	 * Optimize the given list of items into sub-lists where each sub-list is expected to fit into a
	 * single {@link Request} when {@link #createReadRequest(List)} is called.
	 * </p>
	 * 
	 * <p>
	 * Things to take into consideration when optimizing might be:
	 * <ul>
	 * <li>Type of item being read</li>
	 * <li>Address/location of item being read</li>
	 * <li>Limitations on the number of items that can be read at once</li>
	 * <li>Limitations on the size of a request packet</li>
	 * <li>Limitations on the size of the response packet this request may generate</li>
	 * <li>The speed at which a device responds to reading items based on how they are grouped</li>
	 * </ul>
	 * These and any other limitations are, obviously, highly implementation specific.
	 * </p>
	 * 
	 * @param items
	 *            The items to optimize into sub-lists.
	 * 
	 * @return A list of lists, where each sub-list is expected to fit inside a single read
	 *         {@link Request}.
	 */
	protected abstract List<List<? extends ReadItem>> optimizeRead(List<? extends ReadItem> items);

So essentially what happens is a list of ReadItems comes into AbstractDriver. AbstractDriver asks you, the implementation, to split this list into a list of sub-lists where each sub-list is guaranteed to fit into one Request object. What and how many items can fit into a request generally depends on the protocol you’re implementing. Modbus, for example, has an overall limit of 240 bytes, as well as logical restrictions such as only being able to read one register type per request (Holding Register, Input Register, etc…).

Once you’ve optimized into sub-lists, AbstractDriver then asks you to create a Request object for each one of those sub-lists in #createReadRequest(List<? extends ReadItem>).

You can look at the Modbus driver source code to see how it handles these calls as an example.