sbufferwrite

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - USB Interface
Introduced first in SolidGeometry 2.8, Creation date: 2015-12-08, Last change: 2025-09-14

writes bytes into a struct buffer

Description

the basic functions are:
sbuffercreate - create a buffer
sbufferinfo - status info about the buffer
sbufferwrite - write data into the buffer
sbufferget - read data out of the buffer


See Also: sbuffercreate , sbufferinfo , sbufferget

Example Illustration

 missing image of sbufferwrite(b,mbytes)

Syntax

[b,err]=sbufferwrite(b,mbytes)

Input Parameter

b: struct buffer
mbytes: bytes array to write

Output Parameter

b: updated buffer
err: error number




Copyright 2015-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is a function named sbufferwrite that writes a byte array into a buffer structure. It is part of a library for handling buffer operations, specifically designed for a USB interface.

Input Parameters

Output Results

Algorithm Steps

  1. Call sbufferinfo(b) to retrieve the free space f and total length l of the buffer.
  2. Initialize err to false.
  3. Calculate the size of mbytes and store it in msize.
  4. Check if msize is greater than l. If true, issue a warning that the data size is too large for the buffer and set err to true. Exit the function.
  5. Check if msize is greater than f. If true, issue a warning that the data size is too large for the available free space in the buffer and set err to true. Exit the function.
  6. Calculate the buffer indices bi where the data will be written using mod1 to handle circular buffer logic.
  7. Update the write index b.w to the last index in bi.
  8. Increment the buffer's data count b.anz by msize.
  9. Write the mbytes into the buffer at the calculated indices bi.
Algorithm explaination created using ChatGPT on 2025-08-18 23:44. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21