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

proposal for expansion of ScpiConnectionExtensions #2

Closed
VZ42 opened this issue Oct 3, 2023 · 1 comment
Closed

proposal for expansion of ScpiConnectionExtensions #2

VZ42 opened this issue Oct 3, 2023 · 1 comment

Comments

@VZ42
Copy link

VZ42 commented Oct 3, 2023

    /// <summary>
    /// Reads a byte array from the device. The reading is done until all data is read.
    /// </summary>
    /// <param name="conn">Connection to read bytes from.</param>
    /// <param name="specialTimeout">Special timeout (milliseconds). If zero (default value), uses Timeout property value for timeout.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>Bytes retrieved from the device.</returns>
	public static async Task<byte[]>ReadBytes(this IScpiConnection conn, int specialTimeout = 0, CancellationToken cancellationToken = default)
	{
		var result = new MemoryStream();

        var buffer = new byte[1024];

        ReadResult chunk;
        do {
            chunk = await conn.Read(buffer, -1, specialTimeout, cancellationToken);
			result.Write(buffer, 0, chunk.Length);
            //response.Append(Encoding.ASCII.GetString(chunk.Data, 0, chunk.Length));
        } while (!chunk.Eof && chunk.Length > 0);

		return result.ToArray();
    }
@klasyc
Copy link
Owner

klasyc commented Oct 3, 2023

Hi, thank you for your contribution! I have integrated it to the code base.

@klasyc klasyc closed this as completed Oct 3, 2023
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